This is the coding i used:
#include "LoRaWan_APP.h"
#include "Arduino.h"
/* OTAA para*/
uint8_t devEui[] = { 0x00, 0x58, 0xD8, 0x09, 0xEF, 0x5D, 0x86, 0x98 };
uint8_t appEui[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x03, 0x90, 0x67 };
uint8_t appKey[] = { 0xE2, 0xF0, 0xFC, 0xB9, 0x37, 0xEF, 0x66, 0x98, 0xD2, 0x3C, 0xD4, 0x2E, 0x30, 0x07, 0xEE, 0xF5 };
/* ABP para*/
uint8_t nwkSKey[] = { 0xEA, 0xBA, 0xB6, 0x18, 0xCB, 0x0A, 0xF2, 0xF5, 0x8C, 0x38, 0xD3, 0x98, 0x71, 0xF6, 0x16, 0xC9 };
uint8_t appSKey[] = { 0x1B, 0x83, 0x4A, 0x9B, 0x07, 0x71, 0xEF, 0x17, 0x52, 0xAD, 0x7F, 0xAE, 0x6B, 0xBB, 0xEB, 0x55 };
uint32_t devAddr = ( uint32_t )0x26041414;
/*LoraWan channelsmask, default channels 0-7*/
uint16_t userChannelsMask[6]={ 0x00FF,0x0000,0x0000,0x0000,0x0000,0x0000 };
/*LoraWan region, select in arduino IDE tools*/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
/*LoraWan Class, Class A and Class C are supported*/
DeviceClass_t loraWanClass = LORAWAN_CLASS;
/*the application data transmission duty cycle. value in [ms].*/
uint32_t appTxDutyCycle = 15000;
/*OTAA or ABP*/
bool overTheAirActivation = LORAWAN_NETMODE;
/*ADR enable*/
bool loraWanAdr = LORAWAN_ADR;
/* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
bool keepNet = LORAWAN_NET_RESERVE;
/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = LORAWAN_UPLINKMODE;
/* Application port */
uint8_t appPort = 2;
uint8_t confirmedNbTrials = 4;
/* Prepares the payload of the frame */
static void prepareTxFrame( uint8_t port )
{
appDataSize = 4;
appData[0] = 0x00;
appData[1] = 0x01;
appData[2] = 0x02;
appData[3] = 0x03;
}
void setup() {
boardInitMcu();
Serial.begin(115200);
#if(AT_SUPPORT)
enableAt();
#endif
deviceState = DEVICE_STATE_INIT;
LoRaWAN.ifskipjoin();
}
void loop()
{
switch( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass,loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
break;
}
case DEVICE_STATE_JOIN:
{
LoRaWAN.join();
break;
}
case DEVICE_STATE_SEND:
{
prepareTxFrame( appPort );
LoRaWAN.send();
deviceState = DEVICE_STATE_CYCLE;
break;
}
case DEVICE_STATE_CYCLE:
{
// Schedule next packet transmission
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();
break;
}
default:
{
deviceState = DEVICE_STATE_INIT;
break;
}
}
}