Hello World
Recently I’ve bought a Seeeduino for my bachelor thesis. To get started with it, I decided trying to make a few simple programs first. So as a first I tried a simple “Hello World”, which actually took quite some work to get my laptop to accept the Seeeduino as a device. (I had some extra unnecessary services running.) But which I eventually got to work.
Hello LoRaWAN
After this step, I wanted to try to actually connect it to TTN. So I followed this guide: https://blog.squix.org/2017/07/seeeduino-lora-gps-getting-started-with-lorawan-and-ttn.html. I’ve added some extra lines to have a bit more debug of what is going on at a given time. (I’ve added my code at the bottom of this thread.)
However, now that I am trying to connect my Seeeduino, it just attempts to join once and then skips to the loop, without even showing the debug of a reattempt. It also does not display that it either succeeded or failed to join a server, just that it attempts it once and then moves on to the loop. Afterwards it tries to send some packets, of which about one in seven actually gets received according to the device monitor. Unfortunately, this so called successfully received packet is never shown on the server.
My question
How do I get my device to join TTN so that I can actually see data traffic on the server interface and so that I can use the device for different purposes in the future?
Device monitor
This is what the device monitor shows during execution of this code.
Hello world!
+VER: 2.1.15
+ID: DevAddr, 26:01:14:D0
+ID: DevEui, 00:21:FD:31:A2:88:6D:7E
+ID: AppEui, 70:B3:D5:7E:D0:00:C1:9F
+ID: DevEui, 00:21:FD:31:A2:88:6D:7E
+ID: AppEui, 70:B3:D5:7E:+KEY: APPKEY AB08FD9C50A0FF81A642D7F915D4CE45
+MODE: LWOTAA
+DR: EU868
+DR: DR0
+DR: EU868 DR0 SF12 BW125K
+CH: 0,868100000,DR0:DR5
+CH: 1,868300000,DR0:DR5
+CH: 2,868500000,DR0:DR5
+RXWIN1: 0,868100000
+RXWIN2: 869500000,DR3
+LW: DC, ON, 0
+LW: JDC, ON
+POWER: 14
+JOIN: Start
+JOIN: NORMAL
Connected!
Still alive
+MSG: No band in 140211ms
Packet sent: 0
Still alive
+MSG: No band in 118183ms
Packet sent: 0
Still alive
After a while, this turns into:
+MSG: Please join network first
Packet sent: 0
Still alive
My code
#include <LoRaWan.h>
unsigned char data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA,};
char buffer[256];
void setup(void)
{
pinMode(LED_BUILTIN, OUTPUT);
SerialUSB.begin(115200);
while(!SerialUSB){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
}
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
SerialUSB.println("Hello world!");
lora.init();
memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
SerialUSB.print(buffer);
memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
SerialUSB.print(buffer);
// void setId(char *DevAddr, char *DevEUI, char *AppEUI);
lora.setId(NULL, "0021FD31A2886D7E", "70B3D57ED000C19F");
// setKey(char *NwkSKey, char *AppSKey, char *AppKey);
lora.setKey(NULL, NULL, "AB08FD9C50A0FF81A642D7F915D4CE45");
lora.setDeciveMode(LWOTAA);
lora.setDataRate(DR0, EU868);
lora.setChannel(0, 868.1);
lora.setChannel(1, 868.3);
lora.setChannel(2, 868.5);
lora.setReceiceWindowFirst(0, 868.1);
lora.setReceiceWindowSecond(869.5, DR3);
lora.setDutyCycle(true);
lora.setJoinDutyCycle(true);
lora.setPower(20);
while(!lora.setOTAAJoin(JOIN)){
for(int i=0; i<=3; i++){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100);
}
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
SerialUSB.println("Connecting...") ;
}
SerialUSB.println("Connected!");
}
void loop(void)
{
SerialUSB.println("Still alive");
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
bool result = false;
result = lora.transferPacket("Hello World!", 10);
//result = lora.transferPacket(data, 10, 10);
SerialUSB.print("Packet sent: ");
SerialUSB.println(result);
delay(10000);
/*
if(result)
{
short length;
short rssi;
memset(buffer, 0, 256);
length = lora.receivePacket(buffer, 256, &rssi);
if(length)
{
SerialUSB.print("Length is: ");
SerialUSB.println(length);
SerialUSB.print("RSSI is: ");
SerialUSB.println(rssi);
SerialUSB.print("Data is: ");
for(unsigned char i = 0; i < length; i ++)
{
SerialUSB.print("0x");
SerialUSB.print(buffer[i], HEX);
SerialUSB.print(" ");
}
SerialUSB.println();
}
}
*/
}