-
Micropython : ESP32_GENERIC_C3-20240602-v1.23.0 , Board ESP32C3 mini , Thonny 4.1.4. As code i'm using the examples found in the doc , adding just few changes . A WLAN interface must be active to send()/recv()sta = network.WLAN(network.STA_IF) # Or network.AP_IF e = espnow.ESPNow() for i in range(1000): ` For the Receiver this is the code: `import network A WLAN interface must be active to send()/recv()sta = network.WLAN(network.STA_IF) e = espnow.ESPNow() while True:
This is what i see on the Thonny console from the transmitter :
MPY: soft reboot While from the receiver I got : _>>> %Run -c $EDITOR_CONTENT MPY: soft reboot Seems that the receiver code still waiting to receive data from the trasmitter. What other test can I do , having already changed also both board ? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Which boards do you actually use. There are micro ESP32C3 boards sold at very low price which have a very bad antenna design. Side note: Use lines with 3 backticks ``` before and after the python code for proper display. |
Beta Was this translation helpful? Give feedback.
-
Hi Robert, |
Beta Was this translation helpful? Give feedback.
-
These are indeed the boards with the poor antenna design. However, at a short distance of a few meters they should work. About formatting: When using the <> icons for code, pleas highlight the code before pushing <>. Then the lines with three backticks are added. If you just highlight short text, it adds single backticks. Pushing the <> icon is the as as entering Ctrl-E. |
Beta Was this translation helpful? Give feedback.
-
You can try running both of these scripts. # sender.py
import network
import espnow
# A WLAN interface must be active to send()/recv()
ap = network.WLAN(network.AP_IF) # Or network.AP_IF
ap.active(False)
sta = network.WLAN(network.STA_IF) # Or network.AP_IF
sta.active(True)
sta.disconnect() # disconnect from access-point (if any)
e = espnow.ESPNow()
e.active(True)
bcst = b'\xff\xff\xff\xff\xff\xff' # MAC address of peer's wifi interface
e.add_peer(bcst) # Must add_peer() before send() on esp32
# esp8266 don't listen to broadcast message
e.send(bcst, "Starting...")
for i in range(10):
e.send(bcst, str(i)*10, True)
host, msg = e.recv() # Blocking
if msg: # msg == None if timeout in recv()
print(host, msg)
e.send(bcst, b'end')
# receiver.py
import network
import espnow
# run this on esp32-xx
#
# A WLAN interface must be active to send()/recv()
ap = network.WLAN(network.AP_IF)
ap.active(False)
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.disconnect() # disconnect if MCU auto-connects to last Access Point
e = espnow.ESPNow()
e.active(True)
while True:
host, msg = e.recv() # Blocking
if msg: # msg == None if timeout in recv()
print(host, msg)
# host = mac address of sender
# now we can use the mac address to reply
try:
e.add_peer(host)
except:
pass
e.send(host, 'Hello')
if msg == b'end':
break These are my run logs. I use mpremote, I think you should do the same.
Then start the sender.
I hope these are of some help. If you are interested in learning more about dynamic meshing with ESPNow, please take a look at this repository. |
Beta Was this translation helpful? Give feedback.
-
As suggested by @robert-hh , it is much easier to help if you format your code so we can read it more easily. Follow the advice at https://github.com/orgs/micropython/discussions/9111.
import network
import espnow
import utime
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF) # Or network.AP_IF
sta.active(True)
e = espnow.ESPNow()
e.active(True)
peer = b'd\xe83\x8a\xdd\xcc' # MAC address of peer's wifi interface
e.add_peer(peer) # Must add_peer() before send()
print('Peer MAC : ', e.get_peers())
utime.sleep_ms(50)
e.send(peer, "Starting...")
for i in range(1000):
e.send(peer, str(i)*20, True)
e.send(peer, b'end', True)
import network
import espnow
import utime
# A WLAN interface must be active to send()/recv()
sta = network.WLAN(network.STA_IF)
sta.active(True)
#sta.disconnect() # Because ESP8266 auto-connects to last Access Point
mac_address = sta.config("mac")
print(mac_address)
print("Device MAC Address tx:", ":".join(["{:02X}".format(byte) for byte in mac_address]))
e = espnow.ESPNow()
e.active(True)
while True:
print("wait")
host, msg = e.recv()
print("received")
if msg: # msg == None if timeout in recv()
print(host, msg)
if msg == b'end':
break
print('no data received')
Yes. Check the documentation
So, you could try printing the return value from
One thing to check if you are having problems is to make sure that you perform a hard reset before running your test, as the wifi radio can sometimes be left in a bad state after a soft reset. |
Beta Was this translation helpful? Give feedback.
-
At the end as suggeste by @robert-hh the problem is due to the real poor quality of these board. On a set of 8 board ,all bougt from the same supplier ,I've found some board defective . Using the right boards the code suggested by @shariltumin works fine. What is really strange is that in most of the cases the boards are ok as trasmitter but fails as used as receiver . Another thing that I've noticed is that the esp32 chip are very hot but I've no way to compare with other kind of esp 32 boards. Unfortunately for my project I need a very small for factor and the ESP32 C3 mini was the right one, but is not easy have boards of good quality.In a previous set of 4 board bough from another supplier I got all boards with the espr32 c3 cip with inside flash memory, so unusable . Pay attention if you buy these kind of board on Aliexpress. |
Beta Was this translation helpful? Give feedback.
At the end as suggeste by @robert-hh the problem is due to the real poor quality of these board. On a set of 8 board ,all bougt from the same supplier ,I've found some board defective . Using the right boards the code suggested by @shariltumin works fine. What is really strange is that in most of the cases the boards are ok as trasmitter but fails as used as receiver . Another thing that I've noticed is that the esp32 chip are very hot but I've no way to compare with other kind of esp 32 boards. Unfortunately for my project I need a very small for factor and the ESP32 C3 mini was the right one, but is not easy have boards of good quality.In a previous set of 4 board bough from another sup…