A very easy to understand LoRaWAN-node code.
Dependencies: LoRaWAN-lib SX1272Lib X_NUCLEO_IKS01A1 mbed
Important parameters:
• In comissioning.h: DevEUI, AppEUI, AppKEY, DevADR, NwksKEY, AppsKEY, OTAA and public network. Frequency and channel block to use, confirmed or unconfirmed messages, app port, app data size and OTAA and Tx duty cycles.
• In LoRaMac.h: Maximum payload and MAC commands length, receive delays, max FCNT, adr ack limit, timeout and delay, max ack retries, rssi threshold and sync words.
• In LoRaMac.cpp: Maximum payload, MAC commands and FRMpayload length.
• In LoRaMac-board.h: Tx power, data rates and band settings.
NOTE: Please refer to LoRaWAN regional parameters (page 12 for US band) to know which parameters you can modify.
Diff: Code/SerialDisplay.cpp
- Revision:
- 0:60ff878b27b8
diff -r 000000000000 -r 60ff878b27b8 Code/SerialDisplay.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Code/SerialDisplay.cpp Tue Apr 03 17:09:34 2018 +0000 @@ -0,0 +1,137 @@ +/* + / _____) _ | | +( (____ _____ ____ _| |_ _____ ____| |__ + \____ \| ___ | (_ _) ___ |/ ___) _ \ + _____) ) ____| | | || |_| ____( (___| | | | +(______/|_____)_|_|_| \__)_____)\____)_| |_| + (C)2015 Semtech + +Description: VT100 serial display management + +License: Revised BSD License, see LICENSE.TXT file include in the project + +Maintainer: Miguel Luis and Gregory Cristian +*/ + +#include "SerialDisplay.h" + +VT100 vt( USBTX, USBRX ); + +void SerialDisplayJoinUpdate( void ) +{ + printf( "###### ===== JOINING ==== ######\r\n" ); + + DisplayNetworkParam( ); + + printf( "\r\n" ); +} + +void SerialDisplayTxUpdate(void) +{ + printf( "###### ===== UPLINK FRAME %d ==== ######\r\n", LoRaMacUplinkStatus.UplinkCounter ); + + DisplayNetworkParam( ); + + printf( "TX PORT: %d\r\n", LoRaMacUplinkStatus.Port ); + + if( LoRaMacUplinkStatus.BufferSize != 0 ) + { + printf( "TX DATA: " ); + if( LoRaMacUplinkStatus.Type == MCPS_CONFIRMED ) + { + printf( "CONFIRMED\r\n" ); + } + else + { + printf( "UNCONFIRMED\r\n" ); + } + SerialDisplayHex( LoRaMacUplinkStatus.Buffer, LoRaMacUplinkStatus.BufferSize ); + } + + printf( "DATA RATE: DR%d\r\n", LoRaMacUplinkStatus.Datarate ); + + printf( "TX POWER: %d dBm\r\n", 30 - ( LoRaMacUplinkStatus.TxPower << 1 ) ); + + printf( "BATTERY: %2.2fV\r\n", BoardGetBatteryLevel( ) ); + + printf( "\r\n"); +} + +void SerialDisplayRxUpdate( void ) +{ + printf( "###### ===== DOWNLINK FRAME %d ==== ######\r\n", LoRaMacDownlinkStatus.DownlinkCounter ); + + printf( "RX WINDOW: %d\r\n", LoRaMacDownlinkStatus.RxSlot + 1 ); + + printf( "RX PORT: %d\r\n", LoRaMacDownlinkStatus.Port ); + + if( LoRaMacDownlinkStatus.BufferSize != 0 ) + { + printf( "RX DATA: \r\n" ); + SerialDisplayHex( LoRaMacDownlinkStatus.Buffer, LoRaMacDownlinkStatus.BufferSize ); + } + + printf( "RX RSSI: %d\r\n", LoRaMacDownlinkStatus.Rssi ); + + printf( "RX SNR: %d\r\n", LoRaMacDownlinkStatus.Snr ); + + printf( "\r\n" ); +} + +void SerialDisplayHex( uint8_t *pData, uint8_t len ) +{ + int i; + bool newline = 0; + + for( i = 0; i < len; i++ ) + { + if( newline != 0 ) + { + printf( "\r\n" ); + newline = 0; + } + + printf( "%02X", pData[i] ); + + if( ( ( i + 1 ) % 16 ) == 0 ) + { + newline = 1; + } + } + printf( "\r\n" ); +} + + + +void DisplayNetworkParam( void ) +{ +#if( OVER_THE_AIR_ACTIVATION != 0 ) + + printf( "DEVEUI: " ); + SerialDisplayHex( DevEui, 8 ); + + printf( "APPEUI: " ); + SerialDisplayHex( AppEui, 8 ); + + printf( "APPKEY: " ); + SerialDisplayHex( AppKey, 16 ); + +#else + + printf( "DEVADDR: " ); + + uint8_t *pData = ( uint8_t* )&DevAddr; + for( int32_t i = 3; i >= 0; i-- ) + { + printf( "%02X", pData[i] ); + } + printf( "\r\n" ); + + printf( "NWKSKEY: " ); + SerialDisplayHex( NwkSKey, 16 ); + + printf( "APPSKEY: " ); + SerialDisplayHex( AppSKey, 16 ); + +#endif +} \ No newline at end of file