I'm planning to set up a local LoRa network with a receiver (running Python on Raspberry Pi Zero) and several transmitters (running C code on Arduino).
To start on this I was testing some sketches from Adafruit and several other online tutorials and could get a transmitter and receiver to communicate using the RFM95 module.
But the issue is when the Python code reads the LoRa packet it drops the first 4 characters from the packet transmitted by the source.
What could be done to fix this? I suspect this could be a byte/string conversion issue, but I couldn't get it to work yet.
Transmitter code (C on Arduino):
....
void loop() {
Serial.print("Sending - Packet:");
Serial.println(msgCount);
LoRa.beginPacket();
LoRa.print("Packet:");
LoRa.print(msgCount);
LoRa.endPacket();
msgCount++;
delay(5000);
}
.......
Receiver code (Python on PiZero):
.......
while True:
packet = None
packet = rfm9x.receive()
if packet is None:
print('Waiting for PKT')
else:
prev_packet = packet
packet_text = str(prev_packet, "utf-8")
print(packet_text)
time.sleep(1)
time.sleep(0.1)
........
Expected output at the receiver:
Packet:1
Packet:2
Packet:3
.......
Packet:10
Packet:11
........
Actual output at the receiver:
et:1
et:2
et:3
.......
et:10
et:11
.......
I tried the below functions/methods without any success:
packet_text = prev_packet.decode("ascii", 'ignore')
packet_text = prev_packet.decode("utf-8", 'ignore')
Any help is appreciated! Thanks!
It seems you missed the documentation of RFM9x.receive():
One could send a header or use
with_header = True.