/* Teste de paramentros de configuracao, estabelece conexao OTAA e transmite pacote periodicamente para TTN v3 */
/* Includes */
#include <LoRaWAN.h>
#include <SoftwareSerial.h>
#include <stdint.h>
/* SoftwareSerial handles */
SoftwareSerial* hSerialCommands = NULL;
/* Variables */
char payLoad[] = “AT+SENDB=83:0248656C6C6F20576F77”;
char appEUI[] = “AT+APPEUI=00:00:00:00:00:00:00:00”; // Mudar
char appKey[] = “AT+APPKEY=C4:03:40:B3:AC:F9:D1:D2:B2:48:21:DD:8B:B4:65:84”; // mudar
char chMask[] = “FF00:0000:0000:0000:0001:0000”; // Banda 2 AUS
char joinNet[] = “AT+JOIN”;
char rstLWM[] = “ATZ\r\n”;
char setMode[] = “AT+NJM=1\r\n”; // 0 = ABP e 1 = OTAA
char resposta [40];
uint8_t tamanho;
char *pontResp;
uint8_t *pontTam;
void setup()
{
pontResp = &resposta[0];
pontTam = &tamanho;
Serial.begin(9600);
Serial.println("\n\nIniciando…");
hSerialCommands = SerialCommandsInit(7, 6, 9600);
Serial.print("Reset interface LoRaWAN: "); Serial.println(rstLWM);
SendRaw(rstLWM);
delay(1000);
SendRaw(setMode);
delay(1000);
SendRaw(appKey);
delay(1000);
SendRaw(appEUI);
delay(1000);
SendRaw(chMask);
delay(1000);
Serial.print("Enviando Join: "); Serial.println(joinNet);
SendRaw(joinNet);
delay(1000);
if(JoinNetwork(10) == RAD_OK)
{
Serial.println(“EndDevice has joined sucessfully.”);
}
else
{
Serial.println(“Error joining the network.”);
}
SendRaw(“AT+NJS=?”);
delay(1000);
if (ReceivePacketCommand(pontResp, pontTam, 2000) == RAD_OK)
Serial.println(“Radio OK”);
else
Serial.println(“Radio nOK”);
Serial.print("Resposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
}
/* Loop ---------------------- */
void loop()
{
SendRaw(“AT+DEUI=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+DADDR=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.println(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+APPKEY=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+APPSKEY=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+NWKSKEY=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+APPEUI=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+VER=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+CFM=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+DR=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+RX1DL=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(“AT+RX2DL=?”);
delay(1000);
for (int i=0; i < 40; i++) resposta[i] = 0x00;
ReceivePacketCommand(pontResp, pontTam, 2000);
Serial.print("\nResposta: "); Serial.print(resposta);
Serial.print("Tamanho: "); Serial.println(tamanho);
SendRaw(payLoad);
Serial.print("\nWait\n");
delay(30000);
}