Post about your Basic project here

Moderator: Mmiscool

User avatar
By Edi
#59176
joeygbsn wrote:Here is some simple udp code to toggle a relay. Both of the esps set up udp servers.
[/code]


Thanks to joeygbsn, the code would be exactely what I need ... but it doesn't work for me. :(
At first, there is an error in the codebox. The Button-Command and the following two lines need to be written in one line, otherwise there would occur an error.

After correcting that, there was the need (no remember why) to write the if-then-else-endif in separate lines:
if data = 1 then
let data = 0
else
let data = 1
end if

But than there comes a new error in line 14: "Comparaison between string and number!"
Line 14 contains the command "let data = 0".

But also to write al commands related to "data" as a string doesn't work. E.g.:
let data ="1"

With the quotation marks for the value of "data" occurs no error, but the button doesn't do anything else than to become yellow, after pressing it.
No portpin is canging on one of the ESP-Modules.

The hint from Mmiscool in the last posting didn't fix it, but I'm not absolutely sure, where to place this command?

Maybe something in my settings on one ore both ESP's is wrong?
I tryed there many things. Actually I have there nothing else than the IP-adresses (192.168.0.102 for the Master and 192.168.0.109 for the Slave), the Subnet (255.255.255.0), the Gateway (255.255.255.0) and the "Server listening port" is 80.
Of course the Box "Run default.bas at startup" is enabled.

joeygbsn, could it be that the code was tested in not exactely this form?
Or do you have any ideas what may cause the problems?
User avatar
By Edi
#59230 Oh, now the code works!
The main problem was related to my Webbrowser. Because I found the code above by using the search field, there happend some strange stuff with the code in the box, like linebreaks and other things.
After entering the thread in a normal way, it was possible to use it, per copy it from the website and paste it into the edit field of the ESP8266Basic, many thanks to the author!

But it ist to say (maybe it can help other people), that the code allone wansn't enought. It's necessary to make the right (and different) settings in the setting section of both modules.

It is too early for me, to share my solution, because I have to do some changings for my own need and I get many many many problems all the time with the stability of the modules, also with the strange behavior, that sometimes everything works fine, but sometimes not. I think there is need for a much better error handling, for cases like timewise corrupted connection between the modules.
I tried out different modules, like NodeMCU, Witty and other, with soldering additional capacitors direct to VCC and GND and so on, but until now, nothing solves my temoparily problems.

But what I can say: If the connection works, than also the code from joeygbsn does!
Many thanks to him, for sharing it! It's a usefull base for going further.


There is one thing left, that seems strange for me: I come from Atmel AVR and BASCOM. There it was so, that a seriell incomming triggered an Interrupt, so that the programm knows, there are datas to pick up.
The code above goes an other way: It uses a timer to look periodically for incomming datas.
I must say, that this seems a bit strange for me, because most of the time there are no datas, why "bothering" a timer for nearly nothing?
Isn't there a way to implement an UART-interrupt?
User avatar
By Mmiscool
#59231 It is possible to use a serial interrupt to trigger things.

See SERIALBRANCH in the docs
https://docs.google.com/document/d/1EiY ... ovtmhm2x8z