
LMIC transmit example for NAmote-72 with GPS
Dependencies: lib_gps lib_mpl3115a2 lmic_MOTE_L152RC mbed
Deprecated and replaced with
Import programLoRaWAN-NAMote72-Application-Demo
Demonstration of Class-A LoRaWAN device using NAMote-72
LoRaWAN Network Configuration (in Config.h)
For Over the Air (OTA) activation of an End-Device, it must be configured with the following parameters:
DEVEUI
(8 Bytes) : Fist 3 Bytes is the Organizationally Unique Identifier (OUI) followed by 5 bytes of unique ID.APPEUI
(8 Bytes)APPKey
(or DEVKEY) (16 Bytes) The parameters can be entered as shown in the figure below
LoRaWAN Transmission Configuration (in Config.h)
- Inter-Frame Delay :
One can change the delay between each frame transmission using
MS_DELAY_NEXT_TX
It is advisable thatMS_DELAY_NEXT_TX
is greater than or equal to 3sec.
- Payload Length :
The lenght of the payload (in bytes) to be transmitted can be configured using
PAYLOAD_LENGTH
- Data Rate :
The data rate can be configured as per LoRaWAN specification using the paramter
FIXED_DR
- Channel Configuration :
In the case where the End-Device is transmitting over frequencies corresponding to a block of 8 channels, the block can be specified using
CHNL_HYBRID
. The value 0 corresponds to Block A, 1 corresponds to Block B and so on.When the End-Device transmits over more than 50 channels,
CHNL_HYBRID
needs to be commented out
- Transmit Power :
The power of the data to be transmitted can be configured using the parameter
FIXED_TX_POWER
. The maximum transmit power allowed is as per FCC regulation, depending upon the mode of transmission.
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, transmit power, battery level 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 6:0b2b2d196ddd, committed 2015-10-21
- Comitter:
- dudmuck
- Date:
- Wed Oct 21 01:09:19 2015 +0000
- Parent:
- 5:6244f45b15f2
- Child:
- 7:7de55330772d
- Commit message:
- prevent lost TX packet when OP_TXRXPEND is set. Testing reversed appeui & deveui.
Changed in this revision
--- a/config.h Mon Sep 21 18:04:06 2015 +0000 +++ b/config.h Wed Oct 21 01:09:19 2015 +0000 @@ -2,4 +2,4 @@ #define CFG_sx1272_radio -#define CHNL_HYBRID 0 /* 0-7 to select block of 8 channels used */ \ No newline at end of file +//#define CHNL_HYBRID 0 /* 0-7 to select block of 8 channels used */ \ No newline at end of file
--- a/lib_gps.lib Mon Sep 21 18:04:06 2015 +0000 +++ b/lib_gps.lib Wed Oct 21 01:09:19 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/dudmuck/code/lib_gps/#03d7275dc4fd +https://developer.mbed.org/users/dudmuck/code/lib_gps/#b8c049fa7db2
--- a/lmic_MOTE_L152RC.lib Mon Sep 21 18:04:06 2015 +0000 +++ b/lmic_MOTE_L152RC.lib Wed Oct 21 01:09:19 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Semtech/code/lmic_MOTE_L152RC/#dfc048cda33f +https://developer.mbed.org/teams/Semtech/code/lmic_MOTE_L152RC/#0faa1bb768b5
--- a/main.cpp Mon Sep 21 18:04:06 2015 +0000 +++ b/main.cpp Wed Oct 21 01:09:19 2015 +0000 @@ -18,9 +18,8 @@ #include "gps.h" #include "debug.h" - -//#define SENET_F -#define SMTC +#define SENET_F +//#define SMTC typedef enum { MOTE_NONE = 0, @@ -69,10 +68,12 @@ ////////////////////////////////////////////////// #ifdef SENET_F // application router ID (LSBF) -static const u1_t APPEUI[8] = { 0x01, 0x00, 0x01, 0x00, 0x00, 0x0c, 0x25, 0x00 }; +//static const u1_t APPEUI[8] = { 0x01, 0x00, 0x01, 0x00, 0x00, 0x0c, 0x25, 0x00 }; +static const u1_t reverse_APPEUI[8] = { 0x00, 0x25, 0x0C, 0x00, 0x00, 0x01, 0x00, 0x01 }; // unique device ID (LSBF) -static const u1_t DEVEUI[8] = { 0x0f, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; +//static const u1_t DEVEUI[8] = { 0x0f, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; +static const u1_t reverse_DEVEUI[8] = { 0x00, 0x25, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x0F }; // device-specific AES key (derived from device EUI) static const u1_t DEVKEY[16] = { 0xe4, 0x72, 0x71, 0xc5, 0xf5, 0x30, 0xa9, 0x9f, 0xcf, 0xc4, 0x0e, 0xab, 0xea, 0xd7, 0x19, 0x42, }; @@ -82,15 +83,20 @@ #ifdef SMTC // Semtech Activation (v1.x server) // application router ID (LSBF) -static const u1_t APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; +static const u1_t reverse_APPEUI[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + //AA-AA-AA-AA-FF-FF-FF-FF +//static const u1_t APPEUI[8] = { 0xff, 0xff, 0xff, 0xff, 0xaa, 0xaa, 0xaa, 0xaa }; +//static const u1_t reverse_APPEUI[8] = { 0xaa, 0xaa, 0xaa, 0xaa, 0xff, 0xff, 0xff, 0xff }; // unique device ID (LSBF) -//static const u1_t DEVEUI[8] = { 0x20, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; -static const u1_t DEVEUI[8] = { 0x34, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; -//static const u1_t DEVEUI[8] = { 0x35, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; +//static const u1_t DEVEUI[8] = { 0x21, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x25, 0x00 }; +static const u1_t reverse_DEVEUI[8] = { 0x00, 0x25, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x20 }; +//static const u1_t DEVEUI[8] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; +//static const u1_t reverse_DEVEUI[8] = { 0xEF, 0xCD, 0xAB, 0x89, 0x67, 0x45, 0x23, 0x01 }; // device-specific AES key (derived from device EUI) static const u1_t DEVKEY[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; +//static const u1_t DEVKEY[16] = { 0xab, 0x89, 0xef, 0xcd, 0x23, 0x01, 0x67, 0x45, 0x54, 0x76, 0x10, 0x32, 0xdc, 0xfe, 0x98, 0xba }; /*static uint8_t NwkSKey[] = { @@ -112,12 +118,14 @@ // provide application router ID (8 bytes, LSBF) void os_getArtEui (u1_t* buf) { - memcpy(buf, APPEUI, 8); + //memcpy(buf, APPEUI, 8); + LMIC_reverse_memcpy(buf, reverse_APPEUI, 8); } // provide device ID (8 bytes, LSBF) void os_getDevEui (u1_t* buf) { - memcpy(buf, DEVEUI, 8); + //memcpy(buf, DEVEUI, 8); + LMIC_reverse_memcpy(buf, reverse_DEVEUI, 8); } // provide device key (16 bytes) @@ -131,9 +139,6 @@ void get_mote_version() { char first; - - /*DigitalOut pc_7(PC_7); - DigitalIn pc_1(PC_1);*/ pc_7 = 1; first = pc_1; @@ -231,15 +236,12 @@ static void PrepareDataFrame( void ) { uint16_t altitudeGps; - float volts; restore_hsi(); gps.service(); - printf("lat:%f long:%f\r\n", gps.Latitude, gps.Longitude); - // printf("lat:%d long:%d\r\n", gps.LatitudeBinary, gps.LongitudeBinary); + //printf("lat:%f long:%f\r\n", gps.Latitude, gps.Longitude); mpl3115a2.ReadTemperature(); - //printf("temp:%d\r\n", (int)mpl3115a2.Temperature); // immediately prepare next transmission //LMIC.frame[0] = LMIC.rxq.snr; @@ -259,26 +261,26 @@ LMIC.frame[9] = ( altitudeGps >> 8 ) & 0xFF; LMIC.frame[10] = altitudeGps & 0xFF; - volts = bat->read()*AIN_VREF*AIN_VBAT_DIV; - printf("bat:%.2f\r\n", volts); -#ifdef CHNL_HYBRID - LMIC.txpow_limit = 20; -#else + + //printf("bat:%.2f\r\n", volts); +#ifndef CHNL_HYBRID + float volts = bat->read()*AIN_VREF*AIN_VBAT_DIV; if (volts < LOW_BAT_THRESHOLD) LMIC.txpow_limit = 20; else LMIC.txpow_limit = 30; -#endif /* !CHNL_HYBRID */ - - // test forcing: - LMIC.datarate = DR_SF10; // force SF10 - +#endif /* !CHNL_HYBRID */ } -static void onSendFrame (osjob_t* j) { +static void onSendFrame (osjob_t* j) +{ + if (LMIC.opmode & OP_TXRXPEND) + return; + PrepareDataFrame( ); - // schedule transmission (port 1, data[], datalen 1, ACK requested) - // (will be sent as soon as duty cycle permits) + // schedule transmission (port 1, data[], datalen 1, ACK requested) + // (will be sent as soon as duty cycle permits) + LMIC_setTxData2(5, LMIC.frame, APP_DATA_SIZE, APP_ACK); }