WiFi LoRa32 V2 communication with Raspberry Pi (Dragino LoRa/GPS Hat)

Hi,

I am using LoRa32 as a node to communicate with Raspberry Pi. For now I am able to run the code on both ends but I am not receiving or sending any data to the devices. I am looking for some advice thanks in advance!

Heltec LoRa32 code:

// This program sends a response whenever it receives the “INF” mens
// This file is part of rpsreal/LoRa_Ra-02_Arduino
// Based on example Arduino9x_RX RADIOHEAD library
// It is designed to work with LORA_SERVER

#include <SPI.h>
#include <RH_RF95.h>

#define RFM95_CS 18
#define RFM95_RST 14
#define RFM95_INT 26

// Change to 434.0 or other frequency, must match RX’s freq!
#define RF95_FREQ 915.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

// Blinky on receipt
#define LED 13

void setup()
{
pinMode(LED, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);

while (!Serial);
Serial.begin(9600);
delay(100);

// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);

while (!rf95.init()) {
Serial.println(“LoRa radio init failed”);
while (1);
}

// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println(“setFrequency failed”);
while (1);
}

// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:

// Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on.
// Slow+long range.
//rf95.setModemConfig(RH_RF95::Bw125Cr48Sf4096);

// Defaults after init are 434.0MHz, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// Medium Range

rf95.setTxPower(18);

Serial.println(“START”);
}

uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);

void loop()
{
if (rf95.available()){

if (rf95.recv(buf, &len)){
  digitalWrite(LED, HIGH);
  //RH_RF95::printBuffer("Got: ", buf, len);
  Serial.print("Received:  ");
  Serial.println((char*)buf);
  Serial.print("RSSI: ");
  Serial.println(rf95.lastRssi(), DEC);
  if (strcmp("INF",((char*)buf)) == 0){
    Serial.println("Received data request INF");
    delay(2000);
    Serial.println("Send mens: DATA ARDUINO");
    uint8_t data[] = "DATA ARDUINO";
    rf95.send(data, 13); //sizeof(data)
    rf95.waitPacketSent();
  }
  digitalWrite(LED, LOW);
}
else
{
  Serial.println("Receive failed");
}

}
}

Here is the Raspberry Pi Server Code:

import time
from SX127x.LoRa import *
#from SX127x.LoRaArgumentParser import LoRaArgumentParser
from SX127x.board_config import BOARD

BOARD.setup()
BOARD.reset()
#parser = LoRaArgumentParser(“Lora tester”)

class mylora(LoRa):
def init(self, verbose=False):
super(mylora, self).init(verbose)
self.set_mode(MODE.SLEEP)
self.set_dio_mapping([0] * 6)
self.var=0

def on_rx_done(self):
    BOARD.led_on()
    #print("\nRxDone")
    self.clear_irq_flags(RxDone=1)
    payload = self.read_payload(nocheck=True)
    print ("Receive: ")
    print(bytes(payload).decode("utf-8",'ignore')) # Receive DATA
    BOARD.led_off()
    time.sleep(2) # Wait for the client be ready
    print ("Send: ACK")
    self.write_payload([255, 255, 0, 0, 65, 67, 75, 0]) # Send ACK
    self.set_mode(MODE.TX)
    self.var=1

def on_tx_done(self):
    print("\nTxDone")
    print(self.get_irq_flags())

def on_cad_done(self):
    print("\non_CadDone")
    print(self.get_irq_flags())

def on_rx_timeout(self):
    print("\non_RxTimeout")
    print(self.get_irq_flags())

def on_valid_header(self):
    print("\non_ValidHeader")
    print(self.get_irq_flags())

def on_payload_crc_error(self):
    print("\non_PayloadCrcError")
    print(self.get_irq_flags())

def on_fhss_change_channel(self):
    print("\non_FhssChangeChannel")
    print(self.get_irq_flags())

def start(self):          
    while True:
        while (self.var==0):
            print ("Send: INF")
            self.write_payload([255, 255, 0, 0, 73, 78, 70, 0]) # Send INF
            self.set_mode(MODE.TX)
            time.sleep(3) # there must be a better solution but sleep() works
            self.reset_ptr_rx()
            self.set_mode(MODE.RXCONT) # Receiver mode
        
            start_time = time.time()
            while (time.time() - start_time < 10): # wait until receive data or 10s
                pass;
        
        self.var=0
        self.reset_ptr_rx()
        self.set_mode(MODE.RXCONT) # Receiver mode
        time.sleep(10)

lora = mylora(verbose=True)
#args = parser.parse_args(lora) # configs in LoRaArgumentParser.py

Slow+long range Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, CRC on. 13 dBm

lora.set_freq(915.0)
lora.set_pa_config(pa_select=1, max_power=21, output_power=15)
lora.set_bw(BW.BW125)
lora.set_coding_rate(CODING_RATE.CR4_8)
lora.set_spreading_factor(12)
lora.set_rx_crc(True)
#lora.set_lna_gain(GAIN.G1)
#lora.set_implicit_header_mode(False)
lora.set_low_data_rate_optim(True)

Medium Range Defaults after init are 434.0MHz, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 13 dBm

#lora.set_pa_config(pa_select=1)

assert(lora.get_agc_auto_on() == 1)

try:
print(“START”)
lora.start()
except KeyboardInterrupt:
sys.stdout.flush()
print(“Exit”)
sys.stderr.write(“KeyboardInterrupt\n”)
finally:
sys.stdout.flush()
print(“Exit”)
lora.set_mode(MODE.SLEEP)
BOARD.teardown()

rpi:

7E49BD78-3C71-4B35-9D61-6E219FAC9CA9

thank you in advance!

Hi @ccccxtran4,

I can’t really comment on your actual setup, but I can say that I have a range of Heltec processors sending data to a Raspberry Pi via LoRa. I use the Sandeep Mistry LoRa library on the ESP processors and some Python code from CircuitDigest on the Raspberry Pi.

All of my set-up details and code are available here.

Pete