rdlaner / ESPNow_Gateway

ESPNow to MQTT Gateway project.
0 stars 0 forks source link

Simultaneous ESPNOW and WIFI in Circuitpython #1

Open bborncr opened 9 months ago

bborncr commented 9 months ago

I have been looking at your gateway code and notes, trying to figure out how to simultaneously receive ESPNOW packets while being connected to an AP. Below is my attempt at the minimum receiver setup. Sorry to bother you with this but I can't find anyone working with CircuitPython and ESPNOW.

import espnow
import wifi

print("Connecting...")
wifi.radio.connect("ssid", "password")
wifi.radio.start_ap("noop", "12345678")
print("Connected to Wifi!")

e = espnow.ESPNow()

while True:
    if e:
        packet = e.read()
        print(packet)
rdlaner commented 9 months ago

Sure, happy to help. First, it might help to take a look at the EspnowProtocol class I wrote. This serves as the transport layer for the miniot protocol used in this bridge repo: https://github.com/rdlaner/CircuitPython_Libs/blob/main/cp_libs/protocols/wifi_protocols.py#L36

One thing you are missing your minimal setup is that you need to add to your receiver the mac address of each device you want your receiver to listen to. Circuitpython does that with the peers list. Let me know what issues you are running into specifically and I'll see if I can help more.

bborncr commented 9 months ago

Thanks for the help!

Although I believe that the peer list goes in the sender I did add it to the receiver code but no change. If I comment out the 'wifi.radio.connect' line I start to receive packets. Is all that is needed is 'start_ap'? Or is there something else regarding channels. I have left the channels default.

import espnow import wifi

print("Connecting...") wifi.radio.connect("ssid", "password") wifi.radio.start_ap("noop", "12345678")

print("Connected to Wifi!")

e = espnow.ESPNow() peer = espnow.Peer(mac=b'\xd4\xd4\xda\x16\xb7\x1c') e.peers.append(peer)

while True: if e: packet = e.read() print(packet)

On Tue, Nov 21, 2023 at 10:28 AM rdlaner @.***> wrote:

Sure, happy to help. First, it might help to take a look at the EspnowProtocol class I wrote. This serves as the transport layer for the miniot protocol used in this bridge repo:

https://github.com/rdlaner/CircuitPython_Libs/blob/main/cp_libs/protocols/wifi_protocols.py#L36

One thing you are missing your minimal setup is that you need to add to your receiver the mac address of each device you want your receiver to listen to. Circuitpython does that with the peers list. Let me know what issues you are running into specifically and I'll see if I can help more.

— Reply to this email directly, view it on GitHub https://github.com/rdlaner/ESPNow_Gateway/issues/1#issuecomment-1821441698, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMSMCOPXC4OEORQUQMKAUTYFTXEFAVCNFSM6AAAAAA7U2WEUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRGQ2DCNRZHA . You are receiving this because you authored the thread.Message ID: @.***>

-- Bentley Born CRCibernetica.com Mobile +1 (250) 580-4457 bentley@ @.***>crcibernetica.com

rdlaner commented 9 months ago

Good point, you would only need to add the peer list to the receiver if you plan on sending messages back to the sender.

You're also correct about the channels. Both devices need to be on the same channel in order for this to work. This page is a helpful reference even though CircuitPython does things slightly differently: https://docs.micropython.org/en/latest/library/espnow.html#espnow-and-wifi-operation