Hi,
I have this 8266(wemos d1 mini) running a MQTT client posting DHT data to a MQTT server every 183 seconds and then it goes into deep sleep because I have it running on a battery with solar panel.
Now every time I want to change the sleep period, I have to reprogram the unit.
Suppose I could somehow make a server store variables like the seconds to sleep. It could be the MQTT server or just an ftp server on the RouterOS router.
Some system like MQTT has preference because it is so easily set up and managed by phone.
I am thinking of a few of these “smart sensors” to post data and maybe even variables like ” it is raining, put sunroof on position 1″
or: ” it is not raining” and a different sensor says it is “quite hot” under the roof so the sunroof can get these variables every 10 minutes or so and decide on which position the roof should be.
all running on batteries and solar power of course.
How do I get the server to answer to the sensors?
or how do the sensors get their variables?
What’s the server software or home automation platform that you’re using to interact with your ESP using MQTT? You could definitely make a request to that server to get the sleep value for your board…
MQTT runs on a Raspberry pi 3b. it also runs a basic Domoticz setup which keeps track of the digital power- and gas meters.
I have set up a basic proftpd server just for this project. I have no need for it to handle more than this so anonymous login is allowed. Outside access to the Rpi is blocked in the router.
Thanks for thinking with me.
I have not really looked into MQTT, but can you make a request (for a variable, given to it earlier) to the broker?
or can Node-RED do it?
Hi again!
I’m not sure if I’m understanding your question correctly and I’ve also haven’t used Domoticz before, so I don’t know how it works.
But with any home automation platform, you should be able to create variables or components that hold your desired information. Then, the ESP can make an HTTP request or MQTT action to request that data.
I have been experimenting with Node-RED. It is able to react to a MQTT post, and able to react with another MQTT post, but I am unsure about where to store the variable.
example: Mobile phone posts MQTT :
wemos/sleep/set 300
N-R stores it somewhere, or just remembers it.
the wemos posts MQTT:
wemos/sleep/call 1
N-R reacts to any post in ‘wemos/sleep/call’ and posts:wemos/sleep/set 300
the wemos listens to a ‘wemos/sleep/set’ and stores ‘300’ as the new sleeptime (maybe after a string-to-integer conversion). After that it goes to deep-sleep.
So this would depend on timing. Can I set the wemos a certain time limit while waiting for an answer? As with sleep, it never enters the loop. And maybe have the N-Red send it a few times to be sure.
Where can I let the Node-RED store the post (or the variable) to be repeated when asked?
You could create for example a condition that constantly is checked (it’s waiting for the answer from your server). After that value is received, that condition becomes true and your ESP goes into deep sleep.
In Node-RED you can store data using variables for example, here’s how to do it: https://nodered.org/docs/writing-functions#storing-data
Read the “Storing data” heading…
Regards,
Rui
https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages
I stumbled onto this. The solution.
However I already used a potmeter to do the timing. Now I only need the conversion from integer to ‘ const char*’ . If I cannot get it done, I’ll try the retained message.
I’m glad that solve your problem. I’ve just posted the solution for your int to const char* problem: https://rntlab.com/question/invalid-conversion-from-char-to-const-char/
Let me know your results!