diff --git a/cores/asr650x/board/src/asr_board.c b/cores/asr650x/board/src/asr_board.c index 65272cdf..0884c4be 100644 --- a/cores/asr650x/board/src/asr_board.c +++ b/cores/asr650x/board/src/asr_board.c @@ -458,7 +458,7 @@ static const double TWO52[2]={ -void BoardInitMcu( void ) +void boardInitMcu( void ) { SpiInit(); Asr_Timer_Init(); diff --git a/cores/asr650x/cores/AT_Command.h b/cores/asr650x/cores/AT_Command.h index 78c025d6..1d9386ab 100644 --- a/cores/asr650x/cores/AT_Command.h +++ b/cores/asr650x/cores/AT_Command.h @@ -30,17 +30,17 @@ enum eDeviceState_Lora }; -void Enable_AT(void); +void enableAt(void); void getDevParam(void); void printDevParam(void); -void SaveNetInfo(uint8_t *joinpayload, uint16_t size); -void SaveUpCnt(void); -void SaveDownCnt(void); -void GetNetInfo(void); -void SaveDr(void); -bool CheckNetInfo(void); -void NetInfoDisable(void); -extern bool AT_user_check(char * cmd, char * content); +void saveNetInfo(uint8_t *joinpayload, uint16_t size); +void saveUpCnt(void); +void saveDownCnt(void); +void getNetInfo(void); +void saveDr(void); +bool checkNetInfo(void); +void netInfoDisable(void); +extern bool checkUserAt(char * cmd, char * content); diff --git a/cores/asr650x/kernel/protocols/lorawan/README.md b/cores/asr650x/kernel/protocols/lorawan/README.md deleted file mode 100644 index 4180ca8a..00000000 --- a/cores/asr650x/kernel/protocols/lorawan/README.md +++ /dev/null @@ -1,2 +0,0 @@ -#lib_lorawan -This is lib_lorawan component. \ No newline at end of file diff --git a/cores/asr650x/kernel/protocols/lorawan/lorawan.mk b/cores/asr650x/kernel/protocols/lorawan/lorawan.mk deleted file mode 100644 index c613de4a..00000000 --- a/cores/asr650x/kernel/protocols/lorawan/lorawan.mk +++ /dev/null @@ -1,54 +0,0 @@ - -NAME := lorawan - -$(NAME)_SOURCES := lora/system/crypto/aes.c \ - lora/system/crypto/cmac.c \ - lora/system/timeServer.c \ - lora/system/low_power.c \ - lora/system/utilities.c \ - lora/system/delay.c \ - lora/mac/region/Region.c \ - lora/mac/region/RegionCommon.c \ - lora/mac/LoRaMac.c \ - lora/mac/LoRaMacCrypto.c \ - ../../../device/lora/sx1276/sx1276.c - -GLOBAL_INCLUDES += . \ - ../../../device/lora/sx1276 \ - lora/system/crypto \ - lora/radio \ - lora/mac \ - lora/mac/region \ - lora/system - -linkwan?=0 -ifeq ($(linkwan), 1) -GLOBAL_DEFINES += CONFIG_LINKWAN -GLOBAL_DEFINES += CONFIG_DEBUG_LINKWAN -GLOBAL_DEFINES += CONFIG_AOS_DISABLE_TICK -GLOBAL_DEFINES += REGION_CN470A -$(NAME)_SOURCES += linkwan/region/RegionCN470A.c -$(NAME)_SOURCES += linkwan/linkwan.c - -GLOBAL_INCLUDES += linkwan/include -GLOBAL_INCLUDES += linkwan/region - -linkwanat ?= 0 -ifeq ($(linkwanat), 1) -GLOBAL_DEFINES += CONFIG_LINKWAN_AT -GLOBAL_DEFINES += LOW_POWER_DISABLE -$(NAME)_SOURCES += linkwan/linkwan_ica_at.c -#$(NAME)_SOURCES += linkwan/linkwan_at.c -endif -else -$(NAME)_SOURCES += lora/mac/region/RegionAS923.c \ - lora/mac/region/RegionAU915.c \ - lora/mac/region/RegionCN470.c \ - lora/mac/region/RegionCN779.c \ - lora/mac/region/RegionEU433.c \ - lora/mac/region/RegionEU868.c \ - lora/mac/region/RegionIN865.c \ - lora/mac/region/RegionKR920.c \ - lora/mac/region/RegionUS915.c \ - lora/mac/region/RegionUS915-Hybrid.c -endif diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/LICENSE.txt b/cores/asr650x/loramac/LICENSE.txt similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/LICENSE.txt rename to cores/asr650x/loramac/LICENSE.txt diff --git a/cores/asr650x/loramac/mac/Commissioning.h b/cores/asr650x/loramac/mac/Commissioning.h new file mode 100644 index 00000000..5f287679 --- /dev/null +++ b/cores/asr650x/loramac/mac/Commissioning.h @@ -0,0 +1,44 @@ +/*! + * \file Commissioning.h + * + * \brief End device commissioning parameters + * + * \copyright Revised BSD License, see section \ref LICENSE. + * + * \code + * ______ _ + * / _____) _ | | + * ( (____ _____ ____ _| |_ _____ ____| |__ + * \____ \| ___ | (_ _) ___ |/ ___) _ \ + * _____) ) ____| | | || |_| ____( (___| | | | + * (______/|_____)_|_|_| \__)_____)\____)_| |_| + * (C)2013-2017 Semtech + * + * \endcode + * + * \author Miguel Luis ( Semtech ) + * + * \author Gregory Cristian ( Semtech ) + */ +#ifndef __LORA_COMMISSIONING_H__ +#define __LORA_COMMISSIONING_H__ + +#include "LoRaMac.h" + +/*! + * User application data buffer size + */ +#define LORAWAN_APP_DATA_MAX_SIZE 128 //if use AT mode, don't modify this value or may run dead + +/*! + * Indicates if the end-device is to be connected to a private or public network + */ +#define LORAWAN_PUBLIC_NETWORK true + +/*! + * Current network ID + */ +#define LORAWAN_NETWORK_ID ( uint32_t )0 + + +#endif // __LORA_COMMISSIONING_H__ diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.c b/cores/asr650x/loramac/mac/LoRaMac.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.c rename to cores/asr650x/loramac/mac/LoRaMac.c index bc731f1f..96b74cb0 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.c +++ b/cores/asr650x/loramac/mac/LoRaMac.c @@ -699,6 +699,7 @@ static void OpenContinuousRx2Window( void ); static void OnRadioTxDone( void ) { + DIO_PRINTF("Event : Tx Done\r\n"); GetPhyParams_t getPhy; PhyParam_t phyParam; SetBandTxDoneParams_t txDone; @@ -772,7 +773,7 @@ static void OnRadioTxDone( void ) #endif #if (LoraWan_RGB==1) - RGB_OFF(); + turnOffRGB(); #endif } @@ -795,6 +796,7 @@ static void PrepareRxDoneAbort( void ) void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { + DIO_PRINTF("Event : Rx Done\r\n"); uint8_t * temp = payload; LoRaMacHeader_t macHdr; LoRaMacFrameCtrl_t fCtrl; @@ -932,7 +934,7 @@ void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) LoRaMacConfirmQueueSetStatus( LORAMAC_EVENT_INFO_STATUS_OK, MLME_JOIN ); IsLoRaMacNetworkJoined = true; - SaveNetInfo(temp, size); + saveNetInfo(temp, size); //Joined save its DR using LoRaMacParams.ChannelsDatarate, if set it will be default // LoRaMacParams.ChannelsDatarate = LoRaMacParamsDefaults.ChannelsDatarate; } else { @@ -1088,7 +1090,7 @@ void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) } DownLinkCounter = downLinkCounter; if(DownLinkCounter%15000==0){ - SaveDownCnt(); + saveDownCnt(); } } @@ -1213,8 +1215,9 @@ void OnRadioRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) static void OnRadioTxTimeout( void ) { #if (LoraWan_RGB==1) - RGB_OFF(); + turnOffRGB(); #endif + DIO_PRINTF("Event : Tx Timeout\r\n"); if( LoRaMacDeviceClass != CLASS_C ) { @@ -1235,6 +1238,7 @@ static void OnRadioTxTimeout( void ) static void OnRadioRxError( void ) { + DIO_PRINTF("Event : Rx Error\r\n"); bool classBRx = false; if( LoRaMacDeviceClass != CLASS_C ) @@ -1307,8 +1311,10 @@ static void OnRadioRxError( void ) static void OnRadioRxTimeout( void ) { #if (LoraWan_RGB==1) - RGB_OFF(); + turnOffRGB(); #endif + DIO_PRINTF("Event : Rx Timeout\r\n"); + bool classBRx = false; if( LoRaMacDeviceClass != CLASS_C ) @@ -1707,7 +1713,7 @@ static void OnRxWindow1TimerEvent( void ) //printf("w1 dr:%d\r\n",McpsIndication.RxDatarate); RxWindowSetup( RxWindow1Config.RxContinuous, LoRaMacParams.MaxRxWindow ); #if(LoraWan_RGB==1) - RGB_ON(COLOR_RXWINDOW1,0); + turnOnRGB(COLOR_RXWINDOW1,0); #endif } @@ -1733,7 +1739,7 @@ static void OnRxWindow2TimerEvent( void ) RxSlot = RX_SLOT_WIN_2; } #if(LoraWan_RGB==1) - RGB_ON(COLOR_RXWINDOW2,0); + turnOnRGB(COLOR_RXWINDOW2,0); #endif } @@ -2843,7 +2849,7 @@ LoRaMacStatus_t SendFrameOnChannel( uint8_t channel ) } // Send now #if (LoraWan_RGB==1) - RGB_ON(COLOR_SEND,0); + turnOnRGB(COLOR_SEND,0); #endif Radio.Send( LoRaMacBuffer, LoRaMacBufferPktLen ); @@ -3672,8 +3678,7 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest ) case MLME_JOIN: { if ( ( mlmeRequest->Req.Join.DevEui == NULL ) || ( mlmeRequest->Req.Join.AppEui == NULL ) || - ( mlmeRequest->Req.Join.AppKey == NULL ) || - ( mlmeRequest->Req.Join.NbTrials == 0 ) ) { + ( mlmeRequest->Req.Join.AppKey == NULL )) { return LORAMAC_STATUS_PARAMETER_INVALID; } diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.h b/cores/asr650x/loramac/mac/LoRaMac.h similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.h rename to cores/asr650x/loramac/mac/LoRaMac.h index 30d89a7b..5dd283dd 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMac.h +++ b/cores/asr650x/loramac/mac/LoRaMac.h @@ -2449,8 +2449,8 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest ); */ LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest ); -extern void RGB_ON(uint32_t color,uint32_t time); -extern void RGB_OFF(void); +extern void turnOnRGB(uint32_t color,uint32_t time); +extern void turnOffRGB(void); #ifdef __cplusplus diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacClassB.h b/cores/asr650x/loramac/mac/LoRaMacClassB.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacClassB.h rename to cores/asr650x/loramac/mac/LoRaMacClassB.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacClassBConfig.h b/cores/asr650x/loramac/mac/LoRaMacClassBConfig.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacClassBConfig.h rename to cores/asr650x/loramac/mac/LoRaMacClassBConfig.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacConfirmQueue.c b/cores/asr650x/loramac/mac/LoRaMacConfirmQueue.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacConfirmQueue.c rename to cores/asr650x/loramac/mac/LoRaMacConfirmQueue.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacConfirmQueue.h b/cores/asr650x/loramac/mac/LoRaMacConfirmQueue.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacConfirmQueue.h rename to cores/asr650x/loramac/mac/LoRaMacConfirmQueue.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacCrypto.c b/cores/asr650x/loramac/mac/LoRaMacCrypto.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacCrypto.c rename to cores/asr650x/loramac/mac/LoRaMacCrypto.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacCrypto.h b/cores/asr650x/loramac/mac/LoRaMacCrypto.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacCrypto.h rename to cores/asr650x/loramac/mac/LoRaMacCrypto.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacTest.h b/cores/asr650x/loramac/mac/LoRaMacTest.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/LoRaMacTest.h rename to cores/asr650x/loramac/mac/LoRaMacTest.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/Region.c b/cores/asr650x/loramac/mac/region/Region.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/Region.c rename to cores/asr650x/loramac/mac/region/Region.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/Region.h b/cores/asr650x/loramac/mac/region/Region.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/Region.h rename to cores/asr650x/loramac/mac/region/Region.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAS923.c b/cores/asr650x/loramac/mac/region/RegionAS923.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAS923.c rename to cores/asr650x/loramac/mac/region/RegionAS923.c index 5c62a9f5..982cf4ab 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAS923.c +++ b/cores/asr650x/loramac/mac/region/RegionAS923.c @@ -663,7 +663,7 @@ bool RegionAS923RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) } Radio.SetMaxPayloadLength( modem, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -693,7 +693,7 @@ bool RegionAS923TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); } - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAS923.h b/cores/asr650x/loramac/mac/region/RegionAS923.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAS923.h rename to cores/asr650x/loramac/mac/region/RegionAS923.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAU915.c b/cores/asr650x/loramac/mac/region/RegionAU915.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAU915.c rename to cores/asr650x/loramac/mac/region/RegionAU915.c index 3df268f5..613ca075 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAU915.c +++ b/cores/asr650x/loramac/mac/region/RegionAU915.c @@ -572,7 +572,7 @@ bool RegionAU915RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateAU915[dr]; } Radio.SetMaxPayloadLength( MODEM_LORA, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); -// printf("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -592,7 +592,7 @@ bool RegionAU915TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime Radio.SetMaxPayloadLength( MODEM_LORA, txConfig->PktLen ); Radio.SetTxConfig( MODEM_LORA, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); -// printf("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); *txTimeOnAir = Radio.TimeOnAir( MODEM_LORA, txConfig->PktLen ); *txPower = txPowerLimited; diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAU915.h b/cores/asr650x/loramac/mac/region/RegionAU915.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionAU915.h rename to cores/asr650x/loramac/mac/region/RegionAU915.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN470.c b/cores/asr650x/loramac/mac/region/RegionCN470.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN470.c rename to cores/asr650x/loramac/mac/region/RegionCN470.c index 1dc33b5d..a20bca8d 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN470.c +++ b/cores/asr650x/loramac/mac/region/RegionCN470.c @@ -134,7 +134,7 @@ static uint8_t CountNbOfEnabledChannels( uint8_t datarate, uint16_t* channelsMas } } } - //printf("nbEnabledChannels: %d ",nbEnabledChannels); + *delayTx = delayTransmission; return nbEnabledChannels; } @@ -529,6 +529,7 @@ bool RegionCN470RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateCN470[dr]; } Radio.SetMaxPayloadLength( MODEM_LORA, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -547,6 +548,8 @@ bool RegionCN470TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime Radio.SetChannel( Channels[txConfig->Channel].Frequency ); Radio.SetTxConfig( MODEM_LORA, phyTxPower, 0, 0, phyDr, 1, 8, false, true, 0, 0, false, 3000 ); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( MODEM_LORA, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN470.h b/cores/asr650x/loramac/mac/region/RegionCN470.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN470.h rename to cores/asr650x/loramac/mac/region/RegionCN470.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN779.c b/cores/asr650x/loramac/mac/region/RegionCN779.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN779.c rename to cores/asr650x/loramac/mac/region/RegionCN779.c index 020fe8f4..aed5f951 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN779.c +++ b/cores/asr650x/loramac/mac/region/RegionCN779.c @@ -604,7 +604,7 @@ bool RegionCN779RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateCN779[dr]; } Radio.SetMaxPayloadLength( modem, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -634,7 +634,7 @@ bool RegionCN779TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); } - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN779.h b/cores/asr650x/loramac/mac/region/RegionCN779.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCN779.h rename to cores/asr650x/loramac/mac/region/RegionCN779.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCommon.c b/cores/asr650x/loramac/mac/region/RegionCommon.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCommon.c rename to cores/asr650x/loramac/mac/region/RegionCommon.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCommon.h b/cores/asr650x/loramac/mac/region/RegionCommon.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionCommon.h rename to cores/asr650x/loramac/mac/region/RegionCommon.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU433.c b/cores/asr650x/loramac/mac/region/RegionEU433.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU433.c rename to cores/asr650x/loramac/mac/region/RegionEU433.c index 47e4979a..a6fe27aa 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU433.c +++ b/cores/asr650x/loramac/mac/region/RegionEU433.c @@ -604,7 +604,7 @@ bool RegionEU433RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateEU433[dr]; } Radio.SetMaxPayloadLength( modem, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -634,7 +634,7 @@ bool RegionEU433TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); } - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU433.h b/cores/asr650x/loramac/mac/region/RegionEU433.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU433.h rename to cores/asr650x/loramac/mac/region/RegionEU433.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU868.c b/cores/asr650x/loramac/mac/region/RegionEU868.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU868.c rename to cores/asr650x/loramac/mac/region/RegionEU868.c index 3049b53a..872b34a1 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU868.c +++ b/cores/asr650x/loramac/mac/region/RegionEU868.c @@ -634,7 +634,7 @@ bool RegionEU868RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) } Radio.SetMaxPayloadLength( modem, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); -// printf("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -664,7 +664,7 @@ bool RegionEU868TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3000 ); } -// printf("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU868.h b/cores/asr650x/loramac/mac/region/RegionEU868.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionEU868.h rename to cores/asr650x/loramac/mac/region/RegionEU868.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionIN865.c b/cores/asr650x/loramac/mac/region/RegionIN865.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionIN865.c rename to cores/asr650x/loramac/mac/region/RegionIN865.c index ebcdb321..63c8fd53 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionIN865.c +++ b/cores/asr650x/loramac/mac/region/RegionIN865.c @@ -608,7 +608,7 @@ bool RegionIN865RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateIN865[dr]; } Radio.SetMaxPayloadLength( modem, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -638,7 +638,7 @@ bool RegionIN865TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime modem = MODEM_LORA; Radio.SetTxConfig( modem, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); } - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( modem, txConfig->PktLen ); // Get the time-on-air of the next tx frame diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionIN865.h b/cores/asr650x/loramac/mac/region/RegionIN865.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionIN865.h rename to cores/asr650x/loramac/mac/region/RegionIN865.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionKR920.c b/cores/asr650x/loramac/mac/region/RegionKR920.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionKR920.c rename to cores/asr650x/loramac/mac/region/RegionKR920.c index a96e53de..273231f7 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionKR920.c +++ b/cores/asr650x/loramac/mac/region/RegionKR920.c @@ -609,7 +609,7 @@ bool RegionKR920RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) Radio.SetRxConfig( MODEM_LORA, rxConfig->Bandwidth, phyDr, 1, 0, 8, rxConfig->WindowTimeout, false, 0, false, 0, 0, true, rxConfig->RxContinuous ); maxPayload = MaxPayloadOfDatarateKR920[dr]; Radio.SetMaxPayloadLength( MODEM_LORA, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -634,7 +634,7 @@ bool RegionKR920TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime Radio.SetChannel( Channels[txConfig->Channel].Frequency ); Radio.SetTxConfig( MODEM_LORA, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 4e3 ); - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); // Setup maximum payload lenght of the radio driver Radio.SetMaxPayloadLength( MODEM_LORA, txConfig->PktLen ); diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionKR920.h b/cores/asr650x/loramac/mac/region/RegionKR920.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionKR920.h rename to cores/asr650x/loramac/mac/region/RegionKR920.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915-Hybrid.c b/cores/asr650x/loramac/mac/region/RegionUS915-Hybrid.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915-Hybrid.c rename to cores/asr650x/loramac/mac/region/RegionUS915-Hybrid.c index d2238c99..bddb1d44 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915-Hybrid.c +++ b/cores/asr650x/loramac/mac/region/RegionUS915-Hybrid.c @@ -673,7 +673,7 @@ bool RegionUS915HybridRxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateUS915_HYBRID[dr]; } Radio.SetMaxPayloadLength( MODEM_LORA, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -693,7 +693,7 @@ bool RegionUS915HybridTxConfig( TxConfigParams_t* txConfig, int8_t* txPower, Tim Radio.SetMaxPayloadLength( MODEM_LORA, txConfig->PktLen ); Radio.SetTxConfig( MODEM_LORA, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); *txTimeOnAir = Radio.TimeOnAir( MODEM_LORA, txConfig->PktLen ); *txPower = txPowerLimited; diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915-Hybrid.h b/cores/asr650x/loramac/mac/region/RegionUS915-Hybrid.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915-Hybrid.h rename to cores/asr650x/loramac/mac/region/RegionUS915-Hybrid.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915.c b/cores/asr650x/loramac/mac/region/RegionUS915.c similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915.c rename to cores/asr650x/loramac/mac/region/RegionUS915.c index 1ba7f6ea..ead9adc2 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915.c +++ b/cores/asr650x/loramac/mac/region/RegionUS915.c @@ -586,7 +586,7 @@ bool RegionUS915RxConfig( RxConfigParams_t* rxConfig, int8_t* datarate ) maxPayload = MaxPayloadOfDatarateUS915[dr]; } Radio.SetMaxPayloadLength( MODEM_LORA, maxPayload + LORA_MAC_FRMPAYLOAD_OVERHEAD ); - DBG_PRINTF("RX on freq %u Hz at DR %d\n\r", (unsigned int)frequency, dr); + FREQ_PRINTF("RX on freq %u Hz at DR %d\r\n", (unsigned int)frequency, dr); *datarate = (uint8_t) dr; return true; @@ -606,7 +606,7 @@ bool RegionUS915TxConfig( TxConfigParams_t* txConfig, int8_t* txPower, TimerTime Radio.SetMaxPayloadLength( MODEM_LORA, txConfig->PktLen ); Radio.SetTxConfig( MODEM_LORA, phyTxPower, 0, bandwidth, phyDr, 1, 8, false, true, 0, 0, false, 3e3 ); - DBG_PRINTF("TX on freq %u Hz at DR %d\n\r", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); + FREQ_PRINTF("TX on freq %u Hz at DR %d\r\n", (unsigned int)Channels[txConfig->Channel].Frequency, txConfig->Datarate); *txTimeOnAir = Radio.TimeOnAir( MODEM_LORA, txConfig->PktLen ); *txPower = txPowerLimited; diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915.h b/cores/asr650x/loramac/mac/region/RegionUS915.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/mac/region/RegionUS915.h rename to cores/asr650x/loramac/mac/region/RegionUS915.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/radio/radio.h b/cores/asr650x/loramac/radio/radio.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/radio/radio.h rename to cores/asr650x/loramac/radio/radio.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/readme.md b/cores/asr650x/loramac/readme.md similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/readme.md rename to cores/asr650x/loramac/readme.md diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/aes.c b/cores/asr650x/loramac/system/crypto/aes.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/aes.c rename to cores/asr650x/loramac/system/crypto/aes.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/aes.h b/cores/asr650x/loramac/system/crypto/aes.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/aes.h rename to cores/asr650x/loramac/system/crypto/aes.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/cmac.c b/cores/asr650x/loramac/system/crypto/cmac.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/cmac.c rename to cores/asr650x/loramac/system/crypto/cmac.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/cmac.h b/cores/asr650x/loramac/system/crypto/cmac.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/crypto/cmac.h rename to cores/asr650x/loramac/system/crypto/cmac.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/delay.c b/cores/asr650x/loramac/system/delay.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/delay.c rename to cores/asr650x/loramac/system/delay.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/delay.h b/cores/asr650x/loramac/system/delay.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/delay.h rename to cores/asr650x/loramac/system/delay.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.c b/cores/asr650x/loramac/system/low_power.c similarity index 97% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.c rename to cores/asr650x/loramac/system/low_power.c index c3724c53..1be0e895 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.c +++ b/cores/asr650x/loramac/system/low_power.c @@ -61,7 +61,7 @@ static uint32_t LowPower_State = 0; /* Private function prototypes -----------------------------------------------*/ -extern bool WakeByUart; +extern bool wakeByUart; @@ -109,11 +109,11 @@ uint32_t LowPower_GetState( void ) * @param None * @retval None */ -void LowPower_Handler( void ) +void lowPowerHandler( void ) { CPSR_ALLOC(); RHINO_CPU_INTRPT_DISABLE(); - if (LowPower_State == 0 && WakeByUart == false) { + if (LowPower_State == 0 && wakeByUart == false) { // printf("s"); DBG_PRINTF_CRITICAL("dz\n\r"); aos_lrwan_chg_mode.enter_stop_mode(); diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.h b/cores/asr650x/loramac/system/low_power.h similarity index 99% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.h rename to cores/asr650x/loramac/system/low_power.h index acd8ee7e..1dc47216 100644 --- a/cores/asr650x/kernel/protocols/lorawan/lora/system/low_power.h +++ b/cores/asr650x/loramac/system/low_power.h @@ -87,7 +87,7 @@ uint32_t LowPower_GetState( void ); * @param none * @retval none */ -void LowPower_Handler( void ); +void lowPowerHandler( void ); #ifdef __cplusplus } diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/timeServer.h b/cores/asr650x/loramac/system/timeServer.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/timeServer.h rename to cores/asr650x/loramac/system/timeServer.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/timer.h b/cores/asr650x/loramac/system/timer.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/timer.h rename to cores/asr650x/loramac/system/timer.h diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/utilities.c b/cores/asr650x/loramac/system/utilities.c similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/utilities.c rename to cores/asr650x/loramac/system/utilities.c diff --git a/cores/asr650x/kernel/protocols/lorawan/lora/system/utilities.h b/cores/asr650x/loramac/system/utilities.h similarity index 100% rename from cores/asr650x/kernel/protocols/lorawan/lora/system/utilities.h rename to cores/asr650x/loramac/system/utilities.h diff --git a/cores/asr650x/projects/CubeCellLib.a b/cores/asr650x/projects/CubeCellLib.a index e51c8ef6..6ed82808 100644 Binary files a/cores/asr650x/projects/CubeCellLib.a and b/cores/asr650x/projects/CubeCellLib.a differ diff --git a/libraries/Basics/examples/Factory_Test_AB01/Factory_Test_AB01.ino b/libraries/Basics/examples/Factory_Test_AB01/Factory_Test_AB01.ino index 16c8d440..6d3426dc 100644 --- a/libraries/Basics/examples/Factory_Test_AB01/Factory_Test_AB01.ino +++ b/libraries/Basics/examples/Factory_Test_AB01/Factory_Test_AB01.ino @@ -1,6 +1,6 @@ #include "LoRaWan_APP.h" #include "Arduino.h" -#include "SSD1306Wire.h" +#include "cubecell_SSD1306Wire.h" #include "Wire.h" /* * set LoraWan_RGB to 1,the RGB active @@ -44,7 +44,7 @@ void OnTxTimeout( void ); void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); void displayInof(); void sleep(void); -void RGB_test(void); +void testRGB(void); typedef enum { @@ -53,15 +53,15 @@ typedef enum TX }States_t; -int16_t txnumber; +int16_t txNumber; States_t state; -bool sleepmode = false; -int16_t RSSI,rxSize; +bool sleepMode = false; +int16_t rssi,rxSize; void setup() { - BoardInitMcu( ); + boardInitMcu( ); Serial.begin(115200); pinMode(Vext, OUTPUT); digitalWrite(Vext, LOW); @@ -69,9 +69,9 @@ void setup() { display.init(); //display.flipScreenVertically(); - RGB_test(); - txnumber=0; - RSSI=0; + testRGB(); + txNumber=0; + rssi=0; pinMode(P3_3,INPUT); attachInterrupt(P3_3,sleep,FALLING); @@ -102,12 +102,12 @@ void loop() { case TX: delay(1000); - txnumber++; + txNumber++; sprintf(txpacket,"%s","hello"); - sprintf(txpacket+strlen(txpacket),"%d",txnumber); + sprintf(txpacket+strlen(txpacket),"%d",txNumber); sprintf(txpacket+strlen(txpacket),"%s"," rssi : "); - sprintf(txpacket+strlen(txpacket),"%d",RSSI); - RGB_ON(0x100000,0); + sprintf(txpacket+strlen(txpacket),"%d",rssi); + turnOnRGB(0x100000,0); Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); @@ -120,22 +120,22 @@ void loop() state=LOWPOWER; break; case LOWPOWER: - if(sleepmode) + if(sleepMode) { Radio.Sleep( ); Wire.end(); detachInterrupt(RADIO_DIO_1); - RGB_OFF(); + turnOffRGB(); pinMode(GPIO0,ANALOG); pinMode(GPIO1,ANALOG); pinMode(GPIO2,ANALOG); pinMode(GPIO3,ANALOG); - pinMode(GPIO4,ANALOG); + pinMode(GPIO4,ANALOG); pinMode(GPIO5,ANALOG); - pinMode(Vext,ANALOG); + pinMode(Vext,ANALOG); pinMode(ADC,ANALOG); } - LowPower_Handler(); + lowPowerHandler(); break; default: break; @@ -147,7 +147,7 @@ void OnTxDone( void ) { Serial.print("TX done......"); displayInof(); - RGB_ON(0,0); + turnOnRGB(0,0); state=RX; } @@ -160,15 +160,15 @@ void OnTxTimeout( void ) void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { gpioOn(); - RSSI=rssi; + rssi=rssi; rxSize=size; memcpy(rxpacket, payload, size ); rxpacket[size]='\0'; - RGB_ON(0x001000,100); - RGB_ON(0,0); + turnOnRGB(0x001000,100); + turnOnRGB(0,0); Radio.Sleep( ); - Serial.printf("\r\nreceived packet \"%s\" with RSSI %d , length %d\r\n",rxpacket,RSSI,rxSize); + Serial.printf("\r\nreceived packet \"%s\" with rssi %d , length %d\r\n",rxpacket,rssi,rxSize); Serial.println("wait to send next packet"); displayInof(); @@ -178,10 +178,10 @@ void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) void displayInof() { display.clear(); - display.drawString(0, 50, "Packet " + String(txnumber,DEC) + " sent done"); + display.drawString(0, 50, "Packet " + String(txNumber,DEC) + " sent done"); display.drawString(0, 0, "Received Size" + String(rxSize,DEC) + " packages:"); display.drawString(0, 15, rxpacket); - display.drawString(0, 30, "With RSSI " + String(RSSI,DEC)); + display.drawString(0, 30, "With rssi " + String(rssi,DEC)); display.display(); } @@ -191,27 +191,27 @@ void sleep(void) delay(10); if(digitalRead(P3_3)==0) { - sleepmode = true; + sleepMode = true; } } -void RGB_test(void) +void testRGB(void) { display.drawString(0, 20, "RGB Testing"); - display.display(); + display.display(); for(uint32_t i=0;i<=30;i++) { - RGB_ON(i<<16,10); + turnOnRGB(i<<16,10); } for(uint32_t i=0;i<=30;i++) { - RGB_ON(i<<8,10); + turnOnRGB(i<<8,10); } for(uint32_t i=0;i<=30;i++) { - RGB_ON(i,10); + turnOnRGB(i,10); } - RGB_ON(0,0); + turnOnRGB(0,0); } void gpioOn(void) diff --git a/libraries/Basics/examples/Factory_Test_AM01/Factory_Test_AM01.ino b/libraries/Basics/examples/Factory_Test_AM01/Factory_Test_AM01.ino index ca95e2e1..4af1a3fd 100644 --- a/libraries/Basics/examples/Factory_Test_AM01/Factory_Test_AM01.ino +++ b/libraries/Basics/examples/Factory_Test_AM01/Factory_Test_AM01.ino @@ -1,6 +1,6 @@ #include "LoRaWan_APP.h" #include "Arduino.h" -#include "SSD1306Wire.h" +#include "cubecell_SSD1306Wire.h" #include "Wire.h" /* * set LoraWan_RGB to 1,the RGB active @@ -52,15 +52,15 @@ typedef enum TX }States_t; -int16_t txnumber; +int16_t txNumber; States_t state; -bool sleepmode = false; -int16_t RSSI,rxSize; +bool sleepMode = false; +int16_t rssi,rxSize; void setup() { - BoardInitMcu( ); + boardInitMcu( ); Serial.begin(115200); pinMode(ADC, OUTPUT); digitalWrite(ADC, HIGH); @@ -68,8 +68,8 @@ void setup() { display.init(); //display.flipScreenVertically(); - txnumber=0; - RSSI=0; + txNumber=0; + rssi=0; pinMode(GPIO7,INPUT); attachInterrupt(GPIO7,sleep,FALLING); @@ -100,11 +100,11 @@ void loop() { case TX: delay(1000); - txnumber++; + txNumber++; sprintf(txpacket,"%s","hello"); - sprintf(txpacket+strlen(txpacket),"%d",txnumber); + sprintf(txpacket+strlen(txpacket),"%d",txNumber); sprintf(txpacket+strlen(txpacket),"%s"," rssi : "); - sprintf(txpacket+strlen(txpacket),"%d",RSSI); + sprintf(txpacket+strlen(txpacket),"%d",rssi); Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); @@ -117,21 +117,21 @@ void loop() state=LOWPOWER; break; case LOWPOWER: - if(sleepmode) + if(sleepMode) { Radio.Sleep( ); Wire.end(); - Serial.end(); + Serial.end(); detachInterrupt(RADIO_DIO_1); pinMode(GPIO0,ANALOG); pinMode(GPIO1,ANALOG); pinMode(GPIO2,ANALOG); pinMode(GPIO3,ANALOG); - pinMode(GPIO4,ANALOG); + pinMode(GPIO4,ANALOG); pinMode(GPIO5,ANALOG); pinMode(ADC,ANALOG); } - LowPower_Handler(); + lowPowerHandler(); break; default: break; @@ -155,13 +155,13 @@ void OnTxTimeout( void ) void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { gpioOn(); - RSSI=rssi; + rssi=rssi; rxSize=size; memcpy(rxpacket, payload, size ); rxpacket[size]='\0'; Radio.Sleep( ); - Serial.printf("\r\nreceived packet \"%s\" with RSSI %d , length %d\r\n",rxpacket,RSSI,rxSize); + Serial.printf("\r\nreceived packet \"%s\" with rssi %d , length %d\r\n",rxpacket,rssi,rxSize); Serial.println("wait to send next packet"); displayInof(); @@ -171,10 +171,10 @@ void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) void displayInof() { display.clear(); - display.drawString(0, 50, "Packet " + String(txnumber,DEC) + " sent done"); + display.drawString(0, 50, "Packet " + String(txNumber,DEC) + " sent done"); display.drawString(0, 0, "Received Size" + String(rxSize,DEC) + " packages:"); display.drawString(0, 15, rxpacket); - display.drawString(0, 30, "With RSSI " + String(RSSI,DEC)); + display.drawString(0, 30, "With rssi " + String(rssi,DEC)); display.display(); } @@ -184,7 +184,7 @@ void sleep(void) delay(10); if(digitalRead(P3_3)==0) { - sleepmode = true; + sleepMode = true; } } diff --git a/libraries/Basics/examples/LowPower_WakeUpByGPIO/LowPower_WakeUpByGPIO.ino b/libraries/Basics/examples/LowPower_WakeUpByGPIO/LowPower_WakeUpByGPIO.ino index 9ac45c57..a0517209 100644 --- a/libraries/Basics/examples/LowPower_WakeUpByGPIO/LowPower_WakeUpByGPIO.ino +++ b/libraries/Basics/examples/LowPower_WakeUpByGPIO/LowPower_WakeUpByGPIO.ino @@ -5,12 +5,12 @@ static TimerEvent_t sleep; uint8_t lowpower=1; -void OnSleep() +void onSleep() { Serial.println("into lowpower mode. press user key to wake up"); lowpower=1; } -void wakeup() +void wakeUp() { delay(10); if(digitalRead(GPIO7)==0) @@ -26,18 +26,18 @@ void wakeup() void setup() { // put your setup code here, to run once: Serial.begin(115200); - BoardInitMcu(); + boardInitMcu(); Radio.Sleep( ); pinMode(GPIO7,INPUT); - attachInterrupt(GPIO7,wakeup,FALLING); - TimerInit( &sleep, OnSleep ); + attachInterrupt(GPIO7,wakeUp,FALLING); + TimerInit( &sleep, onSleep ); Serial.println("into lowpower mode. press user key to wake up."); } void loop() { if(lowpower){ - //note that LowPower_Handler() run six times the mcu into lowpower mode; - LowPower_Handler(); + //note that lowPowerHandler() run six times the mcu into lowpower mode; + lowPowerHandler(); } // put your main code here, to run repeatedly: } diff --git a/libraries/Basics/examples/LowPower_WakeUpByTimer/LowPower_WakeUpByTimer.ino b/libraries/Basics/examples/LowPower_WakeUpByTimer/LowPower_WakeUpByTimer.ino index d367908e..d0800e28 100644 --- a/libraries/Basics/examples/LowPower_WakeUpByTimer/LowPower_WakeUpByTimer.ino +++ b/libraries/Basics/examples/LowPower_WakeUpByTimer/LowPower_WakeUpByTimer.ino @@ -4,18 +4,18 @@ #define timetosleep 5000 #define timetowake 5000 static TimerEvent_t sleep; -static TimerEvent_t wakeup; +static TimerEvent_t wakeUp; uint8_t lowpower=1; -void OnSleep() +void onSleep() { Serial.printf("into lowpower mode, %d ms later wake up.\r\n",timetowake); lowpower=1; //timetosleep ms later wake up; - TimerSetValue( &wakeup, timetowake ); - TimerStart( &wakeup ); + TimerSetValue( &wakeUp, timetowake ); + TimerStart( &wakeUp ); } -void OnWakeup() +void onWakeUp() { Serial.printf("wake up, %d ms later into lowpower mode.\r\n",timetosleep); lowpower=0; @@ -27,17 +27,17 @@ void OnWakeup() void setup() { // put your setup code here, to run once: Serial.begin(115200); - BoardInitMcu(); + boardInitMcu(); Radio.Sleep( ); TimerInit( &sleep, OnSleep ); - TimerInit( &wakeup, OnWakeup ); + TimerInit( &wakeUp, onWakeUp ); OnSleep(); } void loop() { if(lowpower){ - //note that LowPower_Handler() run six times the mcu into lowpower mode; - LowPower_Handler(); + //note that lowPowerHandler() run six times the mcu into lowpower mode; + lowPowerHandler(); } // put your main code here, to run repeatedly: } diff --git a/libraries/LoRa/examples/AT_Command/AT_Command.ino b/libraries/LoRa/examples/AT_Command/AT_Command.ino index 284a37ec..47403ad4 100644 --- a/libraries/LoRa/examples/AT_Command/AT_Command.ino +++ b/libraries/LoRa/examples/AT_Command/AT_Command.ino @@ -11,20 +11,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = true; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -45,114 +64,115 @@ bool IsTxConfirmed = true; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { - AppDataSize = 4;//AppDataSize max value is 64 - AppData[0] = 0x00; - AppData[1] = 0x01; - AppData[2] = 0x02; - AppData[3] = 0x03; + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ + appDataSize = 4; + appData[0] = 0x00; + appData[1] = 0x01; + appData[2] = 0x02; + appData[3] = 0x03; } void setup() { - BoardInitMcu(); + boardInitMcu(); Serial.begin(115200); - PassthroughMode = true; - Enable_AT(); + passthroughMode = true; + enableAt(); getDevParam(); printDevParam(); - DeviceState = DEVICE_STATE_SLEEP; - LoRaWAN.Ifskipjoin(); - DeviceState_lora = LORA_INIT; + deviceState = DEVICE_STATE_SLEEP; + LoRaWAN.ifskipjoin(); + deviceState_lora = LORA_INIT; } void loop() { - if(Mode_LoraWan)//loraWan mode(defalt;) + if(modeLoraWan)//loraWan mode(defalt;) { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { //Serial.printf("LoRaWan PassthroughMode start!\r\n"); //Serial.printf("please start with command\r\n"); getDevParam(); - LoRaWAN.Init(CLASS,ACTIVE_REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_SLEEP; + LoRaWAN.send(); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_CYCLE: { // only used while joining - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - DeviceState = DEVICE_STATE_SLEEP; - LoRaWAN.Cycle(TxDutyCycleTime); + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + deviceState = DEVICE_STATE_SLEEP; + LoRaWAN.cycle(txDutyCycleTime); break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_SLEEP; + deviceState = DEVICE_STATE_SLEEP; break; } } } else//lora mode { - switch( DeviceState_lora ) + switch( deviceState_lora ) { case LORA_INIT: { getDevParam(); - LoRa.Init(Lora_FREQ, Lora_TXPW, Lora_SF); - DeviceState_lora = MCU_SLEEP; + LoRa.init(Lora_FREQ, Lora_TXPW, Lora_SF); + deviceState_lora = MCU_SLEEP; break; } case LORA_SEND: { - LoRa.Send(); - DeviceState_lora = MCU_SLEEP; + LoRa.send(); + deviceState_lora = MCU_SLEEP; break; } case LORA_RECEIVE: { - LoRa.Receive(); - DeviceState_lora = MCU_SLEEP; + LoRa.receive(); + deviceState_lora = MCU_SLEEP; break; } case MCU_SLEEP: { - LoRa.LOWPOWER(); + LoRa.lowpower(); break; } default: { - DeviceState_lora = MCU_SLEEP; + deviceState_lora = MCU_SLEEP; break; } } diff --git a/libraries/LoRa/examples/LoRaBasic/LoRaSender/LoRaSender.ino b/libraries/LoRa/examples/LoRaBasic/LoRaSender/LoRaSender.ino index 6ece593c..6dd17b28 100644 --- a/libraries/LoRa/examples/LoRaBasic/LoRaSender/LoRaSender.ino +++ b/libraries/LoRa/examples/LoRaBasic/LoRaSender/LoRaSender.ino @@ -47,21 +47,17 @@ char rxpacket[BUFFER_SIZE]; static RadioEvents_t RadioEvents; -int16_t txnumber; +int16_t txNumber; -int16_t RSSI,rxSize; +int16_t rssi,rxSize; void setup() { - BoardInitMcu( ); + boardInitMcu( ); Serial.begin(115200); - txnumber=0; - RSSI=0; - - - - + txNumber=0; + rssi=0; Radio.Init( &RadioEvents ); Radio.SetChannel( RF_FREQUENCY ); @@ -75,20 +71,16 @@ void setup() { void loop() { - - - delay(1000); - txnumber++; - sprintf(txpacket,"%s","Hello world number"); //start a package - sprintf(txpacket+strlen(txpacket),"%d",txnumber); //add to the end of package + delay(1000); + txNumber++; + sprintf(txpacket,"%s","Hello world number"); //start a package + sprintf(txpacket+strlen(txpacket),"%d",txNumber); //add to the end of package - RGB_ON(COLOR_SEND,0); //change rgb light + turnOnRGB(COLOR_SEND,0); //change rgb color - Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); + Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); - Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out - - + Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out } diff --git a/libraries/LoRa/examples/LoRaBasic/LoRaSender_ReadBattery/LoRaSender_ReadBattery.ino b/libraries/LoRa/examples/LoRaBasic/LoRaSender_ReadBattery/LoRaSender_ReadBattery.ino index 9ae1a26d..9043e555 100644 --- a/libraries/LoRa/examples/LoRaBasic/LoRaSender_ReadBattery/LoRaSender_ReadBattery.ino +++ b/libraries/LoRa/examples/LoRaBasic/LoRaSender_ReadBattery/LoRaSender_ReadBattery.ino @@ -51,7 +51,7 @@ #define RX_TIMEOUT_VALUE 1000 #define BUFFER_SIZE 30 // Define the payload size here -char txpacket[BUFFER_SIZE]; +char txPacket[BUFFER_SIZE]; static RadioEvents_t RadioEvents; void OnTxDone( void ); @@ -67,17 +67,16 @@ typedef enum }States_t; States_t state; -bool sleepmode = false; -int16_t RSSI,rxSize; +bool sleepMode = false; +int16_t rssi,rxSize; uint16_t voltage; void setup() { - BoardInitMcu( ); + boardInitMcu( ); Serial.begin(115200); - // txnumber=0; voltage = 0; - RSSI=0; + rssi=0; RadioEvents.TxDone = OnTxDone; RadioEvents.TxTimeout = OnTxTimeout; @@ -100,19 +99,19 @@ void loop() { case TX: { - sprintf(txpacket,"%s","ADC_battery: "); - sprintf(txpacket+strlen(txpacket),"%d",voltage); - RGB_ON(COLOR_SEND,0); - Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); - Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); + sprintf(txPacket,"%s","ADC_battery: "); + sprintf(txPacket+strlen(txPacket),"%d",voltage); + turnOnRGB(COLOR_SEND,0); + Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txPacket, strlen(txPacket)); + Radio.Send( (uint8_t *)txPacket, strlen(txPacket) ); state=LOWPOWER; break; } case LOWPOWER: { - LowPower_Handler(); + lowPowerHandler(); delay(100); - RGB_OFF(); + turnOffRGB(); delay(2000); //LowPower time state = ReadVoltage; break; @@ -134,7 +133,7 @@ void loop() void OnTxDone( void ) { Serial.print("TX done!"); - RGB_ON(0,0); + turnOnRGB(0,0); state=TX; } diff --git a/libraries/LoRa/examples/LoRaBasic/pingpong/pingpong.ino b/libraries/LoRa/examples/LoRaBasic/pingpong/pingpong.ino index c623db65..94f8966f 100644 --- a/libraries/LoRa/examples/LoRaBasic/pingpong/pingpong.ino +++ b/libraries/LoRa/examples/LoRaBasic/pingpong/pingpong.ino @@ -58,8 +58,6 @@ void OnTxDone( void ); void OnTxTimeout( void ); void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); - - typedef enum { LOWPOWER, @@ -67,18 +65,18 @@ typedef enum TX }States_t; -int16_t txnumber; +int16_t txNumber; States_t state; -bool sleepmode = false; -int16_t RSSI,rxSize; +bool sleepMode = false; +int16_t rssi,rxSize; void setup() { - BoardInitMcu( ); + boardInitMcu( ); Serial.begin(115200); - txnumber=0; - RSSI=0; + txNumber=0; + rssi=0; RadioEvents.TxDone = OnTxDone; RadioEvents.TxTimeout = OnTxTimeout; @@ -106,12 +104,12 @@ void loop() { case TX: delay(1000); - txnumber++; + txNumber++; sprintf(txpacket,"%s","hello"); - sprintf(txpacket+strlen(txpacket),"%d",txnumber); + sprintf(txpacket+strlen(txpacket),"%d",txNumber); sprintf(txpacket+strlen(txpacket),"%s"," rssi : "); - sprintf(txpacket+strlen(txpacket),"%d",RSSI); - RGB_ON(COLOR_SEND,0); + sprintf(txpacket+strlen(txpacket),"%d",rssi); + turnOnRGB(COLOR_SEND,0); Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket)); @@ -124,7 +122,7 @@ void loop() state=LOWPOWER; break; case LOWPOWER: - LowPower_Handler(); + lowPowerHandler(); break; default: break; @@ -135,7 +133,7 @@ void loop() void OnTxDone( void ) { Serial.print("TX done......"); - RGB_ON(0,0); + turnOnRGB(0,0); state=RX; } @@ -147,14 +145,14 @@ void OnTxTimeout( void ) } void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ) { - RSSI=rssi; + rssi=rssi; rxSize=size; memcpy(rxpacket, payload, size ); rxpacket[size]='\0'; - RGB_ON(COLOR_RECEIVED,0); + turnOnRGB(COLOR_RECEIVED,0); Radio.Sleep( ); - Serial.printf("\r\nreceived packet \"%s\" with RSSI %d , length %d\r\n",rxpacket,RSSI,rxSize); + Serial.printf("\r\nreceived packet \"%s\" with rssi %d , length %d\r\n",rxpacket,rssi,rxSize); Serial.println("wait to send next packet"); state=TX; diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BH1750/LoRaWan_BH1750.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BH1750/LoRaWan_BH1750.ino index 5b95b6e4..4799a2e9 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BH1750/LoRaWan_BH1750.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BH1750/LoRaWan_BH1750.ino @@ -12,20 +12,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -46,18 +65,20 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ BH1750 lightMeter; -static void PrepareTxFrame( uint8_t port ) + +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ pinMode(GPIO0, OUTPUT); pinMode(Vext, OUTPUT); digitalWrite(GPIO0, HIGH); @@ -70,38 +91,39 @@ static void PrepareTxFrame( uint8_t port ) digitalWrite(Vext, HIGH); digitalWrite(GPIO0, LOW); pinMode(GPIO0, ANALOG); - uint16_t BatteryVoltage = GetBatteryVoltage(); + uint16_t batteryVoltage = getBatteryVoltage(); unsigned char *puc; puc = (unsigned char *)(&lux); - AppDataSize = 6;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; - AppData[4] = (uint8_t)(BatteryVoltage>>8); - AppData[5] = (uint8_t)BatteryVoltage; + + appDataSize = 6; + appData[0] = puc[0]; + appData[1] = puc[1]; + appData[2] = puc[2]; + appData[3] = puc[3]; + appData[4] = (uint8_t)(batteryVoltage>>8); + appData[5] = (uint8_t)batteryVoltage; Serial.print("Light: "); Serial.print(lux); Serial.print(" lx,");Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { @@ -109,40 +131,40 @@ void loop() getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BMP180/LoRaWan_BMP180.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BMP180/LoRaWan_BMP180.ino index bacc3e22..83e3002c 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BMP180/LoRaWan_BMP180.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_BMP180/LoRaWan_BMP180.ino @@ -12,20 +12,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -46,18 +65,20 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ BMP085 bmp; -static void PrepareTxFrame( uint8_t port ) + +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ pinMode(Vext, OUTPUT); digitalWrite(Vext, LOW); @@ -65,7 +86,7 @@ static void PrepareTxFrame( uint8_t port ) float temperature = bmp.readTemperature(); float pressure = bmp.readPressure(); float altitude = bmp.readAltitude(); - float sealevelpressure = bmp.readSealevelPressure(); + float sealevelPressure = bmp.readSealevelPressure(); // you can get a more precise measurement of altitude // if you know the current sea level pressure which will @@ -77,30 +98,30 @@ static void PrepareTxFrame( uint8_t port ) Wire.end(); digitalWrite(Vext, HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); + uint16_t batteryVoltage = getBatteryVoltage(); unsigned char *puc; puc = (unsigned char *)(&temperature); - AppDataSize = 14;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; + appDataSize = 14; + appData[0] = puc[0]; + appData[1] = puc[1]; + appData[2] = puc[2]; + appData[3] = puc[3]; puc = (unsigned char *)(&pressure); - AppData[4] = puc[0]; - AppData[5] = puc[1]; - AppData[6] = puc[2]; - AppData[7] = puc[3]; + appData[4] = puc[0]; + appData[5] = puc[1]; + appData[6] = puc[2]; + appData[7] = puc[3]; puc = (unsigned char *)(&altitude); - AppData[8] = puc[0]; - AppData[9] = puc[1]; - AppData[10] = puc[2]; - AppData[11] = puc[3]; + appData[8] = puc[0]; + appData[9] = puc[1]; + appData[10] = puc[2]; + appData[11] = puc[3]; - AppData[12] = (uint8_t)(BatteryVoltage>>8); - AppData[13] = (uint8_t)BatteryVoltage; + appData[12] = (uint8_t)(batteryVoltage>>8); + appData[13] = (uint8_t)batteryVoltage; Serial.print("Temperature: "); Serial.print(temperature); @@ -108,64 +129,64 @@ static void PrepareTxFrame( uint8_t port ) Serial.print(pressure); Serial.print("Pa, "); Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: - { + { #if(AT_SUPPORT) getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_CCS811/LoRaWan_CCS811.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_CCS811/LoRaWan_CCS811.ino index 82f7a876..fc292693 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_CCS811/LoRaWan_CCS811.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_CCS811/LoRaWan_CCS811.ino @@ -3,6 +3,7 @@ #include #include + /* * set LoraWan_RGB to Active,the RGB active in loraWan * RGB red means sending; @@ -12,20 +13,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -46,18 +66,20 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ CCS811 ccs; -static void PrepareTxFrame( uint8_t port ) + +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ pinMode(Vext, OUTPUT); digitalWrite(Vext, LOW); pinMode(GPIO0,OUTPUT); @@ -91,16 +113,16 @@ static void PrepareTxFrame( uint8_t port ) digitalWrite(Vext, HIGH); digitalWrite(GPIO0,HIGH); digitalWrite(GPIO4,LOW); - uint16_t BatteryVoltage = GetBatteryVoltage(); + uint16_t batteryVoltage = getBatteryVoltage(); - AppDataSize = 6;//AppDataSize max value is 64 - AppData[0] = (uint8_t)(co2>>8); - AppData[1] = (uint8_t)co2; - AppData[2] = (uint8_t)(tvoc>>8); - AppData[3] = (uint8_t)tvoc; - - AppData[4] = (uint8_t)(BatteryVoltage>>8); - AppData[5] = (uint8_t)BatteryVoltage; + appDataSize = 6; + appData[0] = (uint8_t)(co2>>8); + appData[1] = (uint8_t)co2; + appData[2] = (uint8_t)(tvoc>>8); + appData[3] = (uint8_t)tvoc; + + appData[4] = (uint8_t)(batteryVoltage>>8); + appData[5] = (uint8_t)batteryVoltage; Serial.print("CO2: "); Serial.print(co2); @@ -109,64 +131,64 @@ static void PrepareTxFrame( uint8_t port ) Serial.print(tvoc); Serial.print(" ppb,"); Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: - { + { #if(AT_SUPPORT) getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino index 9520d782..bb927772 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino @@ -2,6 +2,8 @@ #include "Arduino.h" #include #include "HDC1080.h" +#include "LoRaWan_APP.h" +#include "Arduino.h" /* * set LoraWan_RGB to Active,the RGB active in loraWan @@ -12,20 +14,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -46,110 +67,111 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /*! * \brief Prepares the payload of the frame */ HDC1080 hdc1080; -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ pinMode(Vext,OUTPUT); digitalWrite(Vext,LOW); hdc1080.begin(0x40); - float Temperature = (float)(hdc1080.readTemperature()); - float Humidity = (float)(hdc1080.readHumidity()); + float temperature = (float)(hdc1080.readTemperature()); + float humidity = (float)(hdc1080.readHumidity()); hdc1080.end(); digitalWrite(Vext,HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); + uint16_t batteryVoltage = getBatteryVoltage(); unsigned char *puc; - puc = (unsigned char *)(&Temperature); - AppDataSize = 10;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; + puc = (unsigned char *)(&temperature); + appDataSize = 10; + appData[0] = puc[0]; + appData[1] = puc[1]; + appData[2] = puc[2]; + appData[3] = puc[3]; - puc = (unsigned char *)(&Humidity); - AppData[4] = puc[0]; - AppData[5] = puc[1]; - AppData[6] = puc[2]; - AppData[7] = puc[3]; + puc = (unsigned char *)(&humidity); + appData[4] = puc[0]; + appData[5] = puc[1]; + appData[6] = puc[2]; + appData[7] = puc[3]; - AppData[8] = (uint8_t)(BatteryVoltage>>8); - AppData[9] = (uint8_t)BatteryVoltage; + appData[8] = (uint8_t)(batteryVoltage>>8); + appData[9] = (uint8_t)batteryVoltage; Serial.print("T="); - Serial.print(Temperature); + Serial.print(temperature); Serial.print("C, RH="); - Serial.print(Humidity); + Serial.print(humidity); Serial.print("%,"); Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: - { + { #if(AT_SUPPORT) getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MPU9250/LoRaWan_MPU9250.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MPU9250/LoRaWan_MPU9250.ino index 66247719..d2ac24f8 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MPU9250/LoRaWan_MPU9250.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MPU9250/LoRaWan_MPU9250.ino @@ -3,7 +3,6 @@ #include #include - /* * set LoraWan_RGB to Active,the RGB active in loraWan * RGB red means sending; @@ -13,20 +12,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -47,23 +65,23 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; - +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ MPU9250 mySensor; -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ float aX, aY, aZ, aSqrt, gX, gY, gZ, mDirection, mX, mY, mZ; - pinMode(Vext, OUTPUT); - digitalWrite(Vext, LOW); + pinMode(Vext, OUTPUT); + digitalWrite(Vext, LOW); Wire.begin(); mySensor.setWire(&Wire); @@ -120,90 +138,90 @@ static void PrepareTxFrame( uint8_t port ) Serial.print("mDirection:"); Serial.println(mDirection); - Wire.end(); - digitalWrite(Vext, HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); - unsigned char *puc; - - puc = (unsigned char *)(&aX); - AppDataSize = 46;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; + Wire.end(); + digitalWrite(Vext, HIGH); + uint16_t batteryVoltage = getBatteryVoltage(); + unsigned char *puc; + + puc = (unsigned char *)(&aX); + appDataSize = 46; + appData[0] = puc[0]; + appData[1] = puc[1]; + appData[2] = puc[2]; + appData[3] = puc[3]; puc = (unsigned char *)(&aY); - AppData[4] = puc[0]; - AppData[5] = puc[1]; - AppData[6] = puc[2]; - AppData[7] = puc[3]; + appData[4] = puc[0]; + appData[5] = puc[1]; + appData[6] = puc[2]; + appData[7] = puc[3]; puc = (unsigned char *)(&aZ); - AppData[8] = puc[0]; - AppData[9] = puc[1]; - AppData[10] = puc[2]; - AppData[11] = puc[3]; + appData[8] = puc[0]; + appData[9] = puc[1]; + appData[10] = puc[2]; + appData[11] = puc[3]; puc = (unsigned char *)(&gX); - AppData[12] = puc[0]; - AppData[13] = puc[1]; - AppData[14] = puc[2]; - AppData[15] = puc[3]; + appData[12] = puc[0]; + appData[13] = puc[1]; + appData[14] = puc[2]; + appData[15] = puc[3]; puc = (unsigned char *)(&gY); - AppData[16] = puc[0]; - AppData[17] = puc[1]; - AppData[18] = puc[2]; - AppData[19] = puc[3]; + appData[16] = puc[0]; + appData[17] = puc[1]; + appData[18] = puc[2]; + appData[19] = puc[3]; puc = (unsigned char *)(&gZ); - AppData[20] = puc[0]; - AppData[21] = puc[1]; - AppData[22] = puc[2]; - AppData[23] = puc[3]; + appData[20] = puc[0]; + appData[21] = puc[1]; + appData[22] = puc[2]; + appData[23] = puc[3]; puc = (unsigned char *)(&mX); - AppData[24] = puc[0]; - AppData[25] = puc[1]; - AppData[26] = puc[2]; - AppData[27] = puc[3]; + appData[24] = puc[0]; + appData[25] = puc[1]; + appData[26] = puc[2]; + appData[27] = puc[3]; puc = (unsigned char *)(&mY); - AppData[28] = puc[0]; - AppData[29] = puc[1]; - AppData[30] = puc[2]; - AppData[31] = puc[3]; + appData[28] = puc[0]; + appData[29] = puc[1]; + appData[30] = puc[2]; + appData[31] = puc[3]; puc = (unsigned char *)(&mZ); - AppData[32] = puc[0]; - AppData[33] = puc[1]; - AppData[34] = puc[2]; - AppData[35] = puc[3]; + appData[32] = puc[0]; + appData[33] = puc[1]; + appData[34] = puc[2]; + appData[35] = puc[3]; puc = (unsigned char *)(&aSqrt); - AppData[36] = puc[0]; - AppData[37] = puc[1]; - AppData[38] = puc[2]; - AppData[39] = puc[3]; + appData[36] = puc[0]; + appData[37] = puc[1]; + appData[38] = puc[2]; + appData[39] = puc[3]; puc = (unsigned char *)(&mDirection); - AppData[40] = puc[0]; - AppData[41] = puc[1]; - AppData[42] = puc[2]; - AppData[43] = puc[3]; + appData[40] = puc[0]; + appData[41] = puc[1]; + appData[42] = puc[2]; + appData[43] = puc[3]; - AppData[44] = (uint8_t)(BatteryVoltage>>8); - AppData[45] = (uint8_t)BatteryVoltage; + appData[44] = (uint8_t)(batteryVoltage>>8); + appData[45] = (uint8_t)batteryVoltage; Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { @@ -211,40 +229,40 @@ void loop() getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MultiSensor/LoRaWan_MultiSensor.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MultiSensor/LoRaWan_MultiSensor.ino index 76a36264..f077d5c3 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MultiSensor/LoRaWan_MultiSensor.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors/LoRaWan_MultiSensor/LoRaWan_MultiSensor.ino @@ -30,18 +30,15 @@ #define ModularNode 0 // TCS9548A I2C 8 port Switch -const char myDevEui[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -const char myAppEui[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -const char myAppKey[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; -/* the application data transmission duty cycle. value in [ms]. */ -uint32_t APP_TX_DUTYCYCLE = 900000; - -/* Indicates if the node is sending confirmed or unconfirmed messages. */ -bool IsTxConfirmed = false; - -/* Number of trials to transmit the frame. */ -uint8_t ConfirmedNbTrials = 8; +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; /* @@ -86,59 +83,51 @@ bool HMC_5883L_e[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // 12 bool UART_e = false; // 200 bool One_Wire_e = false; // 100-103 -/* - set LoraWan_RGB to Active,the RGB active in loraWan - RGB red means sending; - RGB purple means joined done; - RGB blue means RxWindow1; - RGB yellow means RxWindow2; - RGB green means received done; -*/ -#ifndef LoraWan_RGB -#define LoraWan_RGB 0 -#endif -/* - set to 1 the enable AT mode - set to 0 the disable support AT mode -*/ -#ifndef AT_SUPPORT -#define AT_SUPPORT 0 -#endif +/*LoraWan region, select in arduino IDE tools*/ +LoRaMacRegion_t loraWanRegion = ACTIVE_REGION; -#ifndef ACTIVE_REGION -#define ACTIVE_REGION LORAMAC_REGION_EU868 -#endif +/*LoraWan Class, Class A and Class C are supported*/ +DeviceClass_t loraWanClass = LORAWAN_CLASS; -#ifndef LORAWAN_CLASS -#define LORAWAN_CLASS CLASS_A -#endif +/*the application data transmission duty cycle. value in [ms].*/ +uint32_t appTxDutyCycle = 15000; -#ifndef LORAWAN_NETMODE -#define LORAWAN_NETMODE 0 -#endif - -#ifndef LORAWAN_ADR -#define LORAWAN_ADR 1 -#endif - -#ifndef LORAWAN_Net_Reserve -#define LORAWAN_Net_Reserve 1 -#endif - -/*LoraWan Class*/ -DeviceClass_t CLASS = LORAWAN_CLASS; /*OTAA or ABP*/ -bool OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +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 appPort = 2; +/*! +* Number of trials to transmit the frame, if the LoRaMAC layer did not +* receive an acknowledgment. The MAC performs a datarate adaptation, +* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according +* to the following table: +* +* Transmission nb | Data Rate +* ----------------|----------- +* 1 (first) | DR +* 2 | DR +* 3 | max(DR-1,0) +* 4 | max(DR-1,0) +* 5 | max(DR-2,0) +* 6 | max(DR-2,0) +* 7 | max(DR-3,0) +* 8 | max(DR-3,0) +* +* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease +* the datarate, in case the LoRaMAC layer did not receive an acknowledgment +*/ +uint8_t confirmedNbTrials = 8; float Temperature, Humidity, Pressure, lux, co2, tvoc; uint16_t baseline, baselinetemp; @@ -170,7 +159,7 @@ SC16IS740 extSerial(Wire, 0); \brief Prepares the payload of the frame */ -static void PrepareTxFrame(uint8_t port) +static void prepareTxFrame(uint8_t port) { pinMode(Vext, OUTPUT); digitalWrite(Vext, LOW); @@ -178,7 +167,7 @@ static void PrepareTxFrame(uint8_t port) pinMode(GPIO0, OUTPUT); digitalWrite(GPIO0, LOW); - AppDataSize = 0; + appDataSize = 0; int pnr = 0; #if (ModularNode == 1) @@ -221,24 +210,24 @@ static void PrepareTxFrame(uint8_t port) tvoc = CalculateIAQ(); Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 1; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 1; - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)(Humidity * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)(Humidity * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(Humidity * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Humidity * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); ; - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)co2 >> 8); - AppData[AppDataSize++] = (uint8_t)((int)co2); + appData[appDataSize++] = (uint8_t)((int)co2 >> 8); + appData[appDataSize++] = (uint8_t)((int)co2); - AppData[AppDataSize++] = (uint8_t)((int)tvoc >> 8); - AppData[AppDataSize++] = (uint8_t)((int)tvoc); + appData[appDataSize++] = (uint8_t)((int)tvoc >> 8); + appData[appDataSize++] = (uint8_t)((int)tvoc); Serial.print(" BME680: T = "); Serial.print(Temperature); @@ -275,18 +264,18 @@ static void PrepareTxFrame(uint8_t port) Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 2; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 2; - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)(Humidity * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)(Humidity * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(Humidity * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Humidity * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); ; - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0)); Serial.print(" BME280: T = "); Serial.print(Temperature); @@ -334,14 +323,14 @@ static void PrepareTxFrame(uint8_t port) } hdc1080.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 4; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 4; - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = ((int)(Humidity * 10.0)) >> 8; - AppData[AppDataSize++] = (int)(Humidity * 10.0); + appData[appDataSize++] = ((int)(Humidity * 10.0)) >> 8; + appData[appDataSize++] = (int)(Humidity * 10.0); Serial.print(" HDC1080: T = "); Serial.print(Temperature); @@ -411,14 +400,14 @@ static void PrepareTxFrame(uint8_t port) Serial.println(" CCS ERROR"); } - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 3; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 3; - AppData[AppDataSize++] = (uint8_t)((int)co2 >> 8); - AppData[AppDataSize++] = (uint8_t)((int)co2); + appData[appDataSize++] = (uint8_t)((int)co2 >> 8); + appData[appDataSize++] = (uint8_t)((int)co2); - AppData[AppDataSize++] = (uint8_t)((int)tvoc >> 8); - AppData[AppDataSize++] = (uint8_t)((int)tvoc); + appData[appDataSize++] = (uint8_t)((int)tvoc >> 8); + appData[appDataSize++] = (uint8_t)((int)tvoc); Serial.print(" CCS811: CO2 = "); Serial.print(co2); @@ -464,15 +453,15 @@ static void PrepareTxFrame(uint8_t port) Serial.println(" BMP ERROR"); } - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 5; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 5; - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0) >> 8); ; - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0)); Serial.print(" BMP180: T = "); Serial.print(Temperature); @@ -506,11 +495,11 @@ static void PrepareTxFrame(uint8_t port) lightMeter.end(); Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 6; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 6; - AppData[AppDataSize++] = (uint8_t)((int)(lux * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)(lux * 10.0)); + appData[appDataSize++] = (uint8_t)((int)(lux * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)(lux * 10.0)); Serial.print(" BH1750: Light = "); Serial.print(lux); @@ -561,15 +550,15 @@ static void PrepareTxFrame(uint8_t port) Serial.println(" BMP ERROR"); } - AppData[AppDataSize++] = pnr; + appData[appDataSize++] = pnr; - AppData[AppDataSize++] = 7; + appData[appDataSize++] = 7; - AppData[AppDataSize++] = (uint8_t)(((int)((Temperature + 100.0) * 10.0)) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)(((int)((Temperature + 100.0) * 10.0)) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = (uint8_t)(((int)(Pressure * 10.0)) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)(Pressure * 10.0)); + appData[appDataSize++] = (uint8_t)(((int)(Pressure * 10.0)) >> 8); + appData[appDataSize++] = (uint8_t)((int)(Pressure * 10.0)); Serial.print(" BMP280: T="); Serial.print(Temperature); @@ -612,14 +601,14 @@ static void PrepareTxFrame(uint8_t port) */ Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 8; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 8; - AppData[AppDataSize++] = (uint8_t)(((int)((Temperature + 100.0) * 10.0)) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = (uint8_t)(((int)((Temperature + 100.0) * 10.0)) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); - AppData[AppDataSize++] = ((int)(Humidity * 10.0)) >> 8; - AppData[AppDataSize++] = (int)(Humidity * 10.0); + appData[appDataSize++] = ((int)(Humidity * 10.0)) >> 8; + appData[appDataSize++] = (int)(Humidity * 10.0); Serial.print(" SHT2X: T="); Serial.print(Temperature); @@ -648,17 +637,17 @@ static void PrepareTxFrame(uint8_t port) adc2 = ads1015.readADC_SingleEnded(2); adc3 = ads1015.readADC_SingleEnded(3); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 9; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 9; - AppData[AppDataSize++] = ((int)adc0) >> 8; - AppData[AppDataSize++] = (int)adc0; - AppData[AppDataSize++] = ((int)adc1) >> 8; - AppData[AppDataSize++] = (int)adc1; - AppData[AppDataSize++] = ((int)adc2) >> 8; - AppData[AppDataSize++] = (int)adc2; - AppData[AppDataSize++] = ((int)adc3) >> 8; - AppData[AppDataSize++] = (int)adc3; + appData[appDataSize++] = ((int)adc0) >> 8; + appData[appDataSize++] = (int)adc0; + appData[appDataSize++] = ((int)adc1) >> 8; + appData[appDataSize++] = (int)adc1; + appData[appDataSize++] = ((int)adc2) >> 8; + appData[appDataSize++] = (int)adc2; + appData[appDataSize++] = ((int)adc3) >> 8; + appData[appDataSize++] = (int)adc3; Serial.print(" ADS1015: ADC0="); Serial.print(adc0); @@ -754,65 +743,65 @@ static void PrepareTxFrame(uint8_t port) Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 10; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 10; unsigned char *puc; puc = (unsigned char *)(&aX); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&aY); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&aZ); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&gX); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&gY); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&gZ); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&mX); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&mY); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&mZ); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&aSqrt); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&mDirection); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; } /* @@ -844,15 +833,15 @@ static void PrepareTxFrame(uint8_t port) Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 11; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 11; unsigned char *puc; puc = (unsigned char *)(&distance); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; } /* @@ -886,25 +875,25 @@ static void PrepareTxFrame(uint8_t port) Wire.end(); - AppData[AppDataSize++] = pnr; - AppData[AppDataSize++] = 12; + appData[appDataSize++] = pnr; + appData[appDataSize++] = 12; unsigned char *puc; puc = (unsigned char *)(&raw.XAxis); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&raw.YAxis); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; puc = (unsigned char *)(&raw.ZAxis); - AppData[AppDataSize++] = puc[0]; - AppData[AppDataSize++] = puc[1]; - AppData[AppDataSize++] = puc[2]; - AppData[AppDataSize++] = puc[3]; + appData[appDataSize++] = puc[0]; + appData[appDataSize++] = puc[1]; + appData[appDataSize++] = puc[2]; + appData[appDataSize++] = puc[3]; } #if (ModularNode == 1) } @@ -936,8 +925,8 @@ static void PrepareTxFrame(uint8_t port) Wire.end(); - AppData[AppDataSize++] = 0; - AppData[AppDataSize++] = 200; + appData[appDataSize++] = 0; + appData[appDataSize++] = 200; } @@ -956,10 +945,10 @@ static void PrepareTxFrame(uint8_t port) for (int idxx=0; idxx < sensors.getDeviceCount(); idxx++) { Temperature = sensors.getTempCByIndex(idxx); - AppData[AppDataSize++] = 100; - AppData[AppDataSize++] = 100 + idxx; - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); - AppData[AppDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); + appData[appDataSize++] = 100; + appData[appDataSize++] = 100 + idxx; + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0) >> 8); + appData[appDataSize++] = (uint8_t)((int)((Temperature + 100.0) * 10.0)); Serial.print(" OW"); if (idxx < 10) { @@ -982,20 +971,16 @@ static void PrepareTxFrame(uint8_t port) digitalWrite(Vext, HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); - AppData[AppDataSize++] = (uint8_t)(BatteryVoltage >> 8); - AppData[AppDataSize++] = (uint8_t)BatteryVoltage; + uint16_t batteryVoltage = getBatteryVoltage(); + appData[appDataSize++] = (uint8_t)(batteryVoltage >> 8); + appData[appDataSize++] = (uint8_t)batteryVoltage; Serial.print("BatteryVoltage: "); - Serial.print(BatteryVoltage); + Serial.print(batteryVoltage); Serial.println(); } void setup() { - memcpy(DevEui, myDevEui, sizeof(myDevEui)); - memcpy(AppEui, myAppEui, sizeof(myAppEui)); - memcpy(AppKey, myAppKey, sizeof(myAppKey)); - #if (AUTO_SCAN == 1) for (int xx = 0; xx < 8; xx++) { @@ -1069,24 +1054,24 @@ void setup() // UART_e = true; //#endif - BoardInitMcu(); + boardInitMcu(); Serial.begin(115200); Serial.println("Copyright @ 2019 WASN.eu"); Serial.print("FW-version: "); Serial.println(wasnver); Serial.println(""); -#if (AT_SUPPORT == 1) - Enable_AT(); +#if(AT_SUPPORT) + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); -pinMode(Vext, OUTPUT); -digitalWrite(Vext, LOW); //set vext to high -delay(500); -pinMode(GPIO0, OUTPUT); -digitalWrite(GPIO0, LOW); -Wire.begin(); + pinMode(Vext, OUTPUT); + digitalWrite(Vext, LOW); //set vext to high + delay(500); + pinMode(GPIO0, OUTPUT); + digitalWrite(GPIO0, LOW); + Wire.begin(); #if (AUTO_SCAN == 1) byte error, address; @@ -1257,52 +1242,52 @@ Wire.begin(); void loop() { - switch (DeviceState) - { - case DEVICE_STATE_INIT: - { -#if (AT_SUPPORT == 1) - getDevParam(); + switch( deviceState ) + { + case DEVICE_STATE_INIT: + { +#if(AT_SUPPORT) + getDevParam(); #endif - printDevParam(); - Serial.printf("LoRaWan Class % X start! \r\n", CLASS + 10); - LoRaWAN.Init(CLASS, REGION); - 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 = APP_TX_DUTYCYCLE + 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; - } - } + 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; + } + } } + float CalculateIAQ() { float hum_weighting = 0.25; // so hum effect is 25% of the total air quality score @@ -1353,7 +1338,7 @@ void tcaselect(uint8_t i) Wire.endTransmission(); } -bool AT_user_check(char *cmd, char *content) +bool checkUserAt(char *cmd, char *content) { if (strcmp(cmd, "VER") == 0) { @@ -1368,7 +1353,7 @@ bool AT_user_check(char *cmd, char *content) } //downlink data handle function -void DownLinkDataHandle(McpsIndication_t *mcpsIndication) +void downLinkDataHandle(McpsIndication_t *mcpsIndication) { Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port); Serial.print("+REV DATA:"); @@ -1378,11 +1363,11 @@ void DownLinkDataHandle(McpsIndication_t *mcpsIndication) Serial.println(); for(uint8_t i=0;iBufferSize;i++) { if (mcpsIndication->Buffer[i] == 220) { // DC for APP_TX_DUTYCYCLE; 0D BB A0 for 900000 (15min); 04 93 E0 for 300000 (5min) - APP_TX_DUTYCYCLE = mcpsIndication->Buffer[i++]<<32|mcpsIndication->Buffer[i++]<<16|mcpsIndication->Buffer[i++]<<8|mcpsIndication->Buffer[i++]; + appTxDutyCycle = mcpsIndication->Buffer[i++]<<32|mcpsIndication->Buffer[i++]<<16|mcpsIndication->Buffer[i++]<<8|mcpsIndication->Buffer[i++]; Serial.print(" new DutyCycle received: "); - Serial.print(APP_TX_DUTYCYCLE); + Serial.print(appTxDutyCycle); Serial.println("ms"); - SaveDr(); + saveDr(); } } -} \ No newline at end of file +} diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors_ThirdParty/examples/LoRaWAN_BMP280/LoRaWAN_BMP280.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors_ThirdParty/examples/LoRaWAN_BMP280/LoRaWAN_BMP280.ino index 91c7642a..4dea82df 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors_ThirdParty/examples/LoRaWAN_BMP280/LoRaWAN_BMP280.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWAN_Sensors_ThirdParty/examples/LoRaWAN_BMP280/LoRaWAN_BMP280.ino @@ -12,20 +12,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -46,15 +65,9 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; +uint8_t confirmedNbTrials = 8; -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; - -float Temperature, Humidity, Pressure, lux, co2, tvoc; +float temperature, humidity, pressure, lux, co2, tvoc; uint16_t baseline; int count; int maxtry = 50; @@ -65,8 +78,15 @@ BMP280 bmp; \brief Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ pinMode(Vext, OUTPUT); digitalWrite(Vext, LOW); delay(500); @@ -79,9 +99,9 @@ static void PrepareTxFrame( uint8_t port ) BMP280::FILTER_X16, /* Filtering. */ BMP280::STANDBY_MS_500); /* Standby time. */ float temp = bmp.readTemperature(); - Pressure = (float)bmp.readPressure() / 100.0; + pressure = (float)bmp.readPressure() / 100.0; Wire.end(); - while (Pressure > 1190.0 && count < maxtry) { + while (pressure > 1190.0 && count < maxtry) { bmp.begin(); delay(500); bmp.setSampling(BMP280::MODE_NORMAL, /* Operating Mode. */ @@ -89,69 +109,69 @@ static void PrepareTxFrame( uint8_t port ) BMP280::SAMPLING_X16, /* Pressure oversampling */ BMP280::FILTER_X16, /* Filtering. */ BMP280::STANDBY_MS_500); /* Standby time. */ - Pressure = (float)bmp.readPressure() / 100.0; + pressure = (float)bmp.readPressure() / 100.0; Wire.end(); count++; delay(500); } - if (Pressure > 1190.0) { - Pressure = 0; + if (pressure > 1190.0) { + pressure = 0; Serial.println("BMP ERROR"); } Wire.end(); digitalWrite(Vext, HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); + uint16_t batteryVoltage = getBatteryVoltage(); unsigned char *puc; - puc = (unsigned char *)(&Temperature); - AppDataSize = 26;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; + puc = (unsigned char *)(&temperature); + appDataSize = 26; + appData[0] = puc[0]; + appData[1] = puc[1]; + appData[2] = puc[2]; + appData[3] = puc[3]; - puc = (unsigned char *)(&Humidity); - AppData[4] = puc[0]; - AppData[5] = puc[1]; - AppData[6] = puc[2]; - AppData[7] = puc[3]; + puc = (unsigned char *)(&humidity); + appData[4] = puc[0]; + appData[5] = puc[1]; + appData[6] = puc[2]; + appData[7] = puc[3]; puc = (unsigned char *)(&lux); - AppData[8] = puc[0]; - AppData[9] = puc[1]; - AppData[10] = puc[2]; - AppData[11] = puc[3]; + appData[8] = puc[0]; + appData[9] = puc[1]; + appData[10] = puc[2]; + appData[11] = puc[3]; - puc = (unsigned char *)(&Pressure); - AppData[12] = puc[0]; - AppData[13] = puc[1]; - AppData[14] = puc[2]; - AppData[15] = puc[3]; + puc = (unsigned char *)(&pressure); + appData[12] = puc[0]; + appData[13] = puc[1]; + appData[14] = puc[2]; + appData[15] = puc[3]; puc = (unsigned char *)(&co2); - AppData[16] = puc[0]; - AppData[17] = puc[1]; - AppData[18] = puc[2]; - AppData[19] = puc[3]; + appData[16] = puc[0]; + appData[17] = puc[1]; + appData[18] = puc[2]; + appData[19] = puc[3]; puc = (unsigned char *)(&tvoc); - AppData[20] = puc[0]; - AppData[21] = puc[1]; - AppData[22] = puc[2]; - AppData[23] = puc[3]; + appData[20] = puc[0]; + appData[21] = puc[1]; + appData[22] = puc[2]; + appData[23] = puc[3]; - AppData[24] = (uint8_t)(BatteryVoltage >> 8); - AppData[25] = (uint8_t)BatteryVoltage; + appData[24] = (uint8_t)(batteryVoltage >> 8); + appData[25] = (uint8_t)batteryVoltage; Serial.print("T="); - Serial.print(Temperature); + Serial.print(temperature); Serial.print("C, RH="); - Serial.print(Humidity); + Serial.print(humidity); Serial.print("%, Lux="); Serial.print(lux); Serial.print(" lx, Pressure="); - Serial.print(Pressure); + Serial.print(pressure); Serial.print(" hPA, CO2="); Serial.print(co2); Serial.print(" ppm, TVOC="); @@ -159,61 +179,64 @@ static void PrepareTxFrame( uint8_t port ) Serial.print(" ppb, Baseline: "); Serial.print(baseline); Serial.print(", BatteryVoltage:"); - Serial.println(BatteryVoltage); + Serial.println(batteryVoltage); } void setup() { - BoardInitMcu( ); - Serial.begin(115200); - DeviceState = DEVICE_STATE_INIT; + boardInitMcu(); + Serial.begin(115200); +#if(AT_SUPPORT) + enableAt(); +#endif + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch ( DeviceState ) - { - case DEVICE_STATE_INIT: - { - Serial.printf("LoRaWan Class%X test start! \r\n", CLASS + 10); + switch( deviceState ) + { + case DEVICE_STATE_INIT: + { #if(AT_SUPPORT) - Enable_AT(); - getDevParam(); + getDevParam(); #endif - printDevParam(); - LoRaWAN.Init(CLASS, ACTIVE_REGION); - 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 = APP_TX_DUTYCYCLE + 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; - } - } -} \ No newline at end of file + 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; + } + } +} + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWan/LoRaWan.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWan/LoRaWan.ino index 5cd813dc..1986ba8f 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWan/LoRaWan.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWan/LoRaWan.ino @@ -10,19 +10,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; + +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -43,79 +63,79 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { - AppDataSize = 4;//AppDataSize max value is 64 - AppData[0] = 0x00; - AppData[1] = 0x01; - AppData[2] = 0x02; - AppData[3] = 0x03; + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ + appDataSize = 4; + appData[0] = 0x00; + appData[1] = 0x01; + appData[2] = 0x02; + appData[3] = 0x03; } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { #if(AT_SUPPORT) - getDevParam(); + getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWan_downlinkdatahandle/LoRaWan_downlinkdatahandle.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWan_downlinkdatahandle/LoRaWan_downlinkdatahandle.ino index cf4e1744..6a41c79d 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWan_downlinkdatahandle/LoRaWan_downlinkdatahandle.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWan_downlinkdatahandle/LoRaWan_downlinkdatahandle.ino @@ -10,19 +10,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; + +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -43,26 +63,27 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { - AppDataSize = 4;//AppDataSize max value is 64 - AppData[0] = 0x00; - AppData[1] = 0x01; - AppData[2] = 0x02; - AppData[3] = 0x03; + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ + appDataSize = 4; + appData[0] = 0x00; + appData[1] = 0x01; + appData[2] = 0x02; + appData[3] = 0x03; } //downlink data handle function example -void DownLinkDataHandle(McpsIndication_t *mcpsIndication) +void downLinkDataHandle(McpsIndication_t *mcpsIndication) { Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port); Serial.print("+REV DATA:"); @@ -73,65 +94,64 @@ void DownLinkDataHandle(McpsIndication_t *mcpsIndication) Serial.println(); uint32_t color=mcpsIndication->Buffer[0]<<16|mcpsIndication->Buffer[1]<<8|mcpsIndication->Buffer[2]; #if(LoraWan_RGB==1) - RGB_ON(color,5000); - RGB_OFF(); + turnOnRGB(color,5000); + turnOffRGB(); #endif } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { #if(AT_SUPPORT) - getDevParam(); + getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWan_interrupt/LoRaWan_interrupt.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWan_interrupt/LoRaWan_interrupt.ino index 2fe61bf0..01dacd78 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWan_interrupt/LoRaWan_interrupt.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWan_interrupt/LoRaWan_interrupt.ino @@ -1,108 +1,111 @@ #include "LoRaWan_APP.h" -#include #include "Arduino.h" -const char myDevEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -const char myAppEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -const char myAppKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; // The interrupt pin is attached to D4/GPIO1 #define INT_PIN GPIO1 +/* Application port */ +#define DEVPORT 2 +#define APPPORT 1 + bool accelWoke = false; -DeviceClass_t CLASS = LORAWAN_CLASS; +/*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 = (24 * 60 * 60 * 1000); // 24h; /*OTAA or ABP*/ -bool OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; -/* LoRaWAN Adaptive Data Rate */ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +/*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; - -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = DEVPORT; /*! - Number of trials to transmit the frame, if the LoRaMAC layer did not - receive an acknowledgment. The MAC performs a datarate adaptation, - according to the LoRaWAN Specification V1.0.2, chapter 18.4, according - to the following table: - - Transmission nb | Data Rate - ----------------|----------- - 1 (first) | DR - 2 | DR - 3 | max(DR-1,0) - 4 | max(DR-1,0) - 5 | max(DR-2,0) - 6 | max(DR-2,0) - 7 | max(DR-3,0) - 8 | max(DR-3,0) - - Note, that if NbTrials is set to 1 or 2, the MAC will not decrease - the datarate, in case the LoRaMAC layer did not receive an acknowledgment +* Number of trials to transmit the frame, if the LoRaMAC layer did not +* receive an acknowledgment. The MAC performs a datarate adaptation, +* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according +* to the following table: +* +* Transmission nb | Data Rate +* ----------------|----------- +* 1 (first) | DR +* 2 | DR +* 3 | max(DR-1,0) +* 4 | max(DR-1,0) +* 5 | max(DR-2,0) +* 6 | max(DR-2,0) +* 7 | max(DR-3,0) +* 8 | max(DR-3,0) +* +* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease +* the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -#define DEVPORT 2 -#define APPPORT 1 -uint8_t AppPort = 1; +uint8_t confirmedNbTrials = 8; -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = (24 * 60 * 60 * 1000); // 24h /* Prepares the payload of the frame */ static bool prepareTxFrame( uint8_t port ) { int head; - AppPort = port; + appPort = port; switch (port) { case 1: // woke up from interrupt Serial.println("Sending data packet"); - AppDataSize = 1;//AppDataSize max value is 64 - AppData[0] = 0xFF; // set to something useful + appDataSize = 1;//AppDataSize max value is 64 + appData[0] = 0xFF; // set to something useful break; case 2: // daily wake up Serial.println("Sending dev status packet"); - AppDataSize = 1;//AppDataSize max value is 64 - AppData[0] = 0xA0; // set to something else useful + appDataSize = 1;//AppDataSize max value is 64 + appData[0] = 0xA0; // set to something else useful break; } return true; } -extern uint8_t DevEui[]; -extern uint8_t AppEui[]; -extern uint8_t AppKey[]; -extern bool IsLoRaMacNetworkJoined; - void accelWakeup() { - accelWoke = true; + delay(10); + if(digitalRead(INT_PIN)==HIGH) + { + accelWoke = true; + } } void setup() { + boardInitMcu(); Serial.begin(115200); +#if(AT_SUPPORT) + enableAt(); +#endif + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); - delay(200); // wait for stable accelWoke = false; - - memcpy(DevEui, myDevEui, sizeof(myDevEui)); - memcpy(AppEui, myAppEui, sizeof(myAppEui)); - memcpy(AppKey, myAppKey, sizeof(myAppKey)); - BoardInitMcu(); - - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); - - pinMode(INT_PIN, INPUT); + PINMODE_INPUT_PULLDOWN(INT_PIN); attachInterrupt(INT_PIN, accelWakeup, RISING); Serial.println("Interrupts attached"); } @@ -114,58 +117,55 @@ void loop() Serial.print(now); Serial.println("accel woke"); } - switch ( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: - { - Serial.printf("LoRaWan Class%X test start! \r\n", CLASS + 10); + { #if(AT_SUPPORT) - Enable_AT(); - getDevParam(); + getDevParam(); #endif - printDevParam(); - LoRaWAN.Init(CLASS, REGION); - DeviceState = DEVICE_STATE_JOIN; - break; - } + printDevParam(); + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; + break; + } case DEVICE_STATE_JOIN: - { - LoRaWAN.Join(); - break; - } - case DEVICE_STATE_SEND: // a send is scheduled to occur, usu. daily status - { - prepareTxFrame( DEVPORT ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; - break; - } + { + 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 = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; - break; - } + { + // Schedule next packet transmission + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; + break; + } case DEVICE_STATE_SLEEP: - { - if (accelWoke) { - if (IsLoRaMacNetworkJoined) { - if(prepareTxFrame(APPPORT)) { - LoRaWAN.Send(); - } + { + if (accelWoke) { + if (IsLoRaMacNetworkJoined) { + if(prepareTxFrame(APPPORT)) { + LoRaWAN.send(); } - accelWoke = false; } - LoRaWAN.Sleep(); - Serial.println("LoRaWAN.Sleep() finished"); - break; + accelWoke = false; } + LoRaWAN.sleep(); + break; + } default: - { - DeviceState = DEVICE_STATE_INIT; - break; - } + { + deviceState = DEVICE_STATE_INIT; + break; + } } -} +} \ No newline at end of file diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWan_multicast/LoRaWan_multicast.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWan_multicast/LoRaWan_multicast.ino index 2d37e285..10edf9fd 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWan_multicast/LoRaWan_multicast.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWan_multicast/LoRaWan_multicast.ino @@ -1,7 +1,6 @@ #include "LoRaWan_APP.h" #include "Arduino.h" - /* * set LoraWan_RGB to Active,the RGB active in loraWan * RGB red means sending; @@ -11,20 +10,45 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=CLASS_C; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + + +MulticastParams_t mult1; +uint8_t mulNwkSKey[]={0x5c,0x1d,0xce,0x81,0xd8,0x19,0x40,0xb9,0xe0,0xfb,0x1e,0x07,0xdd,0x4d,0xd3,0x9c}; +uint8_t mulAppSKey[]={0x6b,0x5b,0x47,0x6f,0x73,0xb6,0xc3,0x98,0xc8,0x11,0xa8,0xd0,0xd9,0x9f,0x25,0xc7}; +uint32_t multicastAddress=0x00638f9e; + +/*LoraWan region, select in arduino IDE tools*/ +LoRaMacRegion_t loraWanRegion = ACTIVE_REGION; + +/*only Class C support malticast*/ +DeviceClass_t loraWanClass = CLASS_C; + +/*the application data transmission duty cycle. value in [ms].*/ +uint32_t appTxDutyCycle = 15000; + /*OTAA or ABP*/ -bool OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -45,37 +69,35 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { - AppDataSize = 4;//AppDataSize max value is 64 - AppData[0] = 0x00; - AppData[1] = 0x01; - AppData[2] = 0x02; - AppData[3] = 0x03; + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ + appDataSize = 4; + appData[0] = 0x00; + appData[1] = 0x01; + appData[2] = 0x02; + appData[3] = 0x03; } -MulticastParams_t mult1; -uint8_t mulNwkSKey[]={0x5c,0x1d,0xce,0x81,0xd8,0x19,0x40,0xb9,0xe0,0xfb,0x1e,0x07,0xdd,0x4d,0xd3,0x9c}; -uint8_t mulAppSKey[]={0x6b,0x5b,0x47,0x6f,0x73,0xb6,0xc3,0x98,0xc8,0x11,0xa8,0xd0,0xd9,0x9f,0x25,0xc7}; -uint32_t multicastAddress=0x00638f9e; - void setup() { - BoardInitMcu(); + boardInitMcu(); Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); + + //add multicast mult1.Address=multicastAddress; for(int i=0;i<16;i++) { @@ -87,48 +109,48 @@ void setup() { void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { #if(AT_SUPPORT) - getDevParam(); + getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan mutlcast start! \r\n"); - LoRaWAN.Init(CLASS,ACTIVE_REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } } + diff --git a/libraries/LoRa/examples/LoRaWAN/LoRaWan_user_AT/LoRaWan_user_AT.ino b/libraries/LoRa/examples/LoRaWAN/LoRaWan_user_AT/LoRaWan_user_AT.ino index 1da43dc4..f68ffb3f 100644 --- a/libraries/LoRa/examples/LoRaWAN/LoRaWan_user_AT/LoRaWan_user_AT.ino +++ b/libraries/LoRa/examples/LoRaWAN/LoRaWan_user_AT/LoRaWan_user_AT.ino @@ -10,19 +10,39 @@ * RGB green means received done; */ -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; +/* OTAA para*/ +uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 }; +uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 }; + +/* ABP para*/ +uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 }; +uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 }; +uint32_t devAddr = ( uint32_t )0x007e6ae1; + +/*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 OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; +bool overTheAirActivation = LORAWAN_NETMODE; + /*ADR enable*/ -bool LORAWAN_ADR_ON = LORAWAN_ADR; +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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; +bool keepNet = LORAWAN_NET_RESERVE; /* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; +bool isTxConfirmed = LORAWAN_UPLINKMODE; + +/* Application port */ +uint8_t appPort = 2; /*! * Number of trials to transmit the frame, if the LoRaMAC layer did not * receive an acknowledgment. The MAC performs a datarate adaptation, @@ -43,22 +63,23 @@ bool IsTxConfirmed = LORAWAN_UPLINKMODE; * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease * the datarate, in case the LoRaMAC layer did not receive an acknowledgment */ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; +uint8_t confirmedNbTrials = 8; /* Prepares the payload of the frame */ -static void PrepareTxFrame( uint8_t port ) +static void prepareTxFrame( uint8_t port ) { - AppDataSize = 4;//AppDataSize max value is 64 - AppData[0] = 0x00; - AppData[1] = 0x01; - AppData[2] = 0x02; - AppData[3] = 0x03; + /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h". + *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE. + *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure. + *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF. + *for example, if use REGION_CN470, + *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h". + */ + appDataSize = 4; + appData[0] = 0x00; + appData[1] = 0x01; + appData[2] = 0x02; + appData[3] = 0x03; } /* function for user AT command @@ -69,7 +90,7 @@ static void PrepareTxFrame( uint8_t port ) * XXX is the para * cmd and YYYY is the para * content * you can test with 'AT+test=abcd' */ -bool AT_user_check(char * cmd, char * content) +bool checkUserAt(char * cmd, char * content) { if(strcmp(cmd,"test")==0) { @@ -84,59 +105,59 @@ bool AT_user_check(char * cmd, char * content) } void setup() { - BoardInitMcu(); - Serial.begin(115200); + boardInitMcu(); + Serial.begin(115200); #if(AT_SUPPORT) - Enable_AT(); + enableAt(); #endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); + deviceState = DEVICE_STATE_INIT; + LoRaWAN.ifskipjoin(); } void loop() { - switch( DeviceState ) + switch( deviceState ) { case DEVICE_STATE_INIT: { #if(AT_SUPPORT) - getDevParam(); + getDevParam(); #endif printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - DeviceState = DEVICE_STATE_JOIN; + LoRaWAN.init(loraWanClass,loraWanRegion); + deviceState = DEVICE_STATE_JOIN; break; } case DEVICE_STATE_JOIN: { - LoRaWAN.Join(); + LoRaWAN.join(); break; } case DEVICE_STATE_SEND: { - PrepareTxFrame( AppPort ); - LoRaWAN.Send(); - DeviceState = DEVICE_STATE_CYCLE; + prepareTxFrame( appPort ); + LoRaWAN.send(); + deviceState = DEVICE_STATE_CYCLE; break; } case DEVICE_STATE_CYCLE: { // Schedule next packet transmission - TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( 0, APP_TX_DUTYCYCLE_RND ); - LoRaWAN.Cycle(TxDutyCycleTime); - DeviceState = DEVICE_STATE_SLEEP; + txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND ); + LoRaWAN.cycle(txDutyCycleTime); + deviceState = DEVICE_STATE_SLEEP; break; } case DEVICE_STATE_SLEEP: { - LoRaWAN.Sleep(); + LoRaWAN.sleep(); break; } default: { - DeviceState = DEVICE_STATE_INIT; + deviceState = DEVICE_STATE_INIT; break; } } -} \ No newline at end of file +} + diff --git a/libraries/LoRa/examples/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino b/libraries/LoRa/examples/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino deleted file mode 100644 index 2a041ab3..00000000 --- a/libraries/LoRa/examples/LoRaWAN_Sensors/LoRaWan_HDC1080/LoRaWan_HDC1080.ino +++ /dev/null @@ -1,155 +0,0 @@ -#include "LoRaWan_APP.h" -#include "Arduino.h" -#include -#include "HDC1080.h" - -/* - * set LoraWan_RGB to Active,the RGB active in loraWan - * RGB red means sending; - * RGB purple means joined done; - * RGB blue means RxWindow1; - * RGB yellow means RxWindow2; - * RGB green means received done; - */ - -/*LoraWan Class*/ -DeviceClass_t CLASS=LORAWAN_CLASS; -/*OTAA or ABP*/ -bool OVER_THE_AIR_ACTIVATION = LORAWAN_NETMODE; -/*ADR enable*/ -bool LORAWAN_ADR_ON = 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; -/*LoraWan REGION*/ -LoRaMacRegion_t REGION = ACTIVE_REGION; - -/* Indicates if the node is sending confirmed or unconfirmed messages */ -bool IsTxConfirmed = LORAWAN_UPLINKMODE; - -/*! -* Number of trials to transmit the frame, if the LoRaMAC layer did not -* receive an acknowledgment. The MAC performs a datarate adaptation, -* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according -* to the following table: -* -* Transmission nb | Data Rate -* ----------------|----------- -* 1 (first) | DR -* 2 | DR -* 3 | max(DR-1,0) -* 4 | max(DR-1,0) -* 5 | max(DR-2,0) -* 6 | max(DR-2,0) -* 7 | max(DR-3,0) -* 8 | max(DR-3,0) -* -* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease -* the datarate, in case the LoRaMAC layer did not receive an acknowledgment -*/ -uint8_t ConfirmedNbTrials = 8; - -/* Application port */ -uint8_t AppPort = 2; - -/*the application data transmission duty cycle. value in [ms].*/ -uint32_t APP_TX_DUTYCYCLE = 15000; - -/*! - * \brief Prepares the payload of the frame - */ -HDC1080 hdc1080; -static void PrepareTxFrame( uint8_t port ) -{ - pinMode(Vext,OUTPUT); - digitalWrite(Vext,LOW); - hdc1080.begin(0x40); - float Temperature = (float)(hdc1080.readTemperature()); - float Humidity = (float)(hdc1080.readHumidity()); - hdc1080.end(); - digitalWrite(Vext,HIGH); - uint16_t BatteryVoltage = GetBatteryVoltage(); - unsigned char *puc; - - puc = (unsigned char *)(&Temperature); - AppDataSize = 10;//AppDataSize max value is 64 - AppData[0] = puc[0]; - AppData[1] = puc[1]; - AppData[2] = puc[2]; - AppData[3] = puc[3]; - - puc = (unsigned char *)(&Humidity); - AppData[4] = puc[0]; - AppData[5] = puc[1]; - AppData[6] = puc[2]; - AppData[7] = puc[3]; - - AppData[8] = (uint8_t)(BatteryVoltage>>8); - AppData[9] = (uint8_t)BatteryVoltage; - - Serial.print("T="); - Serial.print(Temperature); - Serial.print("C, RH="); - Serial.print(Humidity); - Serial.print("%,"); - Serial.print("BatteryVoltage:"); - Serial.println(BatteryVoltage); -} - - -void setup() { - BoardInitMcu(); - Serial.begin(115200); -#if(AT_SUPPORT) - Enable_AT(); -#endif - DeviceState = DEVICE_STATE_INIT; - LoRaWAN.Ifskipjoin(); -} - -void loop() -{ - switch( DeviceState ) - { - case DEVICE_STATE_INIT: - { -#if(AT_SUPPORT) - getDevParam(); -#endif - printDevParam(); - Serial.printf("LoRaWan Class%X start! \r\n",CLASS+10); - LoRaWAN.Init(CLASS,REGION); - 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 = APP_TX_DUTYCYCLE + 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; - } - } -} diff --git a/libraries/LoRa/src/Commissioning.h b/libraries/LoRa/src/Commissioning.h deleted file mode 100644 index da809170..00000000 --- a/libraries/LoRa/src/Commissioning.h +++ /dev/null @@ -1,81 +0,0 @@ -/*! - * \file Commissioning.h - * - * \brief End device commissioning parameters - * - * \copyright Revised BSD License, see section \ref LICENSE. - * - * \code - * ______ _ - * / _____) _ | | - * ( (____ _____ ____ _| |_ _____ ____| |__ - * \____ \| ___ | (_ _) ___ |/ ___) _ \ - * _____) ) ____| | | || |_| ____( (___| | | | - * (______/|_____)_|_|_| \__)_____)\____)_| |_| - * (C)2013-2017 Semtech - * - * \endcode - * - * \author Miguel Luis ( Semtech ) - * - * \author Gregory Cristian ( Semtech ) - */ -#ifndef __LORA_COMMISSIONING_H__ -#define __LORA_COMMISSIONING_H__ - -#include "LoRaMac.h" - -/*! - * User application data buffer size - */ -#define LORAWAN_APP_DATA_MAX_SIZE 64 //if use AT mode, don't modify this value or may run dead - -/*! - * Indicates if the end-device is to be connected to a private or public network - */ -#define LORAWAN_PUBLIC_NETWORK true - -/*! - * Mote device IEEE EUI (big endian) - * - * \remark In this application the value is automatically generated by calling - * BoardGetUniqueId function - */ -#define LORAWAN_DEVICE_EUI { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02} - -/*! - * Application IEEE EUI (big endian) - */ -#define LORAWAN_APPLICATION_EUI { 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x04 } - -/*! - * AES encryption/decryption cipher application key - */ -#define LORAWAN_APPLICATION_KEY { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 } - -/*! - * Current network ID - */ -#define LORAWAN_NETWORK_ID ( uint32_t )0 - -/*! - * Device address on the network (big endian) - * - * \remark In this application the value is automatically generated using - * a pseudo random generator seeded with a value derived from - * BoardUniqueId value if LORAWAN_DEVICE_ADDRESS is set to 0 - */ -#define LORAWAN_DEVICE_ADDRESS ( uint32_t )0x007e6ae1 - -/*! - * AES encryption/decryption cipher network session key - */ -#define LORAWAN_NWKSKEY { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 } - -/*! - * AES encryption/decryption cipher application session key - */ -#define LORAWAN_APPSKEY { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 } - - -#endif // __LORA_COMMISSIONING_H__ diff --git a/libraries/LoRa/src/LoRaWan_APP.cpp b/libraries/LoRa/src/LoRaWan_APP.cpp index 6df4d237..fbf333ef 100644 --- a/libraries/LoRa/src/LoRaWan_APP.cpp +++ b/libraries/LoRa/src/LoRaWan_APP.cpp @@ -17,30 +17,21 @@ Adafruit_NeoPixel pixels(1, RGB, NEO_GRB + NEO_KHZ800); */ #define LORAWAN_DEFAULT_DATARATE DR_5 -uint8_t DevEui[] = LORAWAN_DEVICE_EUI; -uint8_t AppEui[] = LORAWAN_APPLICATION_EUI; -uint8_t AppKey[] = LORAWAN_APPLICATION_KEY; - -uint8_t NwkSKey[] = LORAWAN_NWKSKEY; -uint8_t AppSKey[] = LORAWAN_APPSKEY; -uint32_t DevAddr = LORAWAN_DEVICE_ADDRESS; - - /*! * User application data size */ -uint8_t AppDataSize = 4; +uint8_t appDataSize = 4; /*! * User application data */ -uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE]; +uint8_t appData[LORAWAN_APP_DATA_MAX_SIZE]; /*! * Defines the application data transmission duty cycle */ -uint32_t TxDutyCycleTime ; +uint32_t txDutyCycleTime ; /*! * Timer to handle the application data transmission duty cycle @@ -51,22 +42,21 @@ static TimerEvent_t TxNextPacketTimer; * PassthroughMode mode enable/disable. don't modify it here. * when use PassthroughMode, set it true in app.ino , Reference the example PassthroughMode.ino */ -bool PassthroughMode = false; +bool passthroughMode = false; /*! * when use PassthroughMode, Mode_LoraWan to set use lora or lorawan mode . don't modify it here. * it is used to set mode lora/lorawan in PassthroughMode. */ -bool Mode_LoraWan = true; - +bool modeLoraWan = true; /*! * Indicates if a new packet can be sent */ -static bool NextTx = true; +static bool nextTx = true; -enum eDeviceState_LoraWan DeviceState; +enum eDeviceState_LoraWan deviceState; /*! @@ -79,7 +69,7 @@ bool SendFrame( void ) McpsReq_t mcpsReq; LoRaMacTxInfo_t txInfo; - if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK ) + if( LoRaMacQueryTxPossible( appDataSize, &txInfo ) != LORAMAC_STATUS_OK ) { // Send empty frame in order to flush MAC commands mcpsReq.Type = MCPS_UNCONFIRMED; @@ -89,23 +79,23 @@ bool SendFrame( void ) } else { - if( IsTxConfirmed == false ) + if( isTxConfirmed == false ) { printf("unconfirmed uplink sending ...\r\n"); mcpsReq.Type = MCPS_UNCONFIRMED; - mcpsReq.Req.Unconfirmed.fPort = AppPort; - mcpsReq.Req.Unconfirmed.fBuffer = AppData; - mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize; + mcpsReq.Req.Unconfirmed.fPort = appPort; + mcpsReq.Req.Unconfirmed.fBuffer = appData; + mcpsReq.Req.Unconfirmed.fBufferSize = appDataSize; mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE; } else { printf("confirmed uplink sending ...\r\n"); mcpsReq.Type = MCPS_CONFIRMED; - mcpsReq.Req.Confirmed.fPort = AppPort; - mcpsReq.Req.Confirmed.fBuffer = AppData; - mcpsReq.Req.Confirmed.fBufferSize = AppDataSize; - mcpsReq.Req.Confirmed.NbTrials = ConfirmedNbTrials; + mcpsReq.Req.Confirmed.fPort = appPort; + mcpsReq.Req.Confirmed.fBuffer = appData; + mcpsReq.Req.Confirmed.fBufferSize = appDataSize; + mcpsReq.Req.Confirmed.NbTrials = confirmedNbTrials; mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE; } } @@ -133,25 +123,26 @@ static void OnTxNextPacketTimerEvent( void ) { if( mibReq.Param.IsNetworkJoined == true ) { - DeviceState = DEVICE_STATE_SEND; - NextTx = true; + deviceState = DEVICE_STATE_SEND; + nextTx = true; } else { // Network not joined yet. Try to join again MlmeReq_t mlmeReq; mlmeReq.Type = MLME_JOIN; - mlmeReq.Req.Join.DevEui = DevEui; - mlmeReq.Req.Join.AppEui = AppEui; - mlmeReq.Req.Join.AppKey = AppKey; + mlmeReq.Req.Join.DevEui = devEui; + mlmeReq.Req.Join.AppEui = appEui; + mlmeReq.Req.Join.AppKey = appKey; + mlmeReq.Req.Join.NbTrials = 1; if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK ) { - DeviceState = DEVICE_STATE_SLEEP; + deviceState = DEVICE_STATE_SLEEP; } else { - DeviceState = DEVICE_STATE_CYCLE; + deviceState = DEVICE_STATE_CYCLE; } } } @@ -191,11 +182,11 @@ static void McpsConfirm( McpsConfirm_t *mcpsConfirm ) break; } } - NextTx = true; + nextTx = true; } #if(LoraWan_RGB==1) -void RGB_ON(uint32_t color,uint32_t time) +void turnOnRGB(uint32_t color,uint32_t time) { uint8_t red,green,blue; red=(uint8_t)(color>>16); @@ -214,15 +205,15 @@ void RGB_ON(uint32_t color,uint32_t time) } } -void RGB_OFF(void) +void turnOffRGB(void) { - RGB_ON(0,0); + turnOnRGB(0,0); digitalWrite(Vext,HIGH); } #endif /* get the BatteryVoltage in mV. */ -uint16_t GetBatteryVoltage(void) +uint16_t getBatteryVoltage(void) { pinMode(ADC_CTL,OUTPUT); digitalWrite(ADC_CTL,LOW); @@ -232,7 +223,7 @@ uint16_t GetBatteryVoltage(void) } -void __attribute__((weak)) DownLinkDataHandle(McpsIndication_t *mcpsIndication) +void __attribute__((weak)) downLinkDataHandle(McpsIndication_t *mcpsIndication) { printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port); printf("+REV DATA:"); @@ -260,8 +251,8 @@ static void McpsIndication( McpsIndication_t *mcpsIndication ) printf( "receive data: rssi = %d, snr = %d, datarate = %d\r\n", mcpsIndication->Rssi, (int)mcpsIndication->Snr,(int)mcpsIndication->RxDatarate); #if (LoraWan_RGB==1) - RGB_ON(COLOR_RECEIVED, 200); - RGB_OFF(); + turnOnRGB(COLOR_RECEIVED, 200); + turnOffRGB(); #endif switch( mcpsIndication->McpsIndication ) @@ -303,7 +294,7 @@ static void McpsIndication( McpsIndication_t *mcpsIndication ) // Check RxSlot if( mcpsIndication->RxData == true ) { - DownLinkDataHandle(mcpsIndication); + downLinkDataHandle(mcpsIndication); } } @@ -323,22 +314,22 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm ) { #if (LoraWan_RGB==1) - RGB_ON(COLOR_JOINED,500); - RGB_OFF(); + turnOnRGB(COLOR_JOINED,500); + turnOffRGB(); #endif printf("joined\r\n"); //in PassthroughMode,do nothing while joined - if(PassthroughMode == false) + if(passthroughMode == false) { // Status is OK, node has joined the network - DeviceState = DEVICE_STATE_SEND; + deviceState = DEVICE_STATE_SEND; } } else { uint32_t rejoin_delay = 30000; - printf("join failed\r\n"); + printf("join failed, join again at 30s later\r\n"); TimerSetValue( &TxNextPacketTimer, rejoin_delay ); TimerStart( &TxNextPacketTimer ); } @@ -356,7 +347,7 @@ static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm ) default: break; } - NextTx = true; + nextTx = true; } /*! @@ -419,15 +410,50 @@ static void lwan_dev_params_update( void ) uint8_t BoardGetBatteryLevel() { - int8 batlevel = ((GetBatteryVoltage()-3.7)/(4.2-3.7))*100; + int8 batlevel = ((getBatteryVoltage()-3.7)/(4.2-3.7))*100; return batlevel; } LoRaMacPrimitives_t LoRaMacPrimitive; LoRaMacCallback_t LoRaMacCallback; -void LoRaWanClass::Init(DeviceClass_t CLASS,LoRaMacRegion_t REGION) +void LoRaWanClass::init(DeviceClass_t lorawanClass,LoRaMacRegion_t region) { + Serial.print("\r\nLoRaWAN "); + switch(region) + { + case LORAMAC_REGION_AS923: + Serial.print("AS923"); + break; + case LORAMAC_REGION_AU915: + Serial.print("AU915"); + break; + case LORAMAC_REGION_CN470: + Serial.print("CN470"); + break; + case LORAMAC_REGION_CN779: + Serial.print("CN779"); + break; + case LORAMAC_REGION_EU433: + Serial.print("EU433"); + break; + case LORAMAC_REGION_EU868: + Serial.print("EU868"); + break; + case LORAMAC_REGION_KR920: + Serial.print("KR920"); + break; + case LORAMAC_REGION_IN865: + Serial.print("IN865"); + break; + case LORAMAC_REGION_US915: + Serial.print("US915"); + break; + case LORAMAC_REGION_US915_HYBRID: + Serial.print("US915_HYBRID "); + break; + } + Serial.printf(" Class %X start!\r\n\r\n",loraWanClass+10); MibRequestConfirm_t mibReq; @@ -437,46 +463,45 @@ void LoRaWanClass::Init(DeviceClass_t CLASS,LoRaMacRegion_t REGION) LoRaMacPrimitive.MacMlmeIndication = MlmeIndication; LoRaMacCallback.GetBatteryLevel = BoardGetBatteryLevel; LoRaMacCallback.GetTemperatureLevel = NULL; - LoRaMacInitialization( &LoRaMacPrimitive, &LoRaMacCallback,REGION); + LoRaMacInitialization( &LoRaMacPrimitive, &LoRaMacCallback,region); TimerStop( &TxNextPacketTimer ); TimerInit( &TxNextPacketTimer, OnTxNextPacketTimerEvent ); mibReq.Type = MIB_ADR; - mibReq.Param.AdrEnable = LORAWAN_ADR_ON; + mibReq.Param.AdrEnable = loraWanAdr; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_PUBLIC_NETWORK; mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK; LoRaMacMibSetRequestConfirm( &mibReq ); - lwan_dev_params_update(); - DeviceState = DEVICE_STATE_JOIN; + deviceState = DEVICE_STATE_JOIN; } -extern "C" void GetNetInfo(void); - -void LoRaWanClass::Join() +void LoRaWanClass::join() { - if( OVER_THE_AIR_ACTIVATION ) + if( overTheAirActivation ) { - Serial.println("joining..."); + Serial.print("joining..."); MlmeReq_t mlmeReq; mlmeReq.Type = MLME_JOIN; - mlmeReq.Req.Join.DevEui = DevEui; - mlmeReq.Req.Join.AppEui = AppEui; - mlmeReq.Req.Join.AppKey = AppKey; + mlmeReq.Req.Join.DevEui = devEui; + mlmeReq.Req.Join.AppEui = appEui; + mlmeReq.Req.Join.AppKey = appKey; + mlmeReq.Req.Join.NbTrials = 1; + if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK ) { - DeviceState = DEVICE_STATE_SLEEP; + deviceState = DEVICE_STATE_SLEEP; } else { - DeviceState = DEVICE_STATE_CYCLE; + deviceState = DEVICE_STATE_CYCLE; } } else @@ -488,74 +513,62 @@ void LoRaWanClass::Join() LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_DEV_ADDR; - mibReq.Param.DevAddr = DevAddr; + mibReq.Param.DevAddr = devAddr; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_NWK_SKEY; - mibReq.Param.NwkSKey = NwkSKey; + mibReq.Param.NwkSKey = nwkSKey; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_APP_SKEY; - mibReq.Param.AppSKey = AppSKey; + mibReq.Param.AppSKey = appSKey; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_NETWORK_JOINED; mibReq.Param.IsNetworkJoined = true; LoRaMacMibSetRequestConfirm( &mibReq ); - DeviceState = DEVICE_STATE_SEND; + deviceState = DEVICE_STATE_SEND; } } -void LoRaWanClass::Send() +void LoRaWanClass::send() { - if( NextTx == true ) + if( nextTx == true ) { MibRequestConfirm_t mibReq; mibReq.Type = MIB_DEVICE_CLASS; LoRaMacMibGetRequestConfirm( &mibReq ); - - if(CLASS == CLASS_C) - { - if( mibReq.Param.Class!= CLASS_C ) - { - mibReq.Param.Class = CLASS_C; - LoRaMacMibSetRequestConfirm( &mibReq ); - } - } - if(CLASS == CLASS_A) + if(loraWanClass != mibReq.Param.Class) { - if( mibReq.Param.Class!= CLASS_A ) - { - mibReq.Param.Class = CLASS_A; - LoRaMacMibSetRequestConfirm( &mibReq ); - } + mibReq.Param.Class = loraWanClass; + LoRaMacMibSetRequestConfirm( &mibReq ); } - NextTx = SendFrame( ); + nextTx = SendFrame( ); } } -void LoRaWanClass::Cycle(uint32_t dutycycle) +void LoRaWanClass::cycle(uint32_t dutyCycle) { - TimerSetValue( &TxNextPacketTimer, dutycycle ); + TimerSetValue( &TxNextPacketTimer, dutyCycle ); TimerStart( &TxNextPacketTimer ); } -void LoRaWanClass::Sleep() +void LoRaWanClass::sleep() { - LowPower_Handler( ); + lowPowerHandler( ); // Process Radio IRQ Radio.IrqProcess( ); } -void LoRaWanClass::Ifskipjoin() +void LoRaWanClass::ifskipjoin() { //if saved net info is OK in lorawan mode, skip join. - if(CheckNetInfo()&&Mode_LoraWan){ + if(checkNetInfo()&&modeLoraWan){ Serial.println(); - if(PassthroughMode==false) + if(passthroughMode==false) { Serial.println("Wait 3s for user key to rejoin network"); uint16_t i=0; @@ -564,7 +577,7 @@ void LoRaWanClass::Ifskipjoin() { if(digitalRead(GPIO7)==LOW)//if user key down, rejoin network; { - NetInfoDisable(); + netInfoDisable(); pinMode(GPIO7,OUTPUT); digitalWrite(GPIO7,HIGH); return; @@ -579,23 +592,23 @@ void LoRaWanClass::Ifskipjoin() getDevParam(); #endif - Init(CLASS,REGION); - GetNetInfo(); - if(PassthroughMode==false){ + init(loraWanClass,loraWanRegion); + getNetInfo(); + if(passthroughMode==false){ Serial.println("User key not detected,Use reserved Net"); } else{ Serial.println("Use reserved Net"); } - if(PassthroughMode==false) + if(passthroughMode==false) { - int32_t temp=randr(0,APP_TX_DUTYCYCLE); + int32_t temp=randr(0,appTxDutyCycle); Serial.println(); Serial.printf("Next packet send %d ms later(random time from 0 to APP_TX_DUTYCYCLE)\r\n",temp); Serial.println(); - Cycle(temp);//send packet in a random time to avoid network congestion. + cycle(temp);//send packet in a random time to avoid network congestion. } - DeviceState = DEVICE_STATE_SLEEP; + deviceState = DEVICE_STATE_SLEEP; } } diff --git a/libraries/LoRa/src/LoRaWan_APP.h b/libraries/LoRa/src/LoRaWan_APP.h index e6a6930d..912a9e07 100644 --- a/libraries/LoRa/src/LoRaWan_APP.h +++ b/libraries/LoRa/src/LoRaWan_APP.h @@ -20,48 +20,52 @@ #include "AT_Command.h" #include - -extern uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t AppDataSize; -extern uint8_t AppPort; -extern uint32_t TxDutyCycleTime; -extern bool OVER_THE_AIR_ACTIVATION; -extern LoRaMacRegion_t REGION; -extern bool LORAWAN_ADR_ON; -extern bool IsTxConfirmed; -extern uint32_t APP_TX_DUTYCYCLE; -extern DeviceClass_t CLASS; -extern uint8_t AppPort; -extern bool PassthroughMode; -extern uint8_t ConfirmedNbTrials; -extern bool Mode_LoraWan; -extern bool KeepNet; - +extern uint8_t devEui[]; +extern uint8_t appEui[]; +extern uint8_t appKey[]; +extern uint8_t nwkSKey[]; +extern uint8_t appSKey[]; +extern uint32_t devAddr; +extern uint8_t appData[LORAWAN_APP_DATA_MAX_SIZE]; +extern uint8_t appDataSize; +extern uint8_t appPort; +extern uint32_t txDutyCycleTime; +extern bool overTheAirActivation; +extern LoRaMacRegion_t loraWanRegion; +extern bool loraWanAdr; +extern bool isTxConfirmed; +extern uint32_t appTxDutyCycle; +extern DeviceClass_t loraWanClass; +extern bool passthroughMode; +extern uint8_t confirmedNbTrials; +extern bool modeLoraWan; +extern bool keepNet; +extern bool IsLoRaMacNetworkJoined; /*! * Defines a random delay for application data transmission duty cycle. 1s, * value in [ms]. */ #define APP_TX_DUTYCYCLE_RND 1000 -extern enum eDeviceState_LoraWan DeviceState; +extern enum eDeviceState_LoraWan deviceState; class LoRaWanClass{ public: - void Init(DeviceClass_t CLASS,LoRaMacRegion_t REGION); - void Join(); - void Send(); - void Cycle(uint32_t dutycycle); - void Sleep(); - void Ifskipjoin(); + void init(DeviceClass_t lorawanClass,LoRaMacRegion_t region); + void join(); + void send(); + void cycle(uint32_t dutyCycle); + void sleep(); + void ifskipjoin(); }; extern "C" bool SendFrame( void ); -extern "C" void RGB_ON(uint32_t color,uint32_t time); -extern "C" void RGB_OFF(void); -extern "C" uint16_t GetBatteryVoltage(void); -extern "C" bool AT_user_check(char * cmd, char * content); -extern "C" void DownLinkDataHandle(McpsIndication_t *mcpsIndication); +extern "C" void turnOnRGB(uint32_t color,uint32_t time); +extern "C" void turnOffRGB(void); +extern "C" uint16_t getBatteryVoltage(void); +extern "C" bool checkUserAt(char * cmd, char * content); +extern "C" void downLinkDataHandle(McpsIndication_t *mcpsIndication); diff --git a/libraries/LoRa/src/LoRa_APP.cpp b/libraries/LoRa/src/LoRa_APP.cpp index 197c4e91..2675a7df 100644 --- a/libraries/LoRa/src/LoRa_APP.cpp +++ b/libraries/LoRa/src/LoRa_APP.cpp @@ -1,9 +1,9 @@ #include -enum eDeviceState_Lora DeviceState_lora; -extern uint8_t AppData[LORAWAN_APP_DATA_MAX_SIZE]; -extern uint8_t AppDataSize; +enum eDeviceState_Lora deviceState_lora; +extern uint8_t appData[LORAWAN_APP_DATA_MAX_SIZE]; +extern uint8_t appDataSize; //Tx Power uint8_t Lora_TXPW = 10; @@ -66,7 +66,7 @@ static void OnLoraRxTimeout( void ) } -void LoRaClass::Init(uint32_t freq, uint8_t power,uint32_t datarate) +void LoRaClass::init(uint32_t freq, uint8_t power,uint32_t datarate) { LoraEvents.TxDone = OnLoraTxDone; LoraEvents.TxTimeout = OnLoraTxTimeout; @@ -78,19 +78,19 @@ void LoRaClass::Init(uint32_t freq, uint8_t power,uint32_t datarate) Radio.SetRxConfig( MODEM_LORA, 0, datarate,1, 0, 8,0, false,0, true, 0, 0, false, true ); } -void LoRaClass::Send() +void LoRaClass::send() { - Radio.Send( AppData, AppDataSize ); + Radio.Send( appData, appDataSize ); } -void LoRaClass::Receive() +void LoRaClass::receive() { Radio.Rx(LoraRxTimeout); } -void LoRaClass::LOWPOWER() +void LoRaClass::lowpower() { - LowPower_Handler( ); + lowPowerHandler( ); // Process Radio IRQ Radio.IrqProcess( ); } diff --git a/libraries/LoRa/src/LoRa_APP.h b/libraries/LoRa/src/LoRa_APP.h index c06d112f..dd586cc5 100644 --- a/libraries/LoRa/src/LoRa_APP.h +++ b/libraries/LoRa/src/LoRa_APP.h @@ -19,7 +19,7 @@ #include "AT_Command.h" #include "Arduino.h" -extern enum eDeviceState_Lora DeviceState_lora; +extern enum eDeviceState_Lora deviceState_lora; extern uint8_t Lora_TXPW; extern uint32_t Lora_SF; extern uint32_t Lora_FREQ; @@ -28,10 +28,10 @@ extern bool PrintMode; class LoRaClass{ public: - void Init(uint32_t freq, uint8_t power,uint32_t datarate); - void Send(); - void Receive(); - void LOWPOWER(); + void init(uint32_t freq, uint8_t power,uint32_t datarate); + void send(); + void receive(); + void lowpower(); }; extern LoRaClass LoRa; diff --git a/libraries/SSD1306/examples/SSD1306DrawingDemo_I2C/SSD1306DrawingDemo_I2C.ino b/libraries/SSD1306/examples/SSD1306DrawingDemo_I2C/SSD1306DrawingDemo_I2C.ino index 37227dc9..f0d37a3f 100644 --- a/libraries/SSD1306/examples/SSD1306DrawingDemo_I2C/SSD1306DrawingDemo_I2C.ino +++ b/libraries/SSD1306/examples/SSD1306DrawingDemo_I2C/SSD1306DrawingDemo_I2C.ino @@ -1,5 +1,5 @@ #include -#include "SSD1306Wire.h" +#include "cubecell_SSD1306Wire.h" SSD1306Wire display(0x3c, SDA, SCL); @@ -183,4 +183,4 @@ void setup() { display.clear(); } -void loop() { } \ No newline at end of file +void loop() { } diff --git a/libraries/SSD1306/examples/SSD1306DrawingDemo_SPI/SSD1306DrawingDemo_SPI.ino b/libraries/SSD1306/examples/SSD1306DrawingDemo_SPI/SSD1306DrawingDemo_SPI.ino index 45968095..3e420ea3 100644 --- a/libraries/SSD1306/examples/SSD1306DrawingDemo_SPI/SSD1306DrawingDemo_SPI.ino +++ b/libraries/SSD1306/examples/SSD1306DrawingDemo_SPI/SSD1306DrawingDemo_SPI.ino @@ -1,4 +1,4 @@ -#include "SSD1306Spi.h" +#include "cubecell_SSD1306Spi.h" SSD1306Spi display(GPIO1, GPIO2, GPIO3);//RST,DC,CS @@ -183,4 +183,4 @@ void setup() { display.clear(); } -void loop() { } \ No newline at end of file +void loop() { } diff --git a/libraries/SSD1306/examples/SSD1306SimpleDemo_I2C/SSD1306SimpleDemo_I2C.ino b/libraries/SSD1306/examples/SSD1306SimpleDemo_I2C/SSD1306SimpleDemo_I2C.ino index 736f1c9d..e701db8c 100644 --- a/libraries/SSD1306/examples/SSD1306SimpleDemo_I2C/SSD1306SimpleDemo_I2C.ino +++ b/libraries/SSD1306/examples/SSD1306SimpleDemo_I2C/SSD1306SimpleDemo_I2C.ino @@ -1,6 +1,6 @@ // For a connection via I2C using the Arduino Wire include: #include -#include "SSD1306Wire.h" +#include "cubecell_SSD1306Wire.h" #include "images.h" SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL diff --git a/libraries/SSD1306/examples/SSD1306SimpleDemo_SPI/SSD1306SimpleDemo_SPI.ino b/libraries/SSD1306/examples/SSD1306SimpleDemo_SPI/SSD1306SimpleDemo_SPI.ino index ae2b89ca..43cd257e 100644 --- a/libraries/SSD1306/examples/SSD1306SimpleDemo_SPI/SSD1306SimpleDemo_SPI.ino +++ b/libraries/SSD1306/examples/SSD1306SimpleDemo_SPI/SSD1306SimpleDemo_SPI.ino @@ -1,4 +1,4 @@ -#include "SSD1306Spi.h" +#include "cubecell_SSD1306Spi.h" #include "images.h" diff --git a/libraries/SSD1306/examples/SSD1306UiDemo/SSD1306UiDemo.ino b/libraries/SSD1306/examples/SSD1306UiDemo/SSD1306UiDemo.ino index e4302e19..87400df7 100644 --- a/libraries/SSD1306/examples/SSD1306UiDemo/SSD1306UiDemo.ino +++ b/libraries/SSD1306/examples/SSD1306UiDemo/SSD1306UiDemo.ino @@ -1,10 +1,10 @@ -#include "SSD1306Spi.h" -#include "OLEDDisplayUi.h" +#include "cubecell_SSD1306Spi.h" +#include "cubecell_OLEDDisplayUi.h" #include "images.h" SSD1306Spi display(GPIO1, GPIO2, GPIO3);//RST,DC,CS -OLEDDisplayUi ui ( &display ); +OLEDDisplayUi ui( &display ); void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); diff --git a/libraries/SSD1306/examples/SSD1306UiDemo_I2C/SSD1306UiDemo_I2C.ino b/libraries/SSD1306/examples/SSD1306UiDemo_I2C/SSD1306UiDemo_I2C.ino index 59903ac4..8cf7c667 100644 --- a/libraries/SSD1306/examples/SSD1306UiDemo_I2C/SSD1306UiDemo_I2C.ino +++ b/libraries/SSD1306/examples/SSD1306UiDemo_I2C/SSD1306UiDemo_I2C.ino @@ -1,6 +1,6 @@ - #include - #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` -#include "OLEDDisplayUi.h" +#include +#include "cubecell_SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` +#include "cubecell_OLEDDisplayUi.h" #include "images.h" @@ -8,7 +8,7 @@ SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL -OLEDDisplayUi ui ( &display ); +OLEDDisplayUi ui( &display ); void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); @@ -141,4 +141,4 @@ void loop() { // time budget. delay(remainingTimeBudget); } -} \ No newline at end of file +} diff --git a/libraries/SSD1306/examples/SSD1306UiDemo_SPI/SSD1306UiDemo_SPI.ino b/libraries/SSD1306/examples/SSD1306UiDemo_SPI/SSD1306UiDemo_SPI.ino index 982ee1b1..dd528845 100644 --- a/libraries/SSD1306/examples/SSD1306UiDemo_SPI/SSD1306UiDemo_SPI.ino +++ b/libraries/SSD1306/examples/SSD1306UiDemo_SPI/SSD1306UiDemo_SPI.ino @@ -1,10 +1,10 @@ -#include "SSD1306Spi.h" -#include "OLEDDisplayUi.h" +#include "cubecell_SSD1306Spi.h" +#include "cubecell_OLEDDisplayUi.h" #include "images.h" SSD1306Spi display(GPIO1, GPIO2, GPIO3);//RST,DC,CS -OLEDDisplayUi ui ( &display ); +OLEDDisplayUi ui( &display ); void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); diff --git a/libraries/SSD1306/src/OLEDDisplay.cpp b/libraries/SSD1306/src/cubecell_OLEDDisplay.cpp similarity index 99% rename from libraries/SSD1306/src/OLEDDisplay.cpp rename to libraries/SSD1306/src/cubecell_OLEDDisplay.cpp index 78d43cee..cbe25a62 100644 --- a/libraries/SSD1306/src/OLEDDisplay.cpp +++ b/libraries/SSD1306/src/cubecell_OLEDDisplay.cpp @@ -1,4 +1,4 @@ -#include "OLEDDisplay.h" +#include OLEDDisplay::OLEDDisplay() { diff --git a/libraries/SSD1306/src/OLEDDisplay.h b/libraries/SSD1306/src/cubecell_OLEDDisplay.h similarity index 99% rename from libraries/SSD1306/src/OLEDDisplay.h rename to libraries/SSD1306/src/cubecell_OLEDDisplay.h index f88f4900..27979c10 100644 --- a/libraries/SSD1306/src/OLEDDisplay.h +++ b/libraries/SSD1306/src/cubecell_OLEDDisplay.h @@ -3,7 +3,7 @@ #include -#include "OLEDDisplayFonts.h" +#include //#define DEBUG_OLEDDISPLAY(...) Serial.printf( __VA_ARGS__ ) //#define DEBUG_OLEDDISPLAY(...) dprintf("%s", __VA_ARGS__ ) diff --git a/libraries/SSD1306/src/OLEDDisplayFonts.h b/libraries/SSD1306/src/cubecell_OLEDDisplayFonts.h similarity index 100% rename from libraries/SSD1306/src/OLEDDisplayFonts.h rename to libraries/SSD1306/src/cubecell_OLEDDisplayFonts.h diff --git a/libraries/SSD1306/src/OLEDDisplayUi.cpp b/libraries/SSD1306/src/cubecell_OLEDDisplayUi.cpp similarity index 99% rename from libraries/SSD1306/src/OLEDDisplayUi.cpp rename to libraries/SSD1306/src/cubecell_OLEDDisplayUi.cpp index f73ffbea..c25ac3f2 100644 --- a/libraries/SSD1306/src/OLEDDisplayUi.cpp +++ b/libraries/SSD1306/src/cubecell_OLEDDisplayUi.cpp @@ -1,4 +1,4 @@ -#include "OLEDDisplayUi.h" +#include void LoadingDrawDefault(OLEDDisplay *display, LoadingStage* stage, uint8_t progress) { display->setTextAlignment(TEXT_ALIGN_CENTER); diff --git a/libraries/SSD1306/src/OLEDDisplayUi.h b/libraries/SSD1306/src/cubecell_OLEDDisplayUi.h similarity index 99% rename from libraries/SSD1306/src/OLEDDisplayUi.h rename to libraries/SSD1306/src/cubecell_OLEDDisplayUi.h index 53d64532..25399f0a 100644 --- a/libraries/SSD1306/src/OLEDDisplayUi.h +++ b/libraries/SSD1306/src/cubecell_OLEDDisplayUi.h @@ -3,7 +3,7 @@ #include -#include "OLEDDisplay.h" +#include //#define DEBUG_OLEDDISPLAYUI(...) Serial.printf( __VA_ARGS__ ) diff --git a/libraries/SSD1306/src/SSD1306Spi.h b/libraries/SSD1306/src/cubecell_SSD1306Spi.h similarity index 98% rename from libraries/SSD1306/src/SSD1306Spi.h rename to libraries/SSD1306/src/cubecell_SSD1306Spi.h index 68a95efa..8d7648f5 100644 --- a/libraries/SSD1306/src/SSD1306Spi.h +++ b/libraries/SSD1306/src/cubecell_SSD1306Spi.h @@ -1,7 +1,7 @@ #ifndef SSD1306Spi_h #define SSD1306Spi_h -#include "OLEDDisplay.h" +#include #include #if F_CPU == 160000000L diff --git a/libraries/SSD1306/src/SSD1306Wire.h b/libraries/SSD1306/src/cubecell_SSD1306Wire.h similarity index 99% rename from libraries/SSD1306/src/SSD1306Wire.h rename to libraries/SSD1306/src/cubecell_SSD1306Wire.h index 4d855be4..69427332 100644 --- a/libraries/SSD1306/src/SSD1306Wire.h +++ b/libraries/SSD1306/src/cubecell_SSD1306Wire.h @@ -1,7 +1,7 @@ #ifndef SSD1306Wire_h #define SSD1306Wire_h -#include "OLEDDisplay.h" +#include #include