xg590 / SX1276

MicroPython Library for SX1276 (A Long Range Radio Chip from Semtech)
Apache License 2.0
34 stars 8 forks source link

BRD packets not printed on the receiver #10

Closed SharathChandan closed 1 year ago

xg590 commented 1 year ago

Code sharing?

SharathChandan commented 1 year ago

Code sharing?

I will share it in the morning I don't have my laptop now. thought of asking you when I was away. The packets aren't printed on the receiver even though both dst id and frequency are same. I'll share the script once I get my laptop.

xg590 commented 1 year ago

Code sharing?

I will share it in the morning I don't have my laptop now. thought of asking you when I was away. The packets aren't printed on the receiver even though both dst id and frequency are same. I'll share the script once I get my laptop.

Let me guess. Have you defined the "lora.brd_packet_handler" in your main code?

lora.brd_packet_handler = lambda self, data, SNR, RSSI: print("[BRD]", data)
SharathChandan commented 1 year ago

Sender: from machine import Pin import time, urandom as random from lora import SX1276

LoRa_MISO_Pin = 12 LoRa_MOSI_Pin = 13 LoRa_SCK_Pin = 14 LoRa_CS_Pin = 15 LoRa_RST_Pin = 27 LoRa_DIO0_Pin = 2 LoRa_DIO1_Pin = 34 SPI_CH = 1

random.seed(11) channels2Hopping = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz

LoRa_id = 1 lora = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping)

payload = str(random.randint(100,65536))+") Hello~" print(payload) lora.send(dst_id=0, msg=payload, pkt_type=lora.PKT_TYPE['BRD']) # Sender's lora_id is 1 and receiver's is 0

Receiver: from machine import Pin import time, urandom as random from lora import SX1276

LoRa_MISO_Pin = 12 LoRa_MOSI_Pin = 13 LoRa_SCK_Pin = 14 LoRa_CS_Pin = 15 LoRa_RST_Pin = 27 LoRa_DIO0_Pin = 2 LoRa_DIO1_Pin = 34 SPI_CH = 1

random.seed(11) channels2Hopping = [866_000_000+200_000 * random.randint(0,10) for i in range(128)]

LoRa_id = 0 lora = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping) lora.brd_packet_handler = lambda self, packet, SNR, RSSI: print("[New 'BRD' packet]", packet, SNR, RSSI) lora.mode = 'RXCONTINUOUS'

xg590 commented 1 year ago

I tried your code on my setup and it works fine. I suggest you double check everything else.

The real scripts used on my controllers.

Heltec WiFi LoRa 32 V2

LoRa_MISO_Pin = 19 LoRa_MOSI_Pin = 27 LoRa_SCK_Pin = 5 LoRa_CS_Pin = 18 LoRa_RST_Pin = 14 LoRa_DIO0_Pin = 26 LoRa_DIO1_Pin = 35 LoRa_DIO2_Pin = 34 SPI_CH = 1

random.seed(11) channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz

LoRa_id = 1 lora = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping)

payload = str(random.randint(100,65536))+") Hello~" print(payload) lora.send(dst_id=0, msg=payload, pkt_type=lora.PKT_TYPE['BRD']) # Sender's lora_id is 1 and receiver's is 0

* Receiver

from machine import Pin import time, urandom as random from lora import SX1276

Heltec WiFi LoRa 32 V2

LoRa_MISO_Pin = 19 LoRa_MOSI_Pin = 27 LoRa_SCK_Pin = 5 LoRa_CS_Pin = 18 LoRa_RST_Pin = 14 LoRa_DIO0_Pin = 26 LoRa_DIO1_Pin = 35 LoRa_DIO2_Pin = 34 SPI_CH = 1

random.seed(11) channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(128)] # Both sender and receiver need to know the sequence of frequences they are hopping on before the first hopping operation.

LoRa_id = 0 lora = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping) lora.brd_packet_handler = lambda self, packet, SNR, RSSI: print("[New 'BRD' packet]", packet, SNR, RSSI) lora.mode = 'RXCONTINUOUS'

SharathChandan commented 1 year ago

Sure. It works for a while and then it fails. I think those are due to unreliable connection on my hardware. Once i sort it i think it will be good going.

SharathChandan commented 1 year ago

should i use different spreading factors for the receive and sender LoRa modules.

xg590 commented 1 year ago

should i use different spreading factors for the receive and sender LoRa modules.

You can google basics of LoRa modulation. Short answer , No.

SharathChandan commented 1 year ago

I meant if i use multiple transmitter nodes should i use different SF

xg590 commented 1 year ago

I meant if i use multiple transmitter nodes should i use different SF

I suggest you use different frequencies. or freq sequences. SF/CR will not prevent interference.

SharathChandan commented 1 year ago

Thanks. Can you share some reliable sources to learn more about LoRa and related concepts?

xg590 commented 1 year ago

Thanks. Can you share some reliable sources to learn more about LoRa and related concepts?

You can begin from here (https://www.thethingsnetwork.org/docs/lorawan/) and here (https://lora-developers.semtech.com/learn/get-started/what-is-lora)

SharathChandan commented 1 year ago

Hello! how can i convert a byte string to a string in micropython. I am using UART on my esp32 and sending data to the slave through UART, the value gets printed on the REPL but not while executing the program. is there a decode option in micropython? i have not found any solution online. kindly help me if you can.

xg590 commented 1 year ago

Hello! how can i convert a byte string to a string in micropython. I am using UART on my esp32 and sending data to the slave through UART, the value gets printed on the REPL but not while executing the program. is there a decode option in micropython? i have not found any solution online. kindly help me if you can.

there is little difference between micropython and python. you can use build in function to convert byte string to string

assert b'abc'.decode() == 'abc', "[ You will not see an AssertionError because they are equal ]" 

A caveat: although

assert b'abc'[0:2] == b'ab', "[ You will not see an AssertionError because they are equal ]"
assert  'abc'[0:2] ==  'ab', "[ You will not see an AssertionError because they are equal ]"
assert b'abc'[0:1] == b'a' , "[ You will not see an AssertionError because they are equal ]"
assert  'abc'[0:1] ==  'a' , "[ You will not see an AssertionError because they are equal ]"

...

assert  'abc'[0] ==  'a'     , "[ You will not see an AssertionError because they are equal ]"
assert b'abc'[0] == b'a'     , "[ You will see an AssertionError because they are not equal ]"
assert b'abc'[0] == ord(b'a'), "[ You will not see an AssertionError because they are equal ]"
SharathChandan commented 1 year ago

Great! can you share a example where i can store the received data on my slave device in real time.

Master: from machine import UART uart = UART(2, 115200)

uart.write('I am testing UART')

file = open ("sample.txt", "r") data = file.read() uart.write(data)

Slave: from machine import UART uart = UART(2, 115200) msg = uart.read() print(msg) # it prints None while in REPL it prints b' I am testing UART

i want to process the data on my slave, is there a way i could store the data to a variable.

xg590 commented 1 year ago

Great! can you share a example where i can store the received data on my slave device in real time.

Master: from machine import UART uart = UART(2, 115200)

uart.write('I am testing UART')

file = open ("sample.txt", "r") data = file.read() uart.write(data)

Slave: from machine import UART uart = UART(2, 115200) msg = uart.read() print(msg) # it prints None while in REPL it prints b' I am testing UART

i want to process the data on my slave, is there a way i could store the data to a variable.

Sorry, I am not familiar with MicroPython's UART module.

SharathChandan commented 1 year ago

Great! can you share a example where i can store the received data on my slave device in real time. Master: from machine import UART uart = UART(2, 115200)

uart.write('I am testing UART')

file = open ("sample.txt", "r") data = file.read() uart.write(data) Slave: from machine import UART uart = UART(2, 115200) msg = uart.read() print(msg) # it prints None while in REPL it prints b' I am testing UART i want to process the data on my slave, is there a way i could store the data to a variable.

Sorry, I am not familiar with MicroPython's UART module.

Fine, i'll let you know if i find a way through it.

hkevman commented 1 year ago

Hello everyone,

I see your conversation i'm very interesting with your work , Can i have your codes, I want to start a project about Lora with Micropython and i need to see some project before if that not a problem . Thanks you