dkuku

dkuku

Looking for library example to control iot device with own state

Hi. I want to control an iot device that has its own state. I think the best way would be to have a copy of the state in a genserver so I don’t have to retrieve it every time. Simple example is a ligh tbulb with colors. I set the color -the bulb changes it but it’s also saved it the genserver state so I can easily query for it. Other example is a radio that has a menu controlled by api calls. You got the top level menu and can navigate to an menu item. This api call gets me the 10 childs of the parent that I can display and I know that I’m 1 level deep. Again I think I need to keep a copy of the state and not query it after every command. Do you know any libraries that use thes pattern? Or maybe is there any other pattern for this kind of things?

Most Liked

paulo-f-oliveira

paulo-f-oliveira

Unless you’re absolutely sure your device can only be accessed by a single GenServer this approach seems Ok: saving state in the process while requesting a change in the device. Otherwise, you might have to ask for a change with “knowledge” of the previous state, e.g. “set color to red if it’s blue”: in this case, if there’s a mismatch with the process state, you should fetch it from the device, store it locally and then do the update. Does this make sense?

entone

entone

You may want to checkout my Lifx library. I haven’t touched it in a while, but it does represent each bulb as a process.

https://github.com/rosetta-home/lifx

Where Next?

Popular in Questions Top

chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement