LoPy vs L01 (OEM module)
-
I have simple LoRa raw code that runs perfectly fine with two LoPy devices talking to each other. But the same simple code causes the exception error #11 EAGAIN when running on an L01 module. Pybytes, Device, Firmware, Python, and MicroPython all report the same on both devices. The code and output (from the L01) is shown below. The L01 always crashes on the 4th 'ping' from socket.send().
Is there some difference between the LoPy and the L01 OEM that requires a different LoRa setup or firmware version?
Code
from network import LoRa import socket import machine import time import uos import sys from network import Bluetooth lora = LoRa(mode=LoRa.LORA, region=LoRa.US915) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) print("PING Unit") print('Device: ' + uos.uname().machine) print('Firmware: ' + uos.uname().release) print('Python: ' + sys.version) print('MicroPython: ' + str(sys.implementation.version[0]) + '.' + str(sys.implementation.version[1]) + '.' + str(sys.implementation.version[2])) print('===============================================================================') print('Switching off Bluetooth') bt = Bluetooth() bt.deinit() s.setblocking(False) while True: print("Send 'Ping'") s.send('Ping') print("Waiting...") data = s.recv(64) print(data) if s.recv(64) == b'Pong': print("Got 'Pong'") time.sleep(2)
Output
![alt text](image url)
-
In case anybody else has this problem. In our case it was either a defective L01 OEM module or a manufacturing defect with the PCB. We built a second unit and the LoRa worked fine in that L01 module. It did not hang or crash, and the LoRa pings worked fine over several minutes of testing.
-
@anthony The transmission speed is the same for both devices. But as @mgranberry pointed out, the program logic is wrong in two aspects:
a) s is set nonblocking. That means, the code will continue immediately once s.send() was called, not waiting for the data to be sent. Similar, the immediately s.recv() will return immediately with either the data which as received beforehand, or None. So at the print statement "Waiting..." it does not wait. The code waits after the second s.recv()
b) you call s.recv() twice in a loop (that's what @mgranberry expressed with his comment).
The whole code is similar to the examples here https://github.com/pycom/pycom-libraries/tree/master/examples/lopy-lopy
-
@robert-hh Do you know how or why this would cause error #11 from the LoRa send command in the code example I listed? Even at its slowest I would assume the LoRa can push ~180 bps, so sending 4 chars every 2 seconds should be easy?
-
@mgranberry This code as-is will work fine with two LoPy boards that ping each other back and forth. The error actually occurs with the "s.send()" line. If I take the receive code out and just have the send and the sleep I will still get "EAGAIN".
-
@anthony The difference between LoPy (assuming LoPy 1) and L01 is the memory size. L01 has 4 MB SPIRAM, which LoPy1 does not have. That affects the timing of code. LoPy1 runs slightly faster. Especially external events are served faster.
-
I think you might have intended
if s.recv(64) == b'Pong':
to beif data == b'Pong':
. I think you have an empty buffer.