HelTecAutomation / Heltec_ESP32

Arduino library for Heltec ESP32 (or ESP32+LoRa) based boards
Other
633 stars 226 forks source link

Heltec WiFi LoRa V3 Peer to Peer Communication with Dragino LA66 USB Adapter #164

Open Tahir-Innok opened 1 month ago

Tahir-Innok commented 1 month ago

Hi All I am trying to communicate between Heltec LoRa V3 module with Dragino LA66 USB Adapter. I did tried my best tried different configurations but all in vain. Any insights on the issue will be highly appreciated. Draginos LA66 is flashed with peer to peer FW. Here is the python code for setting up the device:

import serial
import time

FREQUENCY = 868.500 # Frequency in Hz
POWER = 5 # Sets the output power [dBm]
FREQUENCY_DEVIATION = 0 # Always 0 for LoRa
BANDWIDTH = 0 # Sets the bandwidth (LoRa only)
              # LoRa: [0: 125 kHz, 1: 250 kHz,
              #        2: 500 kHz]
DATA_RATE = 10 # Spreading Factor
CODING_RATE = 1  # Sets the coding rate (LoRa only)
                  # LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
PREAMBLE_LENGTH = 8
FIX_LENGTH = 0 # Fixed length packets [0: variable, 1: fixed]
CRC_ON = 0 # Enables disables the CRC [0: OFF, 1: ON]
FREQUENCY_HOP_ON = 0 # Enables disables the intra-packet frequency hopping
                     # Only for LoRa: [0: OFF, 1: ON]
FREQUENCY_HOP_PERIOD = 0
IQ_INVERTED = 0 # Inverts IQ signals (LoRa only)
                # LoRa: [0: not inverted, 1: inverted]
NETWORK_TYPE = 0 # Sets the network type [0: private, 1: public]
TIMEOUT = 3000  # Transmission timeout [ms]

def setup_lora_usb(port, baudrate=9600):
    ser = serial.Serial(port, baudrate, timeout=0.001)
    time.sleep(2)  # Wait for the device to initialize
    return ser

def setup_la66(ser):
    # Configure the Dragino LA66
    send_at_command(ser, f'AT+FDR')
    send_at_command(ser, f'AT+FRE={FREQUENCY:.3f},{FREQUENCY:.3f}')
    send_at_command(ser, f'AT+BW={BANDWIDTH},{BANDWIDTH}')
    send_at_command(ser, f'AT+SYNCWORD={NETWORK_TYPE},{NETWORK_TYPE}')
    send_at_command(ser, f'AT+POWER={POWER},{POWER}')
    send_at_command(ser, f'AT+SF={DATA_RATE},{DATA_RATE}')
    send_at_command(ser, f'AT+CR={CODING_RATE},{CODING_RATE}')
    send_at_command(ser, f'AT+PREAMBLE={PREAMBLE_LENGTH},{PREAMBLE_LENGTH}')
    send_at_command(ser, f'AT+CRC={CRC_ON},{CRC_ON}')
    send_at_command(ser, f'AT+IQ={IQ_INVERTED},{IQ_INVERTED}')
    send_at_command(ser, f'AT+GROUPMOD=0,0')
    send_at_command(ser, f'AT+HEADER={FIX_LENGTH},{FIX_LENGTH}')
    send_at_command(ser, 'AT+RXMOD=65535,0')
    send_at_command(ser, f'ATZ')

def send_at_command(ser, command, delay=1):
    ser.flushInput()  # Clear any data in the input buffer
    ser.write((command + '\r\n').encode('utf-8'))
    time.sleep(delay)
    response = ser.readlines()
    for line in response:
        print(line.decode('utf-8').strip())

def send_lora_message(ser, message):
    while True:
        try:
            send_at_command(ser, f'AT+SEND={len(message)},{message}')
        except KeyboardInterrupt:
            break

def receive_lora_message(ser):
    while True:
        try:
            send_at_command(ser, 'AT+RECV=1', delay=1)
        except KeyboardInterrupt:
            break

def main():
    ser = setup_lora_usb('/dev/ttyUSB0')
    setup_la66(ser)
    # send_lora_message(ser, 'Hello, World!')
    receive_lora_message(ser)
    ser.close()

if __name__ == '__main__':
    main()

On the other hand the FW for Heltec LoRa V3 is:

#include "LoRaWan_APP.h"
#include "Arduino.h"

#define FREQUENCY 868500000 // Frequency in Hz
#define POWER 5 // Sets the output power [dBm]
#define FREQUENCY_DEVIATION 0 // Always 0 for LoRa
#define BANDWIDTH 0 // Sets the bandwidth (LoRa only)
                    // LoRa: [0: 125 kHz, 1: 250 kHz,
                    //        2: 500 kHz, 3: Reserved]
#define DATA_RATE 10 // Spreading Factor
#define CODING_RATE 1  // Sets the coding rate (LoRa only)
                       // LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
#define PREAMBLE_LENGTH 8
#define FIX_LENGTH 0 // Fixed length packets [0: variable, 1: fixed]
#define CRC_ON 0 // Enables disables the CRC [0: OFF, 1: ON]
#define FREQUENCY_HOP_ON 0 // Enables disables the intra-packet frequency hopping
                          // Only for LoRa: [0: OFF, 1: ON]
#define FREQUENCY_HOP_PERIOD 0
#define IQ_INVERTED 0 // Inverts IQ signals (LoRa only)
                      // LoRa: [0: not inverted, 1: inverted]
#define TIMEOUT 3000  // Transmission timeout [ms]

char txpacket[30];
double txNumber;

static RadioEvents_t RadioEvents;

void OnTxDone(void) {
    Serial.println("TX done...");
    // Other handling code
}

void setup() 
{
    Serial.begin(115200);
    RadioEvents.TxDone = OnTxDone;
    Radio.Init(&RadioEvents);
    Radio.SetChannel(FREQUENCY);
    Radio.SetTxConfig(MODEM_LORA, POWER, FREQUENCY_DEVIATION, BANDWIDTH,
                      DATA_RATE, CODING_RATE, PREAMBLE_LENGTH, FIX_LENGTH,
                      CRC_ON, FREQUENCY_HOP_ON, FREQUENCY_HOP_PERIOD, 
                      IQ_INVERTED, TIMEOUT);
}

void loop() {
    txNumber += 0.01;
    sprintf(txpacket, "Hello world number %0.2f", txNumber);
    Serial.printf("\r\nSending packet \"%s\"\r\n", txpacket);
    Radio.Send((uint8_t *)txpacket, strlen(txpacket));
    delay(1000); // 1-second delay
}

I tried to have identical configurations and also tweaked the settings but both of the devices does not communicate. For testing purpose they both are connected to the same laptop. Any insights will be highly appreciated. Thank you so much in advance.

denismarti commented 3 weeks ago

Bonjour Je doit faire communiquer également un HELTEC WiFi Lora 32 v3 et un DRAGINO LA66 en peer-to-peer. Sans succès. Avez-vous résolu votre problème? Bien à vous

image