Simple LoRaWAN Demo (SX1272 Radio)

Dependencies:   mbed LoRaWAN-lib SX1272Lib

Fork of LoRaWAN-demo-72 by Semtech

Committer:
joshcurry
Date:
Thu Oct 19 13:26:21 2017 +0000
Revision:
8:421371b1777a
Parent:
7:5077515c163b
Working as of 19th october.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mluis 0:45496a70a8a5 1 /*
mluis 0:45496a70a8a5 2 / _____) _ | |
mluis 0:45496a70a8a5 3 ( (____ _____ ____ _| |_ _____ ____| |__
mluis 0:45496a70a8a5 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
mluis 0:45496a70a8a5 5 _____) ) ____| | | || |_| ____( (___| | | |
mluis 0:45496a70a8a5 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 0:45496a70a8a5 7 (C)2015 Semtech
mluis 0:45496a70a8a5 8
mluis 0:45496a70a8a5 9 Description: LoRaMac classA device implementation
mluis 0:45496a70a8a5 10
mluis 0:45496a70a8a5 11 License: Revised BSD License, see LICENSE.TXT file include in the project
mluis 0:45496a70a8a5 12
mluis 0:45496a70a8a5 13 Maintainer: Miguel Luis and Gregory Cristian
mluis 0:45496a70a8a5 14 */
mluis 0:45496a70a8a5 15 #include "mbed.h"
mluis 0:45496a70a8a5 16 #include "board.h"
mluis 0:45496a70a8a5 17 #include "radio.h"
mluis 0:45496a70a8a5 18 #include "LoRaMac.h"
mluis 0:45496a70a8a5 19
mluis 0:45496a70a8a5 20
joshcurry 8:421371b1777a 21 #define APPDATA_SIZE 4
joshcurry 8:421371b1777a 22 #define LORAWAN_DEFAULT_DATARATE DR_0
joshcurry 8:421371b1777a 23 #define LORAWAN_DEVICE_ADDRESS ( uint32_t )0x01234567
joshcurry 8:421371b1777a 24 #define LORAWAN_NWKSKEY { 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }
joshcurry 8:421371b1777a 25 #define LORAWAN_APPSKEY { 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }
mluis 0:45496a70a8a5 26
joshcurry 8:421371b1777a 27 uint8_t AppData[APPDATA_SIZE];
mluis 0:45496a70a8a5 28 static uint8_t NwkSKey[] = LORAWAN_NWKSKEY;
mluis 0:45496a70a8a5 29 static uint8_t AppSKey[] = LORAWAN_APPSKEY;
mluis 0:45496a70a8a5 30
mluis 0:45496a70a8a5 31
mluis 0:45496a70a8a5 32
joshcurry 8:421371b1777a 33 void McpsConfirm( McpsConfirm_t *mcpsConfirm )
mluis 0:45496a70a8a5 34 {
joshcurry 8:421371b1777a 35 return;
mluis 0:45496a70a8a5 36 }
mluis 0:45496a70a8a5 37
joshcurry 8:421371b1777a 38 void McpsIndication( McpsIndication_t *mcpsIndication )
mluis 0:45496a70a8a5 39 {
joshcurry 8:421371b1777a 40 return;
mluis 0:45496a70a8a5 41 }
mluis 0:45496a70a8a5 42
mluis 0:45496a70a8a5 43
mluis 7:5077515c163b 44
joshcurry 8:421371b1777a 45
mluis 0:45496a70a8a5 46 int main( void )
mluis 0:45496a70a8a5 47 {
joshcurry 8:421371b1777a 48 //Initialise firmware
joshcurry 8:421371b1777a 49
mluis 0:45496a70a8a5 50 LoRaMacPrimitives_t LoRaMacPrimitives;
mluis 0:45496a70a8a5 51 LoRaMacCallback_t LoRaMacCallbacks;
mluis 0:45496a70a8a5 52 MibRequestConfirm_t mibReq;
mluis 0:45496a70a8a5 53
joshcurry 8:421371b1777a 54 LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
joshcurry 8:421371b1777a 55 LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
joshcurry 8:421371b1777a 56 // LoRaMacPrimitives.MacMlmeConfirm = McpsConfirm;
joshcurry 8:421371b1777a 57 LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks );
mluis 5:62862ef9480b 58
joshcurry 8:421371b1777a 59 LoRaMacChannelAdd( 3, ( ChannelParams_t ){ 867100000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } );
joshcurry 8:421371b1777a 60 LoRaMacChannelAdd( 4, ( ChannelParams_t ){ 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 });
joshcurry 8:421371b1777a 61 LoRaMacChannelAdd( 5, ( ChannelParams_t ){ 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } );
joshcurry 8:421371b1777a 62 LoRaMacChannelAdd( 6, ( ChannelParams_t ){ 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } );
joshcurry 8:421371b1777a 63 LoRaMacChannelAdd( 7, ( ChannelParams_t ){ 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } );
joshcurry 8:421371b1777a 64 LoRaMacChannelAdd( 8, ( ChannelParams_t ){ 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 } );
joshcurry 8:421371b1777a 65 LoRaMacChannelAdd( 9, ( ChannelParams_t ){ 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 } );
mluis 5:62862ef9480b 66
joshcurry 8:421371b1777a 67 //Join ABP
mluis 0:45496a70a8a5 68
joshcurry 8:421371b1777a 69 mibReq.Type = MIB_NET_ID;
joshcurry 8:421371b1777a 70 mibReq.Param.NetID = 0;
joshcurry 8:421371b1777a 71 LoRaMacMibSetRequestConfirm( &mibReq );
joshcurry 8:421371b1777a 72
joshcurry 8:421371b1777a 73 mibReq.Type = MIB_DEV_ADDR;
joshcurry 8:421371b1777a 74 mibReq.Param.DevAddr = LORAWAN_DEVICE_ADDRESS;
joshcurry 8:421371b1777a 75 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 0:45496a70a8a5 76
joshcurry 8:421371b1777a 77 mibReq.Type = MIB_NWK_SKEY;
joshcurry 8:421371b1777a 78 mibReq.Param.NwkSKey = NwkSKey;
joshcurry 8:421371b1777a 79 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 0:45496a70a8a5 80
joshcurry 8:421371b1777a 81 mibReq.Type = MIB_APP_SKEY;
joshcurry 8:421371b1777a 82 mibReq.Param.AppSKey = AppSKey;
joshcurry 8:421371b1777a 83 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 7:5077515c163b 84
joshcurry 8:421371b1777a 85 mibReq.Type = MIB_NETWORK_JOINED;
joshcurry 8:421371b1777a 86 mibReq.Param.IsNetworkJoined = true;
joshcurry 8:421371b1777a 87 LoRaMacMibSetRequestConfirm( &mibReq );
joshcurry 8:421371b1777a 88
joshcurry 8:421371b1777a 89 mibReq.Type = MIB_CHANNELS_TX_POWER;
joshcurry 8:421371b1777a 90 mibReq.Param.ChannelsTxPower = LORAMAC_MAX_TX_POWER;
joshcurry 8:421371b1777a 91 LoRaMacMibSetRequestConfirm( &mibReq );
joshcurry 8:421371b1777a 92
joshcurry 8:421371b1777a 93 mibReq.Type = MIB_CHANNELS_DEFAULT_TX_POWER;
joshcurry 8:421371b1777a 94 mibReq.Param.ChannelsDefaultTxPower = LORAMAC_MAX_TX_POWER;
joshcurry 8:421371b1777a 95 LoRaMacMibSetRequestConfirm( &mibReq );
mluis 0:45496a70a8a5 96
joshcurry 8:421371b1777a 97 //Prepareframe
mluis 0:45496a70a8a5 98
joshcurry 8:421371b1777a 99 AppData[0] = 0xFF;
joshcurry 8:421371b1777a 100 AppData[1] = 0xFF;
joshcurry 8:421371b1777a 101 AppData[2] = 0xFF;
joshcurry 8:421371b1777a 102 AppData[3] = 0xFF;
joshcurry 8:421371b1777a 103
joshcurry 8:421371b1777a 104 //Sendframe
joshcurry 8:421371b1777a 105
joshcurry 8:421371b1777a 106 McpsReq_t mcpsReq;
joshcurry 8:421371b1777a 107
joshcurry 8:421371b1777a 108 uint8_t AppPort = 3;
joshcurry 8:421371b1777a 109 mcpsReq.Type = MCPS_CONFIRMED;
joshcurry 8:421371b1777a 110 mcpsReq.Req.Confirmed.fPort = AppPort;
joshcurry 8:421371b1777a 111 mcpsReq.Req.Confirmed.fBuffer = AppData;
joshcurry 8:421371b1777a 112 mcpsReq.Req.Confirmed.fBufferSize = APPDATA_SIZE;
joshcurry 8:421371b1777a 113 mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
joshcurry 8:421371b1777a 114
joshcurry 8:421371b1777a 115 LoRaMacMcpsRequest( &mcpsReq );
joshcurry 8:421371b1777a 116
joshcurry 8:421371b1777a 117 while(1);
joshcurry 8:421371b1777a 118 }
mluis 0:45496a70a8a5 119
joshcurry 8:421371b1777a 120
mluis 3:3152aa75c58d 121
joshcurry 8:421371b1777a 122
joshcurry 8:421371b1777a 123