Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LoRaWAN-lib mbed lib_mpl3115a2 lib_mma8451q lib_gps SX1272Lib
Dependents: LoRaWAN-NAMote72-BVS-confirmed-tester-0-7v1_copy
LoRaWAN-NAMote72 Application Demo is a Class-A device example project using LoRaWAN-lib and SX1272Lib libraries.
This project is compliant with LoRaWAN V1.0.1 specification.
Comissioning.h (LoRaWAN Network Configuration)
The end-device can be activated in one of the two ways:
Over the Air (OTA) activation can be enabled as shown in the figure below.

The end-device must be configured with the following parameters:
LORAWAN_DEVICE_EUI(8 Bytes) : Fist 3 Bytes is the Organizationally Unique Identifier (OUI) followed by 5 bytes of unique ID. If not defined by user, then the firmware automatically assigns one to the end-deviceLORAWAN_APPLICATION_EUI(8 Bytes)LORAWAN_APPLICATION_KEY(or DEVKEY) (16 Bytes)

Activation by Personalization (ABP) can be enabled as shown in the figure below.

The end-device must be configured with the following parameters:
LORAWAN_DEVICE_ADDRESS(4 Bytes) : If not defined by user, then the firmware automatically assigns one to the end-deviceLORAWAN_NWKSKEY(16 Bytes)LORAWAN_APPSKEY(16 Bytes)

Config.h (LoRaWAN Communication Parameters)
- Mode of Operation : Hybrid
If the end-device needs to be configured to operate over 8-channels, then
Hybrid Modeneeds to be enabled
- Mode of Operation : Frequency Hop
If the end-device needs to be configured to operate over 64-channels, then
Hybrid Modeneeds to be disabled
- Delay between successive JOIN REQUESTs :
The delay between successive Join Requests (until the end-device joins the network) can be configured using the parameter
OVER_THE_AIR_ACTIVATION_DUTYCYCLE
- Inter-Frame Delay :
One can change the delay between each frame transmission using
APP_TX_DUTYCYCLEIt is advisable thatAPP_TX_DUTYCYCLEis greater than or equal to 3sec.
- Data Rate :
The data rate can be configured as per LoRaWAN specification using the paramter
LORAWAN_DEFAULT_DATARATE. The range of values are DR_0, DR_1, DR_2, DR_3 and DR_4
- Confirmed/Unconfirmed Messages :
The uplink message or payload can be chosen to be confirmed or unconfirmed using the parameter
LORAWAN_CONFIRMED_MSG_ON. When set to 1, the transmitted messages need to be confirmed with anACKby the network server in the subsequent RX window. When set to 0, noACKis requested.
- ADR ON/OFF :
The ADR can be enabled or disabled using the parameter
LORAWAN_ADR_ON. When set to 1, ADR is enabled and disabled when set to 0.
- Application Port :
The application port can be set using parameter
LORAWAN_APP_PORT.
- Payload Length :
The lenght of the payload (in bytes) to be transmitted can be configured using
LORAWAN_APP_DATA_SIZE
- Transmit Power :
The transmit power can be configured using
LORAWAN_TX_POWER(LoRaMAC verifies if the set power is compliant with the LoRaWAN spec and FCC guidelines)
Main.cpp (Device State Machine)
The end-device state machine is defined.
- Initial State : Device is initialized.
- Join State : For OTA, Join Request is transmitted to the network until Join Accept is received by the end-device. Join event function is called that sets Red LED ON.
- Send State : Transmit payload frame is prepared. Tx event is called that blinks the Red LED indicating uplink transmission.
- Cycle State : Next packet transmission is scheduled
LoRaEventProc.cpp (Events and On-board Application)
Define events during Join, Tx & Rx. Prepare TX packet by appending with appropriate application data.

- PrepareLoRaFrame(uint8_t port ) :
Prepare LoRa payload frame with on-board application data such as GPS, Temperature, Battery, etc. LoRa.ApplicationCall(AppType ) calls application AppType defined in
LoRaApp.cpp. AppType is defined inLoRaApp.h

LoRaApp.cpp
User-defined applications such as GPS, Temp, Accelerometer, LED indications etc. Event based actions such as LED blink on Tx, LED toggle on downlink etc

LoRaDeviceStateProc.cpp
Process function calls corresponding to different Device states

LoRaMacLayerService.cpp
Define MAC Layer Services: MLME & MCPS
Serial Terminal Display
By using a serial port connection using applications such as teraterm or putty, one can view the status of the End-Device. Once the End-Device Joins the network, transmission parameters such as payload data, application port, message type etc. are displayed on the terminal.

Default Application Payload
This application defaults to sending uplink data to logical port 5. The application payload consists of:
Sample Application Payload Calculation for Longitude/Latitude
Payload => 00 19 F6 352BBA A94C20 FFFF
Temperature Calculation
19H => 2510
Temp = 25/2 = 12.5 oC
Battery Level
FFH => 100 %
F6H => 96.5 %
Longitude Calculation
longitude = A94C20H => 1109507210
longitudinal coordinate = -360 + (longitude10 x 180/(223))
longitudinal coordinate = -121.93
Latitude Calculation
latitude = 352BBAH = 348460210
latitude coordinate = (latitude10 x 90/(223-1))
latitude coordinate = 37.39
Revision 5:6ffeac53b7cb, committed 2016-06-08
- Comitter:
- ubhat
- Date:
- Wed Jun 08 01:40:42 2016 +0000
- Parent:
- 4:7a3ceb1ce02c
- Child:
- 6:f8194e691dd4
- Commit message:
- Change state machine flow in main.cpp
Changed in this revision
--- a/app/Common.h Thu May 19 18:40:59 2016 +0000 +++ b/app/Common.h Wed Jun 08 01:40:42 2016 +0000 @@ -52,6 +52,8 @@ extern uint8_t IsTxConfirmed; // Indicates if the node is sending confirmed or unconfirmed messages +extern bool IsTxIntUpdate; // Indicates if a new transmit interrupt can be set + extern bool NextTx; // Indicates if a new packet can be sent extern bool IsNetworkJoinedStatusUpdate; // Indicates if the MAC layer network join status has changed.
--- a/app/Config.h Thu May 19 18:40:59 2016 +0000
+++ b/app/Config.h Wed Jun 08 01:40:42 2016 +0000
@@ -36,17 +36,6 @@
#define OVER_THE_AIR_ACTIVATION_DUTYCYCLE 5000000 // value in us
/*!
- * Defines the application data transmission periodicity. It is the time between RX1/RX2 and next TX
- */
-#define APP_TX_DUTYCYCLE 5000000 // value in us
-
-/*!
- * Default mote datarate
- * \remark DR_0 : 980 bps; DR_1 : 1760 bps; DR_2 : 3125 bps; DR_3 : 5470 bps; DR_4 : 12500 bps
- */
-#define LORAWAN_DEFAULT_DATARATE DR_0
-
-/*!
* LoRaWAN confirmed messages
* \remark 1 : Confirmed messages enabled. Must receive ACK from network server
0 : Confirmed messages disabled.
@@ -63,12 +52,7 @@
/*!
* LoRaWAN application port
*/
-#define LORAWAN_APP_PORT 5
-
-/*!
- * User application data buffer size
- */
-#define LORAWAN_APP_DATA_SIZE 11
+#define LORAWAN_APP_PORT 7
/*!
* LoRaWAN User defined Tx Power
@@ -77,4 +61,73 @@
*/
#define LORAWAN_TX_POWER TX_POWER_20_DBM
-#endif // __LORA_CONFIG_H__
\ No newline at end of file
+#if ( LORAWAN_APP_PORT == 5)
+/*====================================================
+ US01 GPS APPLICATION DEMO (PORT 5)
+====================================================*/
+
+/*!
+ * Defines the application data transmission periodicity. It is the time between RX1/RX2 and next TX
+ */
+#define APP_TX_DUTYCYCLE 5000000 // value in us
+
+/*!
+ * Default mote datarate
+ * \remark DR_0 : 980 bps; DR_1 : 1760 bps; DR_2 : 3125 bps; DR_3 : 5470 bps; DR_4 : 12500 bps
+ */
+#define LORAWAN_DEFAULT_DATARATE DR_0
+
+/*!
+ * User application data buffer size
+ */
+#define LORAWAN_APP_DATA_SIZE 11
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+#elif ( LORAWAN_APP_PORT == 6)
+/*====================================================
+ SENET M2X DEMO (PORT 6)
+====================================================*/
+
+/*!
+ * Defines the application data transmission periodicity. It is the time between RX1/RX2 and next TX
+ */
+#define APP_TX_DUTYCYCLE 10000000 // value in us
+
+/*!
+ * Default mote datarate
+ * \remark DR_0 : 980 bps; DR_1 : 1760 bps; DR_2 : 3125 bps; DR_3 : 5470 bps; DR_4 : 12500 bps
+ */
+#define LORAWAN_DEFAULT_DATARATE DR_0
+
+/*!
+ * User application data buffer size
+ */
+#define LORAWAN_APP_DATA_SIZE 2
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+#elif ( LORAWAN_APP_PORT == 7)
+/*====================================================
+ SENET GPS DEMO (PORT 7)
+====================================================*/
+
+/*!
+ * Defines the application data transmission periodicity. It is the time between RX1/RX2 and next TX
+ */
+#define APP_TX_DUTYCYCLE 5000000 // value in us
+
+/*!
+ * Default mote datarate
+ * \remark DR_0 : 980 bps; DR_1 : 1760 bps; DR_2 : 3125 bps; DR_3 : 5470 bps; DR_4 : 12500 bps
+ */
+#define LORAWAN_DEFAULT_DATARATE DR_0
+
+/*!
+ * User application data buffer size
+ */
+#define LORAWAN_APP_DATA_SIZE 11
+
+#endif
+
+#endif // __LORA_CONFIG_H__
--- a/app/LoRaDeviceStateProc.h Thu May 19 18:40:59 2016 +0000
+++ b/app/LoRaDeviceStateProc.h Wed Jun 08 01:40:42 2016 +0000
@@ -64,7 +64,6 @@
DEVICE_STATE_INIT,
DEVICE_STATE_JOIN,
DEVICE_STATE_SEND,
- DEVICE_STATE_CYCLE,
DEVICE_STATE_SLEEP
};
--- a/app/LoRaEventProc.cpp Thu May 19 18:40:59 2016 +0000
+++ b/app/LoRaEventProc.cpp Wed Jun 08 01:40:42 2016 +0000
@@ -16,6 +16,11 @@
#include "LoRaEventProc.h"
+/*!
+ * Defines the application data transmission duty cycle
+ */
+uint32_t TxDutyCycleTime = APP_TX_DUTYCYCLE;
+
bool AppLed = 0;
/*!
@@ -120,6 +125,73 @@
}
}
+
+/*!
+ * \brief Sets Interrupt for next payload transmission
+ */
+void InitNextTxInterrupt( uint8_t port )
+{
+ switch( port )
+ {
+ /* GPS Application Demo
+ Set Timer interrupt for next uplink
+ */
+ case 5:
+ {
+ }
+
+ /* Senet + M2X demo
+ Set Timer interrupt for next uplink
+ */
+ case 6:
+ {
+
+ }
+
+ /* Senet GPS Demo
+ Set Timer interrupt for next uplink
+ */
+ case 7:
+ {
+ // Schedule next packet transmission
+ TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
+ TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
+ TimerStart( &TxNextPacketTimer );
+ break;
+ }
+
+ /* Push Button Demo
+ Send Packet Immedietly
+ */
+ case 11:
+ {
+ DeviceState = DEVICE_STATE_SEND;
+ NextTx = true;
+ break;
+ }
+
+ /* Compliance Test
+ Set Timer interrupt for next uplink
+ */
+ case 224:
+ {
+ // Schedule next packet transmission
+ TimerSetValue( &TxNextPacketTimer, COMPLIANCE_TX_DUTYCYCLE );
+ TimerStart( &TxNextPacketTimer );
+ break;
+ }
+
+ default:
+ {
+ // Schedule next packet transmission
+ TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
+ TimerStart( &TxNextPacketTimer );
+ break;
+ }
+ }
+
+}
+
/*!
* \brief What to do during JOIN process ? blink/toggle LED etc.
*/
--- a/app/LoRaEventProc.h Thu May 19 18:40:59 2016 +0000 +++ b/app/LoRaEventProc.h Wed Jun 08 01:40:42 2016 +0000 @@ -21,6 +21,8 @@ #include "LoRaApp.h" #include "LoRaDeviceStateProc.h" +#define APP_TX_DUTYCYCLE_RND 1000000 + /*! * \brief Prepares the payload of the frame specific to the application port * @@ -29,6 +31,11 @@ void PrepareLoRaFrame( uint8_t port ); /*! + * \brief Prepares the payload of the frame based on application port + */ +void InitNextTxInterrupt( uint8_t port ); + +/*! * \brief Define action during the Network Join process: Blink, Toggle or Set LED ON */ void JoinEvent( void );
--- a/app/LoRaMacLayerService.cpp Thu May 19 18:40:59 2016 +0000
+++ b/app/LoRaMacLayerService.cpp Wed Jun 08 01:40:42 2016 +0000
@@ -55,9 +55,7 @@
LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter;
LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower;
- DeviceState = DEVICE_STATE_CYCLE;
-
- IsTxUpdate = true;
+ IsTxIntUpdate = true;
}
/*!
@@ -191,5 +189,9 @@
}
}
- DeviceState = DEVICE_STATE_CYCLE;
+ // Schedule next packet transmission
+ TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE );
+ TimerStart( &TxNextPacketTimer );
+
+ DeviceState = DEVICE_STATE_SLEEP;
}
\ No newline at end of file
--- a/app/main.cpp Thu May 19 18:40:59 2016 +0000
+++ b/app/main.cpp Wed Jun 08 01:40:42 2016 +0000
@@ -28,7 +28,6 @@
* Defines a random delay for application data transmission duty cycle. 1s,
* value in [us].
*/
-#define APP_TX_DUTYCYCLE_RND 1000000
#if( OVER_THE_AIR_ACTIVATION != 0 )
@@ -75,16 +74,16 @@
uint8_t IsTxConfirmed = LORAWAN_CONFIRMED_MSG_ON;
/*!
- * Defines the application data transmission duty cycle
- */
-static uint32_t TxDutyCycleTime;
-
-/*!
* Timer to handle the application data transmission duty cycle
*/
TimerEvent_t TxNextPacketTimer;
/*!
+ * Indicates if a new transmit interrupt can be set
+ */
+bool IsTxIntUpdate = false;
+
+/*!
* Indicates if a new packet can be sent
*/
bool NextTx = true;
@@ -136,8 +135,17 @@
{
// If downlink received then update Serial Terminal and execute Rx event
IsTxUpdate = false;
+
// Update serial terminal
- SerialDisplayTxUpdate( );
+ SerialDisplayTxUpdate( );
+ }
+
+ if( IsTxIntUpdate == true )
+ {
+ IsTxIntUpdate = false;
+
+ // Initialize next Tx Interrupt
+ InitNextTxInterrupt( AppPort );
}
if( IsRxUpdate == true )
@@ -175,8 +183,6 @@
// Execute Join event
JoinEvent( );
- // Schedule next packet transmission
- TxDutyCycleTime = OVER_THE_AIR_ACTIVATION_DUTYCYCLE;
DeviceState = DEVICE_STATE_SLEEP;
#else // ABP
@@ -198,30 +204,17 @@
NextTx = SendFrame( );
// Execute transmit event
- TxEvent( );
+ TxEvent( );
}
- if( ComplianceTest.Running == true )
+
+ if( NextTx == false )
{
- // Schedule next packet transmission as soon as possible
- TxDutyCycleTime = COMPLIANCE_TX_DUTYCYCLE;
+ IsTxUpdate = true;
}
- else
- {
- // Schedule next packet transmission
- TxDutyCycleTime = APP_TX_DUTYCYCLE + randr( -APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND );
- }
+
DeviceState = DEVICE_STATE_SLEEP;
break;
- }
- case DEVICE_STATE_CYCLE:
- {
- // Schedule next packet transmission
- TimerSetValue( &TxNextPacketTimer, TxDutyCycleTime );
- TimerStart( &TxNextPacketTimer );
-
- DeviceState = DEVICE_STATE_SLEEP;
- break;
- }
+ }
case DEVICE_STATE_SLEEP:
{
// Wake up through events