Questions with regards to ESP8266 Basic and hardware interfacing and control via Basic commands

Moderator: Mmiscool

User avatar
By Boxey
#61073 I have an ESP which receives data using "msgbranch" / "msgget", upon receiving the data, it sets and returns a "msgreturn" message.

This all works fine when sending the data using "http://192.168.1.1/msg?action=on" from a browser, and it returns the "msgreturn" message to the browser as expected, however, I want to send the data from another ESP instead of the browser, and collect the "msgreturn" message to perform other functions.

To do this I'm using "wget" which sends the data from the sending ESP to the receiving ESP ..which works fine, and the "msgreturn" message comes back too .... HOWEVER .... sometimes, instead of getting the "msgreturn" message back, I get:

HTTP/1.1 200 OK Content-Type: text/html Content-Length: 3 Connection: close Access-Control-Allow-Origin: *

Which throws things a bit, and I have no idea why I'm getting this sometimes (but not all the time), and if there is anything I'm doing wrong or what I could do to fix it.

Any ideas would be appriciated ;)
User avatar
By forlotto
#61076 Are you at liberty to share the code or a code example of what you are doing but not exactly it never fails me unless I do not wait for my phone application to load correctly.

How is it setup locally or remotely remote connection will take longer also if you switch between wifi lets say and cell tower during this time you may get that error. Be sure you are alive and connected to whatever service.

I am almost sure there is a solution to your problem. One thing I noticed is the SON SOFF switch seems to have troubles coping sometimes like this but never a nodemcu SONSOFF is very fussy.

What hardware?
What Network?
How is it configured?
What code are you using?
User avatar
By Boxey
#61115 Thanks for the reply forlotto ;)

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 ;)

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 ;)
User avatar
By forlotto
#61164 mymsgs = "ERROR"
if status = "ON" then mymsgs = "OK"
if status = "OFF" then mymsgs = "OK"

msgreturn mymsgs

Try something along this line.

I am not sure about rcvmsg useage is correct I think it is likely a misunderstanding that you believe rcvmsg is something baked into basic that will just automatically real lines on the screen which I do not think is correct you may want to wait for mike on this one I believe you have a few things mixed up with your send subroutine unless something exists that I am not aware of. how do you ever print an error from msg ok? How are you getting No MSG Branch Defined? Maybe it is there I've never had a need for it personally, or I missed it, or it is something in the newer versions not in the documentation? But for me it is like you are expecting the computer to read your mind rather than having it do what you tell it to do if this makes since.

It is also good practice to use spaces between LED=1 like so LED = 1 I recall some builds where not using spaces caused all types of issues. Been a while since I played with the basic parts of this been trying to get voice commands going on my android and am successful I will really break things apart and try it out if you are still having trouble after this but for now I have reached my time limit sorry I have to spend some time winding down before bed but I will better explain where you need explanation it just seems like you understand most of what you are doing but not understanding small bits of how things are working. As I said though I could be wrong here it was a rather quick read through so ... I need to take more time and give it a shot.





Sorry if I hurt more than helped here but hopefully a couple of useful bits of info.