glenn20 / micropython-espnow-images

A collection of pre-compiled micropython images (including espnow support) for the esp32 and esp8266.
102 stars 9 forks source link

RSSI function 'e.peers' returns AttributeError in v1.18-10 and v1.18-6 on ESP8266 D1 mini #19

Closed j-siderius closed 2 years ago

j-siderius commented 2 years ago

Good morning Glenn,

When using your newest ESPnow images with RSSI support (v1.18-10-ge68d28c8b or the earlier v1.18-6-g24cf16719) on a Wemos D1 mini ESP8266 board, the e.peers function returns an AttributeError: 'ESPNow' object has no attribute 'peers'.

For testing, I have two D1 mini ESP8266 boards with the firmware (either both v1.18-10 or v1.18-6, flashed using esptool 3.3 from the Espressif github) and running the following code:

Sender

import network
from esp import espnow

w0 = network.WLAN(network.STA_IF)
w0.active(True)

e = espnow.ESPNow()
e.init()

peer = b'\x84\x0d\x8e\xaa\xaa\xaa'   # < edited the last part of MAC address

e.add_peer(peer)

e.send(peer, "ping", True)  # < returns True in shell

e.peers  # < returns the aformentioned AttributeError

Receiver (start this first so it is listening)

import network
from esp import espnow

w0 = network.WLAN(network.STA_IF)
w0.active(True)

e = espnow.ESPNow()
e.init()

peer = b'\xd8\xf1\x5b\xbb\xbb\xbb'   # < edited the last part of MAC address

e.add_peer(peer)

while True:
    host, msg = e.irecv(0)
    if msg:
        print(host, msg)  # < prints 'bytearray(b'\xd8\xf1\x5b\xbb\xbb\xbb') bytearray(b'ping')' in shell
        if msg == b'ping':
            e.send(peer, "pong", True)

The full error message:

Traceback (most recent call last):
   File "<stdin>", line 16, in <module>
AttributeError: 'ESPNow' object has no attribute 'peers'

Sending messages using your ESPNow images works perfectly, so I'm at a loss why the new function for RSSI doesn't seem to work or even exist... If I am reading the documentation correctly, even when there would not be an RSSI values in the table yet, the e.peers function should at least return {peer: [None, None]}, but it doesn't even do that.

Any help would be greatly appreciated!

glenn20 commented 2 years ago

Thanks for reporting this issue. Unfortunately the rssi monitoring feature is only available on the esp32 variants (not esp8266) and I overlooked to clarify that in the documentation. I apologise for any time lost due to that oversight.

I have updated the docs in the espnow-g20-dev branch and that should make it into the espnow-g20 branch soon.

The principal reason I have not added this feature to the esp8266 port is that the code size would no longer fit within the .text segment boundary on the default micropython builds. Also - I have not tested that the hackery to extract the rssi value works on the esp8266.

IF it does work it would be possible to port this feature to the esp8266, but it could not be enabled in normal micropython esp8266 builds. However, users would be able to compile it in by removing some other micropython features from their image build. I am closing this issue as it is addressed in the fixup to the docs - however, I have put a todo on my task list to check if rssi values are extractable on the 8266.