Using Lopy1 for just LoRa
How applicable is using two LoPy1 SOICs to communicate via LoRa, but not as a packet forwarder? To clarify more, I basically would like to know how well it would work to use a LoPy to act somewhat like a gateway, for receiving data from other LoPys via LoRa. However, once I get that data I want to send it out via UART. No forwarding.
I have done this with the ping-pong example, but how well would this work on a larger scale? Like 20 LoPys sending to the same "listening LoPy".
@robert-hh So a remote raw lora receiver with a lot of nodes sending it is just inevitable that collisions happen? My current "solution" is to send and wait for it to send back an acknowledge, if not just wait a random period of time.
robert-hh last edited by robert-hh
@burgeh lora.stats() returns reasonable values after a packet has sent or received. Avoiding collisions is in general not possible. Looking for another station sending at the same time is more a polite behavior than a robust method. You can only see stations close to your place. Remote stations which also can cause a collision are invisible.
@robert-hh I've tried -120 and -100, both failed everytime. One issue I noticed is that the first time I call lora.stats() the rssi value is 0. I tried sending first and then checking it, and it remains at 0.
Also, this is_channelfree() function the only way to avoid colliding? Because if a unit is just far away, it might not be allowed to send for example.
robert-hh last edited by robert-hh
@burgeh If you init a Lora instance and call is_channelfree() with various value from the REPL, what do you get? Since the test window is pretty short, it is always possible that noise is seen as RF carrier. In my quick test with a LoPy4 I had the following results when calling lora.ischannel_free() with various values:
-120dB Always False
-110dB Always False
-105dB ~50% False, 50% True
-100dB About 100% True
With a LoPy 1 the 50% point was at -117dB, and -115dB was always True. So it looks as if you have to find the proper value by testing.
Burgeh last edited by Burgeh
I don't quite understand the lora.ischannel_free() function. The first code below is my main "sending node". I then send it to a reciever which is using the second code. It works fine without the lora.ischannel_free(-120) condition, but when I use it it never actually sends. I only have one sending so I would not think it is busy. The rssi value is like -40.
from network import LoRa import socket import time import pycom import binascii import machine from machine import UART #NODE B # Please pick the region that matches where you are using the device: # Asia = LoRa.AS923 # Australia = LoRa.AU915 # Europe = LoRa.EU868 # United States = LoRa.US915 lora = LoRa(mode=LoRa.LORA, frequency = 915000000, region=LoRa.US915, tx_power = 20) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setblocking(False) pycom.heartbeat(False) pycom.rgbled(0x007f00) # green receiveFlag = 0 while True: time.sleep(8) pycom.rgbled(0x0000ff) # blue id = binascii.hexlify(machine.unique_id()) data = lora.stats() print("Stats %s" % data) if (lora.ischannel_free(-120)): s.send("ID: %s" % id) print("Sending ID") pycom.rgbled(0xFF00ff) # something... while (receiveFlag == 0): pycom.rgbled(0xFF0000) # RED data1 = s.recv(128) print("Look for Ack") if (b'%s' % id) in data1: receiveFlag = 1; s.send("ID: %s" % id) time.sleep(1) time.sleep(1) pycom.rgbled(0x00ff00) # green receiveFlag = 0
This is my receiver.
from network import LoRa import socket import time import pycom #NODE A # Please pick the region that matches where you are using the device: # Asia = LoRa.AS923 # Australia = LoRa.AU915 # Europe = LoRa.EU868 # United States = LoRa.US915 lora = LoRa(mode=LoRa.LORA, frequency = 915000000, region=LoRa.US915) s = socket.socket(socket.AF_LORA, socket.SOCK_RAW) s.setblocking(False) pycom.heartbeat(False) pycom.rgbled(0x007f00) # green #TX_power is the value that is set on this chip not received. while True: data1 = s.recv(128) if b'ID' in data1: print("ID Received") data = lora.stats() print("Stats %s" % data) print("Content %s" % data1) print("Sending Ack") reply = "Pong %s" % data1 s.send(reply) pycom.rgbled(0x0000ff) # blue time.sleep(.5) pycom.rgbled(0x00ff00) # green s.recv(128)
Here is it working...
@braulio I think you found that already in this post: https://forum.pycom.io/topic/3120/value-of-tx_time_on_air-of-the-lora-stats-function/5
braulio last edited by
How I can get transmition time with LoRaRAW??
@burgeh The receiver can hardly control when two parties are sending at the same time. In that case, the transmission can fail. The sending nodes can check with lora.ischannel_free() before sending, if someone else is sending, and wait until that is finished.
Even when you try to implement something like a round robin protocol, some other devices may send.
It may need two way connection eventually, but would a single LoPy setup as a "gateway" be able to handle multiple other units sending, and deal with collisions?
By deal with collisions I mean, it is receiving data from LoPy A and LoPy B sends, will it wait until A is done and not jumble the messages?
@burgeh You can do that with raw LoRa. if you look at the nanogateway examples, the gateway are configures as Raw Lora Devices. If it is just one direction, nodes to "gateway", that should be simple. If you want to implement a kind of downlink, you have to add more elements of a protocol, such that the nodes in your net can tell the types and purpose of messages they receive.
Obviously you have the problem of collisions and lost messages, which is not addressed by the basic transport mechanism.