Strange ESP-Now Issue - SOLVED

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Strange ESP-Now Issue - SOLVED

Post by MMliam » Thu Jul 28, 2022 5:26 pm

Using two ESP8266 as ESP-Now senders and one ESP32 as an ESP-Now receiver.
The code in the two ESP8266's is identical.
Both ESP8266's have the same micropython builds - v1.191(583K)
ESP8266 Code (In Part)

Code: Select all

enRcvr = b'\x78\x21\x84\x9b\x57\xf4'    # Unit ESP32-001
devState = bytes('On', 'UTF-8')
ackRcvd = False
TryCnt = 0
Tstart = time.ticks_ms()
while TryCnt < 3 and not ackRcvd:
    print('\nSending')
    ackRcvd = eNow.send(enRcvr,devState,True)
    TryCnt += 1
ESP32 Receiver Code (In Part)

Code: Select all

while True:
    recvSender, recvMsg = eNow.irecv(recvWait) # Default timeout = 5 mins (wait on recv if neg).
    if recvMsg != None:            # msg == None if timeout in recv()
        Sender=ubinascii.hexlify(recvSender)
        Message=recvMsg.decode('ascii')
        print(Sender,Message)
        if Sender == Sensor001:
            print('Sensor001: '+str(Message))
Each sender will try 3 times to send; after which it returns to REPL
The first ESP8266 (Sensor001) sends once, and receives an acknowledge; the receiver's recvSender has it's MAC, and recvMsg has the message sent.
The second ESP8266 (with identical code) tries to send 3 times then returns to REPL; the receiver's eNow.irecv(recvWait) does not return anything and times out after one minute.
Both ESP8266 modules were tested with identical code to confirm wifi connection; making sure the respective radios were functional.

Any suggestions as to why one ESP8266 is received and the other is not?
Last edited by MMliam on Thu Jul 28, 2022 11:44 pm, edited 1 time in total.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Strange ESP-Now Issue

Post by davef » Thu Jul 28, 2022 7:52 pm

Just an idea
- don't power-up ESP8266 #2:
- reboot the other two devices, confirmed received message on ESP8266 #1
- power-down ESP8266 #1
- reboot the other two devices, confirmed received message on ESP8266 #2

Repeat the whole process while trying to send two messages to each ESP8266.

Are you doing hard-rests each time?

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Strange ESP-Now Issue

Post by MMliam » Thu Jul 28, 2022 8:23 pm

Hi Dave, How are you doing.

First, I should explain I haven't been running the two senders at the same time. I would plug-in one say #1 and it would work; unplug #1, plug in #2 and the receiver wouldn't receive the sent (3 times) message. As I mentioned, I did confirm by installing code that uses MQTT on #2, that it can send wifi signals; so the radio is functional.

Everything was going so smoothly with #1 talking ESP-Now to the Gateway, and the Gateway passing that information via MQTT to Node-Red flows; smoothly that is until this mystery popped-up.

BTW: I am booting the the units.

Thanks for the reply,

Mike

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Strange ESP-Now Issue

Post by davef » Thu Jul 28, 2022 8:31 pm

Hi Mike,

The tests were to confirm that the problem was really confined to the one specific ESP8266. So, on the the unit that does work can you send two messages and receive them?
Last edited by davef on Thu Jul 28, 2022 9:06 pm, edited 1 time in total.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Strange ESP-Now Issue

Post by MMliam » Thu Jul 28, 2022 8:48 pm

On the unit that does work, I can send as many messages as I like and they are all responded to by the receiver after just a single send attempt.
I'm using two instances of Thonny to monitor the sender & receiver; I've even tried swapping the USB connections with the same result; the unit that works, still works, and the unit that fails still fails.

Even though the microPython seems to be functioning on the unit that's failing, I'm going to re-flash to see if that has any affect.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Strange ESP-Now Issue

Post by MMliam » Thu Jul 28, 2022 9:10 pm

Well the re-flashing failed, after several attempts and variations in the esptool flash-mode. That might have answered the question, but I had previously tried a third ESP8266, loading it with the same software and it failed to get a message to the receiver. It's beginning to look like that one unit is magic - lol

Update: I got it to flash, made a rookie mistake; forgot to check the interpreter; I was last using the ESP32.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Strange ESP-Now Issue

Post by davef » Thu Jul 28, 2022 9:29 pm

O dear ... a bit confusing.

My current issue is that I only get the first message, re-boot and only the first message again.

Good luck!

Do you check the mac just before you try to send something?

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Strange ESP-Now Issue

Post by MMliam » Thu Jul 28, 2022 9:38 pm

SUCCESS!!!
Apparently, re-flashing micropython and reinstalling the software (Boot & Main), solved the problem. I still don't see how microPython could function in every other respect, but fail with ESP-Now. Before flashing I even checked to see if an ESP-Now object was actually created; it was assigned a memory location - go figure. :?

I may have lead you astray when I said I can send as many messages as I want; that's with each reboot. Normally the sender will be in deep-sleep and awakened by re-booting. However, I can check if I can send multiple messages without rebooting.

MMliam
Posts: 121
Joined: Mon May 07, 2018 1:08 pm

Re: Strange ESP-Now Issue

Post by MMliam » Thu Jul 28, 2022 9:59 pm

Dave,
The first send went normally, however, I got this error on the second pass trying to send:
Sending
Traceback (most recent call last):
File "main.py", line 32, in <module>
OSError: -3
Line 32 is my ESP-Now send.
Is this the error you're getting?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: Strange ESP-Now Issue

Post by davef » Thu Jul 28, 2022 10:13 pm

Hmmm, I don't get an error message just doesn't work the 2nd time. How do you raise the error message?

Post Reply