ABP Connection parameters MKR WAN 1310

Hello!
I have programmed a code on my MKR WAN 1310 to send the sensor data to my MQTT server via my Dragino gateway. But to make this work, I need the ABP connection parameters like the devAddr., nwSKey, appSkey ... for the configuration of the gateway. Where can I find these specific to my device? Or can I define them myself in the code and pick them independently? I have not found anything on the internet and would appreciate any help. This is my current code:

#include <Arduino_MKRENV.h>
#include <MKRWAN.h>
#include <LoRa.h>

LoRaModem modem;


// Definition der wichtigen Geräte-IDs für die Verbindung
String appEui = "0000000000000000";
String appKey = "C13B9DAD423E2BBD106BE4A91184BD0D";
String devAddr = "20123473";
String nwkSkey = "A9054E2745F187DD19EC18427C1327D0";
String appSkey= "A0EEA235743C1235DD3425000028574F";

void setup() {
  Serial.begin(115200);
  
  if (!ENV.begin()) {
    
    while (1);
  }

  if (!modem.begin(EU868)) {
    
    while (1);
  }

/*appKey.trim();
appEui.trim();
  // Verbindung zum TTN-Netzwerk mit OTAA (Over-The-Air Activation) herstellen
  int connected = modem.joinOTAA(appEui, appKey);*/

  //Verbindung über ABP

    devAddr.trim();
    nwkSkey.trim();
    appSkey.trim();

   int connected = modem.joinABP(devAddr, nwkSkey, appSkey);
  
  if (!connected) {
    while (1);
  }
  
  delay(5000);
  int err;

  // Portnummer für die Pakete festlegen
  modem.setPort(3);

  // Nachrichtenübertragung starten
  modem.beginPacket();

  // Nachricht zum Paket hinzufügen
  modem.print("Geklappt!");

  // Senden des Pakets und Speichern des Rückgabewerts in "err"
  err = modem.endPacket(true);

  // Überprüfen, ob das Senden erfolgreich war
  if (err > 0) {
    // Nachricht erfolgreich gesendet
    // Serial.println("Message sent correctly!");
  } else {
    // Fehler beim Senden der Nachricht
    // Serial.println("Error sending message :(");
  }
   
  
}

void loop() {
 
  unsigned long interval = 1 * 60 * 1000;
  static unsigned long previousMillis = 0;
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    float temperature = ENV.readTemperature();
    float humidity = ENV.readHumidity();
    float pressure = ENV.readPressure();
    float illuminance = ENV.readIlluminance();
    

    int err;
    modem.dataRate(5);
    modem.setPort(3);  // Portnummer für das Paket festlegen
    modem.beginPacket();
    // Sensordaten zum Paket hinzufügen
    modem.print("Temperatur = " + String(temperature) + " C, ");
    modem.print("Feuchtigkeit = " + String(humidity) + " %, ");
    modem.print("Druck = " + String(pressure)+ "kPa");


    err = modem.endPacket(true);
    
    if (err > 0) {
      Serial.println("Message sent correctly!");
    } else {
      Serial.println("Error sending message :(");
    }
  }
}

Moved to MKR WAN 1310 specific category.... Please don't post again in Uncategorized.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.