First contact with LoRa... No success
-
Hi all!
For my first try to implement LoRa I just used the LoRa (Raw) Gateway example. My setup:Gateway: PyTrack with a Lopy4
Node 1: L01 on a custom baseboard
Node 2: Lopy4 on a Expansionboard 3.0Everything is at the latest stable firmware and all devices are equiped with a Taoglas FXP.280 LoRa antenna.
At the nodes I just added a timeout for the response from the gateway. My radio scanner shows me, that the nodes are sending something at the right frequency, but the gateway receives just nothing. I changed the role of the devices in every possible way, with no efford.Is there something else I need to do? Switching of the WLAN or something else? But especially for the gateway, it's very impractical, to have no WLAN, isn't it?
Cheers,
Thomas
-
@thosch42 Thanks for the progress update. Glad you managed to get it to work.
Just to note. "Empty" messages are intentional. calls to recv are blocking and will eventually timeout returning an empty message if no data has been read during that period.
-
Ok, and if I switch back to my original code, and set
tx_iq=False
the whole thing works pretty fine. I can forward my LoRa messages to MQTT, and everything looks great...Cheers,
Thomas
-
Ok, now I switched the L01 (Device 3) back to the original node code, I already posted before. And... I get nothing from it on the two other devices. They only see each other.
The only big difference I can see, is this optiontx_iq=True
in the LoRa init. Unfortunately, I do not know what "enables TX IQ inversion." exactly means. But if I set it totx_iq=False
, I an see the messages from Device 3 on the two other devices.
If I now set tx_iq to True on all three devices I receive on Device 1:b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b'' b''
and on Device 2:
b'' b'' b'' b'\xb0C\x81aR\x14zT\xa9\x9d\x9dI\x82\x1d\x1e\x9a\x0e\x99\x02\x8c\x8b@\x7f\x0b\x1a\xcb\r\x1f\x8em\xb3\x1a\xf07\xbf&\xcf\xf2\x08\xa1\xb7\x9e\xf6Y\x04\x8a\xc0\x9e\xce@"\x0c2^\n)\xfd\xcc3\x1f\x97\xd4t(' b'T\xaa\x7f\xa3\xd4-\xb964P\x03\r\x00\x8f\xa7\xe2\x84j\xef\x8f\\\xaa\xeeV\xbe1\x94\n\xb0\x0f\x98XAo\xf2E\x0e\x05\nm&}\x93T\x11l\xa3\x07d\xa0%\xac\x01\x7f)7\xab\xc1\xe8\x13\xfb\x88\xfc\x1d' b'\x9f\x04\n\xa8\xec\x8fj*\x1a\xc7n\xffo{\x963\x8a\x00\xb0\xa2\xbf\x9c\xb6\xa7\xc0\x0f\xa21\xd4\x10\xd3v\xde\xb9\x97\x9aE\xce\xed\tk\xa9$f\x92\x8d\xec@Z\xf1\xd6\x86\xe8N\x94\xba\x0b\x93\xbcD4J\x16\xdb' b'\x08f\n\xcc].a\x1bGc\rfQ\x10y\x87\xec?\x7f"\xc8\xf89\x19U\x8a' b'' b'' b'' b'' b'' b'' b'' b''
Just as an example.
So, do I have to dig in the sources or is there any further explanation of this option anywhere?Cheers,
Thomas
-
@thosch42
And made it a little bit more complex with a 3rd device, the L01 on my custom baseboard.
Device 1: PyTrack \w Lopy4
Device 2: Expansionboard 3.0 \w Lopy4
Device 3: Custom baseboard \w L01
Device 1:b'Hello-2' b'Hello-2' b'Hello-3' b'Hello-3' b'Hello-2' b'Hello-3' b'Hello-2' b'Hello-3' b'Hello-2' b'Hello-3'
Device 2:
b'Hello-1' b'Hello-3' b'Hello-3' b'Hello-1' b'Hello-3' b'' b'' b'' b'Hello-3' b'' b'' b'' b'' b'Hello-3'
Device 3:
b'Hello-1' b'Hello-2' b'Hello-1' b'Hello-2' b'Hello-2' b'Hello-2' b'Hello-2' b'Hello-1' b'Hello-2' b'Hello-2' b'Hello-2' b'Hello-2' b'Hello-2' b'Hello-2'
More or less what I had to expect, isn't it?
-
@jcaron said in First contact with LoRa... No success:
Have you tried the simpler https://docs.pycom.io/tutorials/lora/lora-mac.html ?
Ok, with the little bit simpler code I get "Hello" on both sides, mixed up with empty messages.
b'Hello' b'Hello' b'' b'Hello' b'Hello' b'' b'Hello' b'Hello'
Fine. It's a goog sign.
-
@jcaron Sorry! It's always better to show the code...
This is what I use for the gateway:
import socket import struct from network import LoRa#, WLAN import machine import config # A basic package header, B: 1 byte for the deviceId, B: 1 byte for the pkg size, %ds: Formated string for string _LORA_PKG_FORMAT = "!BB%ds" # A basic ack package, B: 1 byte for the deviceId, B: 1 bytes for the pkg size, B: 1 byte for the Ok (200) or error messages _LORA_PKG_ACK_FORMAT = "BBB" lora = None lora_sock = None def start_lora(): global lora global lora_sock print("Init LoRa radio...", end='') lora = LoRa(mode=LoRa.LORA, tx_iq=True, region=LoRa.EU868) print("Done!!!") print("Init LoRa socket...", end='') lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW) print("Done!!!") print("Disable LoRa blocking...", end='') lora_sock.setblocking(False) print("Done!!!") print("Ready to receive LoRa packets") start_lora() while (True): recv_pkg = lora_sock.recv(512) if (len(recv_pkg) > 2): recv_pkg_len = recv_pkg[1] device_id, pkg_len, msg = struct.unpack(_LORA_PKG_FORMAT % recv_pkg_len, recv_pkg) # If the uart = machine.UART(0, 115200) and os.dupterm(uart) are set in the boot.py this print should appear in the serial port print('Device: %d - Pkg: %s' % (device_id, msg)) ack_pkg = struct.pack(_LORA_PKG_ACK_FORMAT, device_id, 1, 200) lora_sock.send(ack_pkg) print("ACK send")
And this for the nodes:
import os import socket import time import struct from network import LoRa # A basic package header, B: 1 byte for the deviceId, B: 1 bytes for the pkg size _LORA_PKG_FORMAT = "BB%ds" _LORA_PKG_ACK_FORMAT = "BBB" DEVICE_ID = 0x02 lora = LoRa(mode=LoRa.LORA, tx_iq=True, region=LoRa.EU868) lora_sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW) lora_sock.setblocking(False) print("#1") while(True): # Package send containing a simple string msg = "Device 2 Here" pkg = struct.pack(_LORA_PKG_FORMAT % len(msg), DEVICE_ID, len(msg), msg) print(">>S>> ", end='') lora_sock.send(pkg) # Wait for the response from the gateway. NOTE: For this demo the device does an infinite loop for while waiting the response. Introduce a max_time_waiting for you application waiting_ack = True wait_ack_cycls = 5 while(waiting_ack): wait_ack_cycls -= 1 recv_ack = lora_sock.recv(256) if (len(recv_ack) > 0): device_id, pkg_len, ack = struct.unpack(_LORA_PKG_ACK_FORMAT, recv_ack) if (device_id == DEVICE_ID): if (ack == 200): waiting_ack = False # If the uart = machine.UART(0, 115200) and os.dupterm(uart) are set in the boot.py this print should appear in the serial port print("ACK") else: waiting_ack = False # If the uart = machine.UART(0, 115200) and os.dupterm(uart) are set in the boot.py this print should appear in the serial port print("Message Failed") else: if(wait_ack_cycls <= 0): waiting_ack = False print("Message Lost") else: time.sleep_ms(500) time.sleep(5)
Yes, I use the right antenna header (868MHz, NOT the one next to the reset button). I'm in Germany, so I use the EU868 frequency plan, exactly like in the example.
Cheers,
Thomas
-
@thosch42 Can you clarify which code you are using? Is it this one: https://docs.pycom.io/tutorials/lora/lora-mac-nano-gateway.html ?
Have you tried the simpler https://docs.pycom.io/tutorials/lora/lora-mac.html ?
What region/frequency band are you using?
Also note that the Lopy4 has two antenna connectors for LoRa (one for 800/900 MHz, the other for 433), make sure you use the right one (the 800/900 MHz connector is on the opposite side on the LoPy 4 compared to the LoPy 1, if you used one of those earlier).