Open msillano opened 6 years ago
Recursion is not supported (only one level of "on" statements). Perhaps I should have a view into the script.
Flashing the binary doesn't delete the script. If you want to, do this:
esptool.py --port /dev/ttyUSB0 erase_flash
A language, to be "Turing complete" must have 3 structures: sequences, selections (if, or case, - all are equivalents) and iteractions (while or do or for - all are equivalents). The MQTT script is missing iterations. Iterations can ben done also with function recursion, but it looks that script do not allows recursion. So it is important to add some form of iteration:.
The simplest form is maybe ' while
Why I need it?
I try to give you the idea (test code not whit me now, I can send it you later): a timer, doing tasks at any time: ex: @08:25 (long 3 min), @10:30 (long 12 min), @12:07 (long 4 min), etc....
A json structure (in @X) keeps in arrays the start times (ordered) and the durations:.
I can access it using json_parse() and an index...
The problem is at the start: if Sonoff starts at 09:10, I must set the alarm to 10:30:. To do this I must to iterate over the full array, to find the first start time bigger than 09:10: no alternatives, no way.
To give you an idea of the application, see https://github.com/msillano/sonoff_watering (work in progress not full finished), This poject is simpler. because it do not need iterations: times are only 2, T1 and T2, but it is very near at the new one.
Martin, thanks for your time. Regards
p.s. I read again your answer: My recursion is not on "on topicR": they are flat (like a switch statment). I use "on topicR" as a procedure with side effects. Recursion is inside the ''on topicR'" expression: I can execute a "publish local topicR" for the same "topicR"... It is allowed ??? if yes, the recursion is possible. (my test program must have a banal error producing infinite loop). Tomorrow i will kill the bad script and do some tests....
Marco,
as a computer scientist I was aware, that the language is not "Turing complete". Actually, it was originally never intended to be. A downside of being "Turing complete" is the "Halting problem" or even less, the ability to code arbitrary long loops. I was thinking of small action-response clauses, that cannot block the CPU...
For more sophisticated apps I thought using the uMQTTBroker lib with an Arduino sketch would be a generic solution.
Nevertheless, I will think about a "while" loop...
Cheers, Martin
Just added a "while do" to the language... ;-)
hahaha wonderful ! Thanks. i will try it soon.
Testing a recursive script, Sonoff goes on loop. Using the serial console (PuTTY) I get:
I cannot insert any command !. I also re-flashed the Sonoff (using last bin files) but it stiil loops :( Any idea? I'm trying to do iterations using 'on topic' as recursive function. So it is possible that the script (wrong) goes in infinite loop, giving a stack error. But flashing Sonoff don't clear the script?
Best regards Marco