New to the forum but not new to IT related stuff and Arduino's.
I try to control the DeepSleep for ESP8266's (Wemos D1 mini) running ESPEasy on Version mega-20190225 over MQTT.
What I want to do:
deploy some battery powered ESPEasy-devices remotely but reachable over WiFi.
In case of some config-changes and/or firmware updates I do not want to walk to these, connect D0 to GND, do the stuff and re-connect D0 to RST.
Idea:
Why not use the currently working MQTT broker (mosquitto) to control the DeepSleep?
What I did so far:
I created a "Generic - MQTT Import"-Device subscribing to the below: I have configured MQTT to publish stuff like temp, humidity, etc. MQTT is working fine.
I published 2 retained messages that "define" the values evaltuated in the rule:
DeepSleep will be enabled and last for 10 seconds
Code: Select all
mosquitto_pub -r "49/DeepSleep/Enabled" -m "1"
mosquitto_pub -r "49/DeepSleep/Duration" -m "10"
Code: Select all
mosquitto_sub -v -t "49/#"
49/DeepSleep/Enabled 1
49/DeepSleep/Duration 10
Code: Select all
on MQTT#Connected do
Publish %sysname%/DeepSleep/Status,"Awake. Enabled? [MQTT-IN#DeepSleepEnabled]"
Publish,%sysname%/DeepSleep/Duration,[MQTT-IN#DeepSleepDuration]
if MQTT-IN#DeepSleepEnabled="1.00"
Publish,%sysname%/DeepSleep/Duration,[MQTT-IN#DeepSleepDuration]
Publish,%sysname%/GPIO/12,1 // LED just to have a visible indicator. Later the Data-Stuff will be placed here.
publish,%sysname%/SensorData/PublishTime,%systime% //publish when data-stuff was read.
Publish %sysname%/DeepSleep/Status,"Sleeping for [MQTT-IN#DeepSleepDuration] seconds"
//deepsleep,[MQTT-IN#DeepSleepDuration] //go to deepsleep for X seconds (even if deepsleep value is not configured in the config menu)
else
Publish %sysname%/DeepSleep/Status,"staying awake"
Publish,%sysname%/GPIO/12,0 //turning off the LED
endon
49/status/LWT //Connected Connect the MQTT works fine.
49/DeepSleep/Status "Awake. Enabled? 0.00" //Here comes the bad stuff: Set to 1 but output is 0
49/DeepSleep/Duration 0.00 //Also the duration got lost.
49/DeepSleep/Duration 0.00
49/GPIO/12 1 //Another strange thing: Enabled was read in line #2 as 0.00 but here it went into the DeepSleep part.
49/SensorData/PublishTime 13:10:37
49/DeepSleep/Status "Sleeping for 0.00 seconds"
I assume that the rule runs "too fast" to get the MQTT stuff read.
I also tried the below code but that did not put out anything on the screen but went to sleep all the time even I set the "enabled" to 0
Code: Select all
On MQTT#Connected Do //when the broker is connected
timerSet,1,5
endon
On Rules#Timer=1 Do
Publish %sysname%/DeepSleep/Status,"Awake. Enabled? [MQTT-IN#DeepSleepEnabled]"
Publish,%sysname%/DeepSleep/Duration,[MQTT-IN#DeepSleepDuration]
if MQTT-IN#DeepSleepEnabled="1.00"
Publish,%sysname%/DeepSleep/Duration,[MQTT-IN#DeepSleepDuration]
Publish,%sysname%/GPIO/12,1 // LED just to have a visible indicator
publish,%sysname%/SensorData/PublishTime,%systime% //publish when stuff was read.
Publish %sysname%/DeepSleep/Status,"Sleeping for [MQTT-IN#DeepSleepDuration] seconds"
deepsleep,[MQTT-IN#DeepSleepDuration] //go to deepsleep for X seconds (even if deepsleep value is not configured in the config menu)
else
Publish %sysname%/DeepSleep/Status,"staying awake"
Publish,%sysname%/GPIO/12,0 //turning off the LED
EndOn
49/status/LWT Connected
49/status/LWT Connection Lost
49/status/LWT Connected
49/status/LWT Connection Lost
49/status/LWT Connected
49/DeepSleep/Enabled 0 <= Here I set the value
49/status/LWT Connection Lost
49/status/LWT Connected
49/status/LWT Connection Lost
49/status/LWT Connected
COuld anyone point me into the right direction, please?
Many thanks
Sven