• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Getting variables to a 8266 in deep sleep.

Q&A Forum › Getting variables to a 8266 in deep sleep.
0 Vote Up Vote Down
C Bruggeman asked 7 years ago

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?

 

 

8 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

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… 

0 Vote Up Vote Down
C Bruggeman answered 7 years ago

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.

0 Vote Up Vote Down
C Bruggeman answered 7 years ago

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?

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

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.

0 Vote Up Vote Down
C Bruggeman answered 7 years ago

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?

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

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

0 Vote Up Vote Down
C Bruggeman answered 7 years ago

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.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

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!

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.