Hello,
currently I am working on an project that requires a LoRa PTP-connection to be forwarded into The Things Network.
As a test I created a program which connects to TTN and sends a message every 2 minutes. The LoRaWAN connection on it´s own always worked pretty good.
My problem is that TTN does not receive any messages as soon as I begin the PTP connection, even if I end it directly again.
With help of the serial monitor i found out that the programm stops working in line 84.
The Arduino I am using is a MKR WAN 1310.
The libraries I am using are MKRWAN.h ; SPI.h ; LoRa.h
Now my question. Is it possible to switch between LoRa and LoRaWAN?
code:
/*
Lora Send And Receive
This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module.
This example code is in the public domain.
*/
#include <MKRWAN.h>
#include <SPI.h>
#include <LoRa.h>
LoRaModem modem;
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
String appEui = SECRET_APP_EUI;
String appKey = SECRET_APP_KEY;
int Counter = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial);
if (!modem.begin(EU868)) {
Serial.println("Failed to start module");
while (1) {}
};
Serial.print("Your module version is: ");
Serial.println(modem.version());
Serial.print("Your device EUI is: ");
Serial.println(modem.deviceEUI());
int connected = modem.joinOTAA(appEui, appKey);
if (!connected) {
Serial.println("Something went wrong; are you indoor? Move near a window and retry");
Serial.println(connected);
while (1) {}
}
else
{
Serial.println("Connected");
}
// Set poll interval to 60 secs.
modem.minPollInterval(60);
// NOTE: independently by this setting the modem will
// not allow to send more than one message every 2 minutes,
// this is enforced by firmware and can not be changed.
delay(1000);
if (!LoRa.begin(868E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
delay(1000);
}
void loop() {
LoRa.end();
delay(10000);
Counter++;
String msg = "Sendevorgang: ";
Serial.println();
Serial.print("Sending: " + msg + " - ");
for (unsigned int i = 0; i < msg.length(); i++) {
Serial.print(msg[i] >> 4, HEX);
Serial.print(msg[i] & 0xF, HEX);
Serial.print(" ");
}
Serial.println();
int err;
modem.beginPacket();
Serial.println("Paket begonnen");
modem.print(msg + Counter);
Serial.print("Nachricht verschicken");
err = modem.endPacket(true);
Serial.println("Paket beenden");
if (err > 0) {
Serial.println("Message sent correctly!");
} else {
Serial.println("Error sending message :(");
Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength");
Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)");
}
delay(12000);
}
