Lora_with_GPS integration code - program hangs after a few transmissions
Dependencies: mbed LoRaWAN-lib SingleFrequencyLora
Fork of simple-demo-76_revised_20171113 by
app/main.cpp@13:ac84e36985a7, 2017-11-20 (annotated)
- Committer:
- Rishin
- Date:
- Mon Nov 20 12:09:24 2017 +0000
- Revision:
- 13:ac84e36985a7
- Parent:
- 12:7debb1c79a06
LoRa with GPS publish
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mluis | 0:92bca02df485 | 1 | /* |
mluis | 0:92bca02df485 | 2 | / _____) _ | | |
mluis | 0:92bca02df485 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
mluis | 0:92bca02df485 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
mluis | 0:92bca02df485 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
mluis | 0:92bca02df485 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 0:92bca02df485 | 7 | (C)2015 Semtech |
mluis | 0:92bca02df485 | 8 | |
mluis | 0:92bca02df485 | 9 | Description: LoRaMac classA device implementation |
mluis | 0:92bca02df485 | 10 | |
mluis | 0:92bca02df485 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
mluis | 0:92bca02df485 | 12 | |
mluis | 0:92bca02df485 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
mluis | 0:92bca02df485 | 14 | */ |
mluis | 0:92bca02df485 | 15 | #include "mbed.h" |
mluis | 0:92bca02df485 | 16 | #include "board.h" |
mluis | 0:92bca02df485 | 17 | #include "radio.h" |
mluis | 0:92bca02df485 | 18 | #include "LoRaMac.h" |
Rishin | 12:7debb1c79a06 | 19 | #include "l86.hpp" |
mluis | 3:9c6f7f082151 | 20 | |
Rishin | 12:7debb1c79a06 | 21 | // #define APPDATA_SIZE 55 // size of a GPS_data struct //commented by Rish |
joshcurry | 10:9364ab3a08eb | 22 | #define LORAWAN_DEFAULT_DATARATE DR_0 |
joshcurry | 10:9364ab3a08eb | 23 | #define LORAWAN_DEVICE_ADDRESS ( uint32_t )0x01234567 |
joshcurry | 10:9364ab3a08eb | 24 | #define LORAWAN_NWKSKEY { 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 } |
joshcurry | 10:9364ab3a08eb | 25 | #define LORAWAN_APPSKEY { 0x11, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 } |
mluis | 1:352f608c3337 | 26 | |
Rishin | 12:7debb1c79a06 | 27 | |
Rishin | 12:7debb1c79a06 | 28 | RawSerial gps(GPS_TX, GPS_RX); // USART1 |
Rishin | 12:7debb1c79a06 | 29 | // RawSerial pc(PC_TX, PC_RX); |
Rishin | 12:7debb1c79a06 | 30 | |
Rishin | 12:7debb1c79a06 | 31 | DigitalOut Reset(RESET_PIN); |
Rishin | 12:7debb1c79a06 | 32 | DigitalOut Force_on(FORCE_ON_PIN); |
Rishin | 12:7debb1c79a06 | 33 | DigitalOut GPS_status(GPS_STATUS_LED); |
Rishin | 12:7debb1c79a06 | 34 | // DigitalIn OnePPS(ONEPPS_PIN); |
Rishin | 12:7debb1c79a06 | 35 | |
Rishin | 12:7debb1c79a06 | 36 | |
Rishin | 12:7debb1c79a06 | 37 | // uint8_t AppDatasend[APPDATA_SIZE]; |
Rishin | 12:7debb1c79a06 | 38 | RMC_data RMC; |
Rishin | 12:7debb1c79a06 | 39 | GPS_data GPS_parse; |
Rishin | 12:7debb1c79a06 | 40 | volatile int Char_index = 0; // index for char array |
Rishin | 12:7debb1c79a06 | 41 | char Rx_data[MAX_NMEA_LENGTH] = "0"; // char array to store received bytes |
Rishin | 12:7debb1c79a06 | 42 | char tx_line[82]; |
Rishin | 12:7debb1c79a06 | 43 | |
Rishin | 12:7debb1c79a06 | 44 | void gps_receive(void) { |
Rishin | 12:7debb1c79a06 | 45 | // Note: you need to actually read from the serial to clear the RX interrupt |
Rishin | 12:7debb1c79a06 | 46 | while(gps.readable()) { |
Rishin | 12:7debb1c79a06 | 47 | char incoming = gps.getc(); |
Rishin | 12:7debb1c79a06 | 48 | // #ifdef DEBUGGER |
Rishin | 12:7debb1c79a06 | 49 | // pc.putc(incoming); |
Rishin | 12:7debb1c79a06 | 50 | // #endif |
Rishin | 12:7debb1c79a06 | 51 | Rx_data[Char_index] = incoming; |
Rishin | 12:7debb1c79a06 | 52 | |
Rishin | 12:7debb1c79a06 | 53 | if((Rx_data[Char_index] == '\n')){ // Received the end of an NMEA scentence |
Rishin | 12:7debb1c79a06 | 54 | if((strncmp(GPRMC_Tag,Rx_data,(sizeof(GPRMC_Tag)-1)) == 0) || (strncmp(GNRMC_Tag,Rx_data,(sizeof(GNRMC_Tag)-1)) == 0)){ |
Rishin | 12:7debb1c79a06 | 55 | RMC = Parse_RMC_sentence(Rx_data); |
Rishin | 12:7debb1c79a06 | 56 | if(strcmp(RMC.Status, "A") == 0){ |
Rishin | 12:7debb1c79a06 | 57 | GPS_status = 0; // Turn status LED off |
Rishin | 12:7debb1c79a06 | 58 | // GPS_parse = Parse_RMC_data(RMC); // Parse into format suitable for Tom (Dinghy_RaceTrak software) |
Rishin | 12:7debb1c79a06 | 59 | // Call function to send using LoRa module |
Rishin | 12:7debb1c79a06 | 60 | } |
Rishin | 12:7debb1c79a06 | 61 | else{ |
Rishin | 12:7debb1c79a06 | 62 | GPS_status = 1; |
Rishin | 12:7debb1c79a06 | 63 | // Send "No GPS fix" over LoRa? |
Rishin | 12:7debb1c79a06 | 64 | } |
Rishin | 12:7debb1c79a06 | 65 | |
Rishin | 12:7debb1c79a06 | 66 | // delete this line // Or replace with whatever Tom wants for invalid GPS data |
Rishin | 12:7debb1c79a06 | 67 | GPS_parse = Parse_RMC_data(RMC); // Parse into format suitable for Tom (Dinghy_RaceTrak software) |
Rishin | 12:7debb1c79a06 | 68 | // __disable_irq(); // edit |
Rishin | 12:7debb1c79a06 | 69 | // Send_GPS_data(GPS_parse); //edit |
Rishin | 12:7debb1c79a06 | 70 | |
Rishin | 12:7debb1c79a06 | 71 | |
Rishin | 12:7debb1c79a06 | 72 | } |
Rishin | 12:7debb1c79a06 | 73 | Char_index = 0; |
Rishin | 12:7debb1c79a06 | 74 | memset(Rx_data,0,sizeof(Rx_data)); |
Rishin | 12:7debb1c79a06 | 75 | } |
Rishin | 12:7debb1c79a06 | 76 | else |
Rishin | 12:7debb1c79a06 | 77 | Char_index++; |
Rishin | 12:7debb1c79a06 | 78 | } |
Rishin | 12:7debb1c79a06 | 79 | // __enable_irq();// edit |
Rishin | 12:7debb1c79a06 | 80 | return; |
Rishin | 12:7debb1c79a06 | 81 | // store chars into a string then process into LAT, LONG, SOG, COG & DATETIME, VALID/INVLAID |
Rishin | 12:7debb1c79a06 | 82 | } |
Rishin | 12:7debb1c79a06 | 83 | |
mluis | 0:92bca02df485 | 84 | static uint8_t NwkSKey[] = LORAWAN_NWKSKEY; |
mluis | 0:92bca02df485 | 85 | static uint8_t AppSKey[] = LORAWAN_APPSKEY; |
mluis | 0:92bca02df485 | 86 | |
mluis | 0:92bca02df485 | 87 | |
mluis | 0:92bca02df485 | 88 | |
joshcurry | 10:9364ab3a08eb | 89 | void McpsConfirm( McpsConfirm_t *mcpsConfirm ) |
mluis | 0:92bca02df485 | 90 | { |
joshcurry | 10:9364ab3a08eb | 91 | return; |
mluis | 0:92bca02df485 | 92 | } |
mluis | 0:92bca02df485 | 93 | |
joshcurry | 10:9364ab3a08eb | 94 | void McpsIndication( McpsIndication_t *mcpsIndication ) |
mluis | 0:92bca02df485 | 95 | { |
joshcurry | 10:9364ab3a08eb | 96 | return; |
mluis | 3:9c6f7f082151 | 97 | } |
mluis | 3:9c6f7f082151 | 98 | |
mluis | 3:9c6f7f082151 | 99 | |
mluis | 9:ee9dcbb9708d | 100 | |
joshcurry | 10:9364ab3a08eb | 101 | |
mluis | 0:92bca02df485 | 102 | int main( void ) |
mluis | 0:92bca02df485 | 103 | { |
joshcurry | 10:9364ab3a08eb | 104 | //Initialise firmware |
Rishin | 12:7debb1c79a06 | 105 | |
Rishin | 12:7debb1c79a06 | 106 | |
mluis | 3:9c6f7f082151 | 107 | LoRaMacPrimitives_t LoRaMacPrimitives; |
mluis | 3:9c6f7f082151 | 108 | LoRaMacCallback_t LoRaMacCallbacks; |
mluis | 3:9c6f7f082151 | 109 | MibRequestConfirm_t mibReq; |
mluis | 0:92bca02df485 | 110 | |
joshcurry | 10:9364ab3a08eb | 111 | LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm; |
joshcurry | 10:9364ab3a08eb | 112 | LoRaMacPrimitives.MacMcpsIndication = McpsIndication; |
joshcurry | 10:9364ab3a08eb | 113 | // LoRaMacPrimitives.MacMlmeConfirm = McpsConfirm; |
joshcurry | 10:9364ab3a08eb | 114 | LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks ); |
mluis | 7:3173f0508a98 | 115 | |
cdebank | 11:32323f490d9e | 116 | LoRaMacChannelAdd( 3, ( ChannelParams_t ){ 869400000, { ( ( DR_5 << 4 ) | DR_5 ) }, 3 } ); |
cdebank | 11:32323f490d9e | 117 | //LoRaMacChannelAdd( 4, ( ChannelParams_t ){ 867300000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } ); |
cdebank | 11:32323f490d9e | 118 | //LoRaMacChannelAdd( 5, ( ChannelParams_t ){ 867500000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } ); |
cdebank | 11:32323f490d9e | 119 | //LoRaMacChannelAdd( 6, ( ChannelParams_t ){ 867700000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } ); |
cdebank | 11:32323f490d9e | 120 | //LoRaMacChannelAdd( 7, ( ChannelParams_t ){ 867900000, { ( ( DR_5 << 4 ) | DR_0 ) }, 0 } ); |
cdebank | 11:32323f490d9e | 121 | //LoRaMacChannelAdd( 8, ( ChannelParams_t ){ 868800000, { ( ( DR_7 << 4 ) | DR_7 ) }, 2 } ); |
cdebank | 11:32323f490d9e | 122 | //LoRaMacChannelAdd( 9, ( ChannelParams_t ){ 868300000, { ( ( DR_6 << 4 ) | DR_6 ) }, 1 } ); |
mluis | 7:3173f0508a98 | 123 | |
joshcurry | 10:9364ab3a08eb | 124 | //Join ABP |
mluis | 0:92bca02df485 | 125 | |
joshcurry | 10:9364ab3a08eb | 126 | mibReq.Type = MIB_NET_ID; |
joshcurry | 10:9364ab3a08eb | 127 | mibReq.Param.NetID = 0; |
joshcurry | 10:9364ab3a08eb | 128 | LoRaMacMibSetRequestConfirm( &mibReq ); |
joshcurry | 10:9364ab3a08eb | 129 | |
joshcurry | 10:9364ab3a08eb | 130 | mibReq.Type = MIB_DEV_ADDR; |
joshcurry | 10:9364ab3a08eb | 131 | mibReq.Param.DevAddr = LORAWAN_DEVICE_ADDRESS; |
joshcurry | 10:9364ab3a08eb | 132 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 3:9c6f7f082151 | 133 | |
joshcurry | 10:9364ab3a08eb | 134 | mibReq.Type = MIB_NWK_SKEY; |
joshcurry | 10:9364ab3a08eb | 135 | mibReq.Param.NwkSKey = NwkSKey; |
joshcurry | 10:9364ab3a08eb | 136 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 3:9c6f7f082151 | 137 | |
joshcurry | 10:9364ab3a08eb | 138 | mibReq.Type = MIB_APP_SKEY; |
joshcurry | 10:9364ab3a08eb | 139 | mibReq.Param.AppSKey = AppSKey; |
joshcurry | 10:9364ab3a08eb | 140 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 9:ee9dcbb9708d | 141 | |
joshcurry | 10:9364ab3a08eb | 142 | mibReq.Type = MIB_NETWORK_JOINED; |
joshcurry | 10:9364ab3a08eb | 143 | mibReq.Param.IsNetworkJoined = true; |
joshcurry | 10:9364ab3a08eb | 144 | LoRaMacMibSetRequestConfirm( &mibReq ); |
joshcurry | 10:9364ab3a08eb | 145 | |
joshcurry | 10:9364ab3a08eb | 146 | mibReq.Type = MIB_CHANNELS_TX_POWER; |
joshcurry | 10:9364ab3a08eb | 147 | mibReq.Param.ChannelsTxPower = LORAMAC_MAX_TX_POWER; |
joshcurry | 10:9364ab3a08eb | 148 | LoRaMacMibSetRequestConfirm( &mibReq ); |
joshcurry | 10:9364ab3a08eb | 149 | |
joshcurry | 10:9364ab3a08eb | 150 | mibReq.Type = MIB_CHANNELS_DEFAULT_TX_POWER; |
joshcurry | 10:9364ab3a08eb | 151 | mibReq.Param.ChannelsDefaultTxPower = LORAMAC_MAX_TX_POWER; |
joshcurry | 10:9364ab3a08eb | 152 | LoRaMacMibSetRequestConfirm( &mibReq ); |
mluis | 3:9c6f7f082151 | 153 | |
Rishin | 12:7debb1c79a06 | 154 | /*//Prepareframe |
mluis | 3:9c6f7f082151 | 155 | |
cdebank | 11:32323f490d9e | 156 | AppData[0] = 0x43; |
cdebank | 11:32323f490d9e | 157 | AppData[1] = 0x68; |
cdebank | 11:32323f490d9e | 158 | AppData[2] = 0x72; |
cdebank | 11:32323f490d9e | 159 | AppData[3] = 0x69; |
cdebank | 11:32323f490d9e | 160 | AppData[4] = 0x73; |
cdebank | 11:32323f490d9e | 161 | AppData[5] = 0x21; |
Rishin | 12:7debb1c79a06 | 162 | AppData[6] = 0x21;*/ |
joshcurry | 10:9364ab3a08eb | 163 | |
joshcurry | 10:9364ab3a08eb | 164 | //Sendframe |
joshcurry | 10:9364ab3a08eb | 165 | |
Rishin | 12:7debb1c79a06 | 166 | /*McpsReq_t mcpsReq; |
joshcurry | 10:9364ab3a08eb | 167 | |
joshcurry | 10:9364ab3a08eb | 168 | uint8_t AppPort = 3; |
cdebank | 11:32323f490d9e | 169 | mcpsReq.Type = MCPS_UNCONFIRMED; |
cdebank | 11:32323f490d9e | 170 | mcpsReq.Req.Unconfirmed.fPort = AppPort; |
cdebank | 11:32323f490d9e | 171 | mcpsReq.Req.Unconfirmed.fBuffer = AppData; |
cdebank | 11:32323f490d9e | 172 | mcpsReq.Req.Unconfirmed.fBufferSize = APPDATA_SIZE; |
cdebank | 11:32323f490d9e | 173 | mcpsReq.Req.Unconfirmed.Datarate = DR_5; |
joshcurry | 10:9364ab3a08eb | 174 | |
Rishin | 12:7debb1c79a06 | 175 | LoRaMacMcpsRequest( &mcpsReq ); // Commented out by Rish*/ |
Rishin | 12:7debb1c79a06 | 176 | |
Rishin | 12:7debb1c79a06 | 177 | GPS_status = 1; |
Rishin | 12:7debb1c79a06 | 178 | gps.attach(&gps_receive, Serial::RxIrq); |
Rishin | 12:7debb1c79a06 | 179 | gps.printf(PMTK_SET_NMEA_OUTPUT_RMC); // Only output RMC and GPTXT |
Rishin | 12:7debb1c79a06 | 180 | gps.printf(PMTK_SET_UPDATE_F_2HZ); // Set update Frequency to 2Hz |
joshcurry | 10:9364ab3a08eb | 181 | |
cdebank | 11:32323f490d9e | 182 | while(1){ |
Rishin | 12:7debb1c79a06 | 183 | wait(5); // could time how long the IRQ takes to improve the efficienct of this |
Rishin | 12:7debb1c79a06 | 184 | //LoRaMacMcpsRequest( &mcpsReq ); |
Rishin | 12:7debb1c79a06 | 185 | // Print_GPS_data(GPS_parse); |
Rishin | 12:7debb1c79a06 | 186 | Send_GPS_data(GPS_parse); |
Rishin | 12:7debb1c79a06 | 187 | |
Rishin | 12:7debb1c79a06 | 188 | //interrupt is not getting triggered!- reentrancy issues |
Rishin | 12:7debb1c79a06 | 189 | //gps_receive(); |
cdebank | 11:32323f490d9e | 190 | } |
joshcurry | 10:9364ab3a08eb | 191 | } |
mluis | 3:9c6f7f082151 | 192 |