after getting great help corresponding my last (and very first) topic, I have another two questions.
My goal is to send mqtt messages from some kind of mcu (esp32/esp8266/etc) to node-red and write it into influxdb. That works great.
Now, I also want to read this information somehow with another esp32. For example by sending some kind of polling every 15 min (maybe a mqtt message). Then node-red should answer with another mqtt message to give the state of e.g. a window (open/closed) back to the esp32. (I wanna switch a status LED using that information)
Ist that realistic?
How could I do that?
Do I have to write such things like live-state of the window into the influxdb or do i not? If yes, should I save it as a tag or as a field? hm.
Please can you clarify a couple of points.
Do you want to poll the state of the window, or poll what's in the dataBase??
Thats the question. If a sensor has sent the status of the window 2 min ago. Must I save this information into the database to ask for it a few minutes later or is it not necessary?
Every 15 minutes a device want to check if a window was reported as open or closed.
Is it now clear? Sorry, i am not a native speaker
Well you can do it either way, it really depends on what you want to get out of the system.
A dataBase is ideal for storing information that is collected on a regular or irregular basis.
For example collecting weather information (temp/humidity/pressure) and then display this information on a Node-RED dashboard by running a query against the dB.
You can also poll a device (assuming you are using a Wemos D1 Mini -ESP8266-based microcontroller or an equivalent) and get the state of the input. Here again I'm assuming you have a microswitch or magnetic switch to detect if the window is open/closed and input this to the Wemos where it is transmitted to Node-RED via MQTT.
If you use ESP-Easy firmware (some of the alternative firmwares may offer this as well) you can get the Wemos to listen for an event sent via MQTT from Node-RED to the Wemos. Then within ESP-Easy you could trigger a rule to sense and report the state of the input pin. This is your polling method.
So you have a number of options/ways to implement your project.
- Get the microcontroller to report its status every x-minutes
- Get the microcontroller to report its status if something changes. (E.g. window is opened.)
- Get the microcontroller to report its status when it's asked to do so. (Polled)
- Or a mixture of 1 and 3 or even all of them.
Hope that helps.
Feed the status and 15 minute event message into a Join node configured as in this cookbook example on Joining Streams. Then use a Switch node on the output to pass only the 15 minute messages and then you will get a message with the latest status in it every 15 minutes.
OK. My situation now:
Several sensors like esp8266 sending every 15 min the state of their window via mqtt to node-red. (Then they go to sleep for 15 min)
I do not want to display the state on the Dashboard. I want another esp device (which also wakes up every 15 min and is most of the time sleeping) to ask node-red if any window state was reported as open. If so, the device stay awake and shows the result by blinking a LED. If no window is reported as open, it goes to sleep for 15 minutes.
So, because the device is normally switched off, it cannot receive the window states of the sensors directly. It has to ask node-red for the last reported state.
So, how could a flow look like to achieve this goal (receive the mqtt-ask-message from my device and answer with another mqtt containing the open Windows)?
At the moment, my device which shows the state by blinking a LED has to be always switched on because it receives the Messages directly form the sensors devices. I want to avoid that.
If you make the status mqtt topics Retained, then when the device wakes up and re-connects to mqtt it will automatically get the latest values.
Ah, I see. I ll try that. Thx
that was easy. That was exacly what I need. I see, I still have to learn a lot.
If you haven't already done so then look through the hivemq tutorial mqtt essentials. That is a good way of finding what it is all about.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.