- Tue Jan 17, 2017 12:09 am
#61115
Thanks for the reply forlotto
![Wink ;)](./images/smilies/icon_e_wink.gif)
The two ESP's are both Lolin/NodeMCU boards with 12E's on (although I have tried the same code on the yellow ESP12 evaluation board and on an ESP-07 and get the same results).
I thought it might be me, so I went back and started from the basics ...using Mikes ESP to ESP Communication as a starting point ...although that's written for the older version of BASIC, I updated it and added test branches to see how often the problem occurs.
I'm using the newest Alpha 65 3.0 Branch
The programs I've put together just for testing consist of code for the receiving side, this just sits there and flashes the blue led on the ESP when it receives a Msg and sends the msgreturn message back, it only shows that it's running when viewed from a browser (and shows if any incorrect Msg data is received.. which only happens if you purposely send anything other than an "ON" or "OFF")
Receiver Code:
Code: Select allmemclear 'CLEAR MEMORY
cls 'CLEAR SCREEN
minutes = ((millis()/1000) /60) 'DISPLAY UPTIME IN MINUTES
print "Uptime Minutes: " & minutes 'TO SEE IF ESP HAS REBOOTED
print "Waiting for alternating ON/OFF msg"
print
button "Exit",[exit]
msgbranch [doit] 'MSGBRANCH
wait
[doit] 'JUMP HERE IF MSG RECEIVED
status=msgget("stat") 'status = "stat" FROM MSG
if status <> "ON" and status <> "OFF" then print status 'IF status IS NOT "ON" OR "OFF" THEN PRINT status
if status="ON" then io(po,2,0) 'TURN ESP LED ON IF status = "ON"
if status="OFF" then io(po,2,1) 'TURN ESP LED OFF IF status = "OFF"
if status = "ON" or status = "OFF" then myrtnmsg="MSG OK" else myrtnmsg="MSG ERROR" 'SET RETURN MSG TO "MSG OK" IF "ON" OR "OFF" RECEIVED, "ERROR" IF ANYTHING ELSE
msgreturn myrtnmsg 'SEND RETURN MSG
wait
[exit] 'EXIT ROUTINE
cls
wprint |<a href="../edit">[EDIT]</a>|
wprint " "
wprint |<a href="../run">[RUN]</a>|
wprint " "
wprint |<a href="../debug">[DEBUG]</a>|
end
The Sending side also flashes the ESP's blue LED when it sends a "wget" message, and when running doesn't show much in a browser either (I wanted to let them run, and only let me know if an error occurred). The blue flashing LED's let me know their running, and only if an error occurs will the details appear in the browser window.
The Sending side is set to send an alternating "ON" / "OFF" message every second automatically using the Timer option. (I've included options for web button and ESP switch operation ...rem'd out... if anyone wants to spend their time continually pressing it until an error occurs!).
The receiving ESP needs to be started first or the Sending ESP gets a bit upset that it can't find anyone to talk to!
After setting the receiving side to Run, then Running the Sending side, both ESP blue LED's should flash (almost in unison) as one illuminates when it's sent the Msg and the other only flashes when it receives the Msg... this being almost instantly though, so it looks like they are flashing together.
I leave them run like this... (leaving both their browser pages open on my PC)... and check on them every 5 minutes or so. Sometimes they can run for a while without an error, but eventually an error will occur, sometimes every few minutes, sometimes after half an hour ...it's getting to the bottom of these errors which is driving me mad, I need them to be reliable (or reliable as possible).
Sending Code:
Code: Select allmemclear 'CLEAR MEMORY
cls 'CLEAR SCREEN
minutes = ((millis()/1000)/60) 'DISPLAY UPTIME IN MINUTES
print "Uptime Minutes: " & minutes 'TO SEE IF ESP HAS REBOOTED
print "Sending alternating ON/OFF msg"
print
button "Exit",[exit] 'EXIT BUTTON
LED=0 'DEFINE LED
rcvmsg="" 'DEFINE rcvmsg
timer 1000,[send] 'TIMER OPTION
'button "Send",[send] 'WEB BUTTON OPTION
'interrupt 0,[send] 'ESP SWITCH OPTION
wait
[send]
if LED=0 then io(po,2,0) else io(po,2,1) 'TURNS LED ON ESP ON OR OFF
if LED=0 then rcvmsg = wget("192.168.1.17/msg?stat=ON") 'SENDS ON TO OTHER ESP, RECEIVES RTN MSG
if LED=1 then rcvmsg = wget("192.168.1.17/msg?stat=OFF") 'SENDS OFF TO OTHER ESP, RECEIVES RTN MSG
if LED=1 then LED=0 else LED=1 'FLIP-FLOP TO SWAP BETWEEN ON AND OFF
if rcvmsg <> "MSG OK" then print "ERROR: " & rcvmsg
if rcvmsg = "No MSG Branch Defined" then print "RECEIVING ESP ON BUT NOT RUNNING"
if rcvmsg = "" then print "RECEIVING ESP TURNED OFF / NO REPLY / NULL REPLY RECEIVED"
wait
[exit] 'EXIT ROUTINE
cls
wprint |<a href="../edit">[EDIT]</a>|
wprint " "
wprint |<a href="../run">[RUN]</a>|
wprint " "
wprint |<a href="../debug">[DEBUG]</a>|
end
Hopefully someone will be able to find the error, show me where I may of made an error, or offer an alternative (reliable) solution
![Wink ;)](./images/smilies/icon_e_wink.gif)
I'm thinking it might be something with the Wget function (possibly) ..and wondered if maybe there was another way of receiving the returned message.
Oh, and don't forget that both the IP's need to be changed in the Sending side code (in the "wget" function lines), to the IP of the Receiving ESP