gemu2015 / Sonoff-Tasmota

Tasmota Fork TCS34725,PN532_i2,ccc1101 Moritz support,m5stack 4,7 epaper, hotplug drivers
GNU General Public License v3.0
24 stars 19 forks source link

Is it possible to issue a Subscribe command from inside a script? #15

Open YvesLev opened 4 years ago

YvesLev commented 4 years ago

ISSUE DESCRIPTION - TROUBLESHOOTING

Hello @gemu2015, I managed to compile latest dev branch of tasmota and enable Scripting (and disable rules) and enable also Subscribe/Unsubscribe.

In the console, issuing a Subscribe command with a Variable name defined in the script works very well.

But I have not manage to issue the very same Subscribe command inside the script with: =>Subscribe SubVar, Topic/stat/POWER

This in the console gives: {"Command":"Unknown"}

Since I lose the subscribe when power cycle off/on, I would have like to issue this subscribe command from the Script.

So I would like to know if there is another way of writing the command from the script or if this is just not implemented yet?

Thank you. (And thanks to have brought this scripting option to tasmota!)

Yves

REQUESTED INFORMATION

Make sure these boxes are checked before submitting your issue. Thank you

FAILURE TO COMPLETE THE REQUESTED INFORMATION WILL RESULT IN YOUR ISSUE BEING CLOSED

gemu2015 commented 4 years ago

you may NOT execute subscribe in the >B section because MQTT is not yet running there you must send it in >S and assure that it is issued only once

>S if mqttc>0 then =>Subscribe SubVar, Topic/stat/POWER endif

YvesLev commented 4 years ago

Thanks,

That is exactly what I did but had no luck yet: Console with debug info: 13:06:33 QPC: Reset 13:06:33 Script: performs "Subscribe MqtR, BulbChambreAmi/stat/POWER" 13:06:33 SRC: Rule 13:06:33 CMD: Group 0, Index 1, Command "SUBSCRIBE", Data "MqtR, BulbChambreAmi/stat/POWER" 13:06:33 MQT: stat/McuTest/RESULT = {"Command":"Unknown"} 13:06:35 APP: Boot Count 9 13:06:35 CFG: Saved to flash at FB, Count 73, Bytes 4096 13:06:37 MQT: tele/McuTest/STATE = {"Time":"2019-11-29T13:06:37","Uptime":"0T00:00:12","UptimeSec":12,"Heap":27,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER":"ON","Wifi":{"AP":1,"SSId":"PuttPutt","BSSId":"1C:87:2C:68:7C:A8","Channel":11,"RSSI":98,"LinkCount":1,"Downtime":"0T00:00:06"}} 13:06:39 HTP: Main Menu 13:06:45 HTP: Console 13:07:42 CMD: subscribe 13:07:42 SRC: WebConsole from 192.168.2.58 13:07:42 CMD: Group 0, Index 1, Command "SUBSCRIBE", Data "" 13:07:42 MQT: stat/McuTest/RESULT = {"Subscribe":""}

In the script I have:

S if mqttc==1 then =>Subscribe MqtR, BulbChambreAmi/stat/POWER endif

gemu2015 commented 4 years ago

this works for me without error

>D MqtR=0

>S

if mqttc>0 then =>Subscribe MqtR, BulbChambreAmi/stat/POWER endif

YvesLev commented 4 years ago

Can you tell me which version of tasmota you compile with?

YvesLev commented 4 years ago

In the user_config_override.h, I have the following:

ifndef USE_SCRIPT

define USE_SCRIPT // adds about 17k flash size, variable ram size

endif

ifdef USE_RULES

undef USE_RULES

endif

ifndef USE_BUTTON_EVENT

define USE_BUTTON_EVENT

endif

ifndef SUPPORT_MQTT_EVENT

define SUPPORT_MQTT_EVENT

endif

gemu2015 commented 4 years ago

the very last version of my fork but is identical in scripter to the current Tasmota dev

YvesLev commented 4 years ago

I'll try the very latest one in tasmota, and if not working, I'll try yours.

I'll be back soon :-) Thanks

YvesLev commented 4 years ago

With the latest Tasmota Dev Branch, I still have same problem.

Gonna try your fork now.

May I ask what IDE are you using to compile?

YvesLev commented 4 years ago

So I compiled using universal8 branch with GitPod and I have the same problem.

So I guess I must be doing something wrong in the parameters for the compilation... Or do I have to use some SetOption commands?

All I do to compile, is go to gitub of tasmota, use de defaut branch which is develop, then I click on GitPod on the right which I believe opens the latest version of develop into the GitPod IDE.

Then I edit Platform.ini to have Tamsota uncommented and all other language commented. Also I uncomment the line to use User_Config_Override.h.

I attached in a previous post the content of my user_config_override.h file.

Let me know if I forgot something.

Thanks again!

gemu2015 commented 4 years ago

strange, i now get the error too ??? it was working several times ???

try this variant =>

if mqttc>0 then +>Subscribe MqtR, BulbChambreAmi/stat/POWER endif

YvesLev commented 4 years ago

Ok, +> works !!!

Funny, cause I tried yesterday the "->" variant and had same problem and stopped there with the variants lol.

Big Thanks!

Should we close this issue? I think at least the documentation should be revised and also the cook book to show an example of use with the mqttc thing etc...

gemu2015 commented 4 years ago

ok, leave it open for others. i will examine why that variant works and others not. +> allows for recursion but i am sure it also worked with => when i developed the call.