Lora transmit Relay / packet forwarder

All the possible settings should be mentioned in the Readme.md file that accompanies the library.

However I will again point out that the relay program was designed for point to point LoRa, I cannot see how it could be used to make a proper TTN compliant relay …

1 Like

Now i have a code made for getting data from arduino LoRa Node over the Relay to my heltec LoRa V2 Board but i need some help for the payload to mqtt

its about this : client.publish(“esp32/lora”, LoRaData);

how can i seperate the id / temp / humi ?

Here is my code:

#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
#include <U8x8lib.h>


U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16); // Oled


#define ss 18             // NSS   Pin LoRa
#define rst 14            // Reset Pin LoRa
#define dio0 26           // dio0  Pin LoRa


const char* ssid = "xxxxxxxxxxxxxxx";       // Wlan SSID
const char* password = "xxxxxxxxxx";       // Wlan Passwort


const char* mqtt_server = "xxxxxxxxxx";    // MQTT Server IP Adresse 

WiFiClient espClient;
PubSubClient client(espClient);


char msg[50];


void setup() {
  
  Serial.begin(115200);

  setup_wifi();
  client.setServer(mqtt_server, 1883);   // MQQT Port
  client.setCallback(callback);

}



void setup_wifi() {                       // Setup Wifi
  
  delay(10);
  
  while (!Serial);
  Serial.println("LoRa Empfänger");

  
  LoRa.setPins(ss, rst, dio0);           // LoRa Setup
  

  while (!LoRa.begin(866E6)) {           // Netzauswahl - Europa
    Serial.println(".");
    delay(500);
  }


  LoRa.setSpreadingFactor(7);                     // Spreading Faktor 7 - 12
  LoRa.setSignalBandwidth(125E3);                 // Bandwidth zb. 125Kbaud - (125E3)
  LoRa.setCodingRate4(5);                         // CodingRate 5 - 
  LoRa.enableCrc();                               // Crc Check
  LoRa.setSyncWord(0x34);                         // sync word ( 0-0xFF ) ****  (0x34); für LoRaWan **** 
  LoRa.setFrequency(868100000);                   // Frequenz / Kanal 
  Serial.println("LoRa OK!");

  
    u8x8.begin();
    u8x8.setFont(u8x8_font_chroma48medium8_r);
    u8x8.drawString(4, 0, "LoRa OK ");

  
  Serial.println();
  Serial.print("verbinden zu ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi verbunden");
  Serial.println("IP Adresse: ");
  Serial.println(WiFi.localIP());
  
     u8x8.setCursor(2,1);
     u8x8.print("IP Adresse"); 
     u8x8.setCursor(0,2);
     u8x8.print(WiFi.localIP()); 
     delay(500);
    
}

void callback(char* topic, byte* message, unsigned int length) {
  Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Nachricht: ");
  String messageTemp;
  
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();

}

void reconnect() {
  
  while (!client.connected()) {
    Serial.print("versuche MQTT zu verbinden...");
    
    if (client.connect("ESP8266Client")) {
      Serial.println("verbunden");
      
       u8x8.setCursor(0,3);
       u8x8.print("MQTT verbunden"); 
      
      client.subscribe("esp32/output");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" erneuter Versuch in 6 Sekunden");

       u8x8.setCursor(0,3);
       u8x8.print("            ");
       u8x8.setCursor(0,3);
       u8x8.print("MQTT Fehler");
      
      delay(6000);
    }
  }
}


void loop() {
  
  if (!client.connected()) {
      

      reconnect();     
  }
  
       client.loop();


   int packetSize = LoRa.parsePacket();
   
  if (packetSize) {
   
    Serial.println("empfangenes Packet '");


    while (LoRa.available()) {
      
      String LoRaData = LoRa.readString();
      Serial.print(LoRaData); 
      
       u8x8.setCursor(0,4);
       u8x8.print("Lora Packet:");
       u8x8.setCursor(0,5);
       u8x8.print(LoRaData);

   
      client.publish("esp32/lora", LoRaData);
     
      
    }

   
    Serial.print("' mit der RSSI ");
    Serial.println(LoRa.packetRssi());
       
       u8x8.setCursor(0,7);
       u8x8.print("RSSI: "); 
       u8x8.setCursor(6,7);
       u8x8.print(LoRa.packetRssi()); 
  }
}

It’s good to hear you’ve got some sort of relay working.

This forum services topics on LoRaWAN on TTN and not general LoRa questions.

Maybe the Heltec forum could assist?

1 Like

ok thank you :wink: