LoRaWAN smart agriculture application using FRDM-K64F ARM mbed board along with SX1272MB2xAS LoRa shield as the LoRa Node.

Dependencies:   DHT11 LMiC SX1272Lib mbed

Fork of LoRaWAN-lmic-app by Semtech

Committer:
GTsapparellas
Date:
Mon Apr 02 16:09:01 2018 +0000
Revision:
7:8ffc2f64b0f8
Parent:
6:3758685f4b75
Child:
8:f307640ed331
Added comments for usability principles coverage.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GTsapparellas 6:3758685f4b75 1 /*******************************************************************************
GTsapparellas 6:3758685f4b75 2 * Internet of Things (IoT) smart monitoring
GTsapparellas 6:3758685f4b75 3 * device for agriculture using LoRaWAN technology.
GTsapparellas 6:3758685f4b75 4 *
GTsapparellas 6:3758685f4b75 5 * LoRa Gateway: Single-channel Dragino LG01-P LoRa Gateway
GTsapparellas 6:3758685f4b75 6 *
GTsapparellas 6:3758685f4b75 7 * Measurement parameters: Temperature (Celcius)
GTsapparellas 6:3758685f4b75 8 * Humidity (Relative Humidity %)
GTsapparellas 6:3758685f4b75 9 * Light Intenisty (Volts)
GTsapparellas 6:3758685f4b75 10 * Soil Moisture (Volts)
GTsapparellas 6:3758685f4b75 11 *
GTsapparellas 6:3758685f4b75 12 * Evaluation board: FRDM-K64F ARM mbed board
GTsapparellas 6:3758685f4b75 13 *
GTsapparellas 6:3758685f4b75 14 * LoRa shield: Semtech SX1272MB2xAS
GTsapparellas 6:3758685f4b75 15 *
GTsapparellas 6:3758685f4b75 16 * IoT Cloud Server: The Things Network (Europe EU-868.1 frequency band)
GTsapparellas 6:3758685f4b75 17 *
GTsapparellas 6:3758685f4b75 18 * API Platform: All Things Talk Maker
GTsapparellas 6:3758685f4b75 19 *
GTsapparellas 6:3758685f4b75 20 * - Time-triggered program periodically sends playload data (including
GTsapparellas 6:3758685f4b75 21 * temperature, humidity, light intensity and soil moisture sensor parameters)
GTsapparellas 6:3758685f4b75 22 * by using FRDM-K64F ARM mbed board and Semtech SX1272MB2xAS as the LoRa Node.
GTsapparellas 6:3758685f4b75 23 *
GTsapparellas 6:3758685f4b75 24 * - DHT library and Digital Input pin used for the successful measurement
GTsapparellas 6:3758685f4b75 25 * of temperature and humidity sensor parameters.
GTsapparellas 6:3758685f4b75 26 *
GTsapparellas 6:3758685f4b75 27 * - Analog Input pins used for the successful employement of soil moisture and
GTsapparellas 6:3758685f4b75 28 * light intensity sensor parameters.
GTsapparellas 6:3758685f4b75 29 *
GTsapparellas 6:3758685f4b75 30 * - Semtech's SX1272Lib used for the successful configuration and set up of
GTsapparellas 6:3758685f4b75 31 * of SX1272MB2xAS LoRa shield.
GTsapparellas 6:3758685f4b75 32 *
GTsapparellas 6:3758685f4b75 33 * - IBM's LMiC library used for the successful implementation of LoRa modulation.
GTsapparellas 6:3758685f4b75 34 *
GTsapparellas 6:3758685f4b75 35 * - LoRa Node transmitting playload data directly to the single-channel Dragino
GTsapparellas 6:3758685f4b75 36 * LG01-P LoRa Gateway which is connected to The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 37 *
GTsapparellas 6:3758685f4b75 38 * - ABP (Activation By Personalization) selected as the activation method over
GTsapparellas 6:3758685f4b75 39 * The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 40 *
GTsapparellas 6:3758685f4b75 41 * - The Things Network Cloud Server makes playload data available online.
GTsapparellas 6:3758685f4b75 42 *
GTsapparellas 6:3758685f4b75 43 * - Through required integration, The Things Network Cloud Server passes
GTsapparellas 6:3758685f4b75 44 * playload data to All Things Talk Maker API which visualizes the data in
GTsapparellas 7:8ffc2f64b0f8 45 * a meaningful way for end-user's reference.
GTsapparellas 7:8ffc2f64b0f8 46 *
GTsapparellas 7:8ffc2f64b0f8 47 * - Fully reset device through RESET BUTTON pressed.
GTsapparellas 6:3758685f4b75 48 *
GTsapparellas 6:3758685f4b75 49 * @Author: Giorgos Tsapparellas
GTsapparellas 6:3758685f4b75 50 *
GTsapparellas 7:8ffc2f64b0f8 51 * Code available at: 1) GITHUB LINK
GTsapparellas 7:8ffc2f64b0f8 52 * 2) MBED LINK
GTsapparellas 6:3758685f4b75 53 *
GTsapparellas 7:8ffc2f64b0f8 54 * SEE readME.txt file for instructions of how to compile and run the program.
GTsapparellas 6:3758685f4b75 55 *
GTsapparellas 6:3758685f4b75 56 *******************************************************************************/
GTsapparellas 7:8ffc2f64b0f8 57 // ADD links above
GTsapparellas 6:3758685f4b75 58 // ADD LED FLASHING
GTsapparellas 7:8ffc2f64b0f8 59 // ADD to mbed
GTsapparellas 6:3758685f4b75 60 // ADD to git hub as well
GTsapparellas 7:8ffc2f64b0f8 61 // write readME.txt file
GTsapparellas 6:3758685f4b75 62 // TEST THE CODE IF OK
GTsapparellas 7:8ffc2f64b0f8 63 // fill in logbook
mluis 1:60184eda0066 64
GTsapparellas 6:3758685f4b75 65 #include <mbed.h>
GTsapparellas 6:3758685f4b75 66 #include <lmic.h>
GTsapparellas 6:3758685f4b75 67 #include <hal.h>
GTsapparellas 6:3758685f4b75 68 #include <SPI.h>
GTsapparellas 6:3758685f4b75 69 #include <DHT.h>
GTsapparellas 6:3758685f4b75 70 #include <debug.h>
mluis 0:a2929fa6e4f0 71
GTsapparellas 6:3758685f4b75 72 ///////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 73 // DEFINITION DECLARATIONS //
GTsapparellas 6:3758685f4b75 74 /////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 75
GTsapparellas 7:8ffc2f64b0f8 76 #define MAX_EU_CHANNELS 16 // Frequency channels automatically initialized for EU reqion.
GTsapparellas 6:3758685f4b75 77 #define SINGLE_CHANNEL_GATEWAY // Force it to use 868.1 MHz frequency band only due to Dragino LG01-P LoRa Gateway hardware limitation.
GTsapparellas 6:3758685f4b75 78 #define TRANSMIT_INTERVAL 1800 // Transmit interval in seconds, too often may get traffic ignored.
GTsapparellas 6:3758685f4b75 79 #define DEBUG_LEVEL 0 // Set debug level to 1 for outputting messages to the UART Terminal (e.g. Tera Term).
GTsapparellas 6:3758685f4b75 80 #define ACTIVATION_METHOD 0 // Set activation method to 0 for ABP (Activation By Personalization)
GTsapparellas 6:3758685f4b75 81 // Set activation method to 1 for OTAA (Over The Air Activation)
mluis 0:a2929fa6e4f0 82
GTsapparellas 6:3758685f4b75 83 ///////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 84 // GLOBAL VARIABLES DECLARATIONS //
GTsapparellas 6:3758685f4b75 85 /////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 86
GTsapparellas 6:3758685f4b75 87 // Transmit interval in seconds.
GTsapparellas 6:3758685f4b75 88 uint16_t transmit_interval = TRANSMIT_INTERVAL;
mluis 1:60184eda0066 89
GTsapparellas 7:8ffc2f64b0f8 90 // Static osjob_t sendjob variable used by loop function
GTsapparellas 7:8ffc2f64b0f8 91 static osjob_t sendjob;
GTsapparellas 7:8ffc2f64b0f8 92
GTsapparellas 7:8ffc2f64b0f8 93 // Unsigned integer packet counter used by transmit function.
GTsapparellas 7:8ffc2f64b0f8 94 unsigned int packetCounter = 1;
GTsapparellas 7:8ffc2f64b0f8 95
GTsapparellas 7:8ffc2f64b0f8 96 // Disable data rate adaption.
GTsapparellas 7:8ffc2f64b0f8 97 // Set to 1 in order to enable data rate adaption.
GTsapparellas 7:8ffc2f64b0f8 98 static const bit_t disableAdrMode = 0;
GTsapparellas 7:8ffc2f64b0f8 99
GTsapparellas 7:8ffc2f64b0f8 100 // Disable link check validadtion.
GTsapparellas 7:8ffc2f64b0f8 101 // Set to 1 in order to enable link check validation.
GTsapparellas 7:8ffc2f64b0f8 102 static const bit_t disableLinkCheck = 0;
GTsapparellas 7:8ffc2f64b0f8 103
GTsapparellas 7:8ffc2f64b0f8 104 // Set LoRa Node's transmission power to 14 dBm.
GTsapparellas 7:8ffc2f64b0f8 105 static const s1_t txPower = 14;
GTsapparellas 7:8ffc2f64b0f8 106
GTsapparellas 7:8ffc2f64b0f8 107 // Set LoRa Node's network id to 0x1.
GTsapparellas 7:8ffc2f64b0f8 108 static const u4_t NETID = 0x1;
GTsapparellas 7:8ffc2f64b0f8 109
GTsapparellas 7:8ffc2f64b0f8 110 /* LMiC frame initializations. */
GTsapparellas 7:8ffc2f64b0f8 111
GTsapparellas 6:3758685f4b75 112 // Playload frame length of size 8.
GTsapparellas 7:8ffc2f64b0f8 113 static const u1_t LMIC_FRAME_LENGTH = 8;
GTsapparellas 7:8ffc2f64b0f8 114
GTsapparellas 7:8ffc2f64b0f8 115 // Set listening port to 1.
GTsapparellas 7:8ffc2f64b0f8 116 static const u1_t LMIC_PORT = 1;
GTsapparellas 7:8ffc2f64b0f8 117
GTsapparellas 7:8ffc2f64b0f8 118 // Disable confirmation of transmitted LMiC data.
GTsapparellas 7:8ffc2f64b0f8 119 // Set to 1 in order to enable confirmation of transmitted LMiC data.
GTsapparellas 7:8ffc2f64b0f8 120 static const u1_t LMIC_CONFIRMED = 0;
GTsapparellas 6:3758685f4b75 121
GTsapparellas 6:3758685f4b75 122 #if ACTIVATION_METHOD == 1 // if OTAA (Over The Air Activation) is applied.
mluis 1:60184eda0066 123
GTsapparellas 6:3758685f4b75 124 // LoRaWAN Application identifier (AppEUI) associated with The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 125 static const u1_t APPEUI[8] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x00, 0xA4, 0x54 };
GTsapparellas 6:3758685f4b75 126
GTsapparellas 6:3758685f4b75 127 // LoRaWAN unique device ID (DevEUI) associated with The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 128 static const u1_t DEVEUI[8] = { 0x00, 0x1D, 0x45, 0x32, 0xEC, 0xA8, 0x01, 0x59 };
mluis 1:60184eda0066 129
mluis 1:60184eda0066 130 #endif
mluis 1:60184eda0066 131
GTsapparellas 6:3758685f4b75 132 // Acquired activation method
GTsapparellas 6:3758685f4b75 133 #if ACTIVATION_METHOD == 0 // if ABP (Activation By Personalization) is applied.
mluis 1:60184eda0066 134
GTsapparellas 6:3758685f4b75 135 // LoRaWAN network session key (NwkSKey) associated with The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 136 static const u1_t NWKSKEY[16] = { 0xDF, 0x9B, 0xB1, 0x30, 0xE8, 0x33, 0x42, 0x76, 0x33, 0x0C, 0x88, 0xBB, 0x30, 0xE2, 0xC2, 0xE9 };
mluis 1:60184eda0066 137
GTsapparellas 6:3758685f4b75 138 // LoRaWAN application session key (AppSKey) associated with The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 139 static const u1_t APPSKEY[16] = { 0xE0, 0x52, 0x18, 0x15, 0x0B, 0xE1, 0xEF, 0x1F, 0xAF, 0x8C, 0x8A, 0x31, 0x09, 0xB9, 0xAB, 0x9C };
mluis 1:60184eda0066 140
GTsapparellas 6:3758685f4b75 141 // LoRaWAN end-device address (DevAddr) associated with The Things Network Cloud Server.
GTsapparellas 6:3758685f4b75 142 static const u4_t DEVADDR = 0x26011B39 ;
mluis 1:60184eda0066 143
mluis 1:60184eda0066 144 #endif
mluis 0:a2929fa6e4f0 145
GTsapparellas 6:3758685f4b75 146 /*On board's LEDs Declaration
GTsapparellas 6:3758685f4b75 147 DigitalOut RED_LED(PTB22); // PTB22 = Red pin -- Indicates an error occur
GTsapparellas 6:3758685f4b75 148 DigitalOut GREEN_LED(PTE26); // PTE26 = Green pin -- Indicates transmission is in progress
GTsapparellas 6:3758685f4b75 149 DigitalOut BLUE_LED(PTB21); // PTB21 = Blue pin -- Indicates MCU is sleeping
GTsapparellas 6:3758685f4b75 150 */
GTsapparellas 6:3758685f4b75 151
GTsapparellas 7:8ffc2f64b0f8 152 /* Sensor declarations. */
GTsapparellas 7:8ffc2f64b0f8 153
GTsapparellas 6:3758685f4b75 154 // Digital Input pin of temperature and humidity sensor set to D6.
GTsapparellas 6:3758685f4b75 155 DHT sensorTempHum(D6, DHT11);
GTsapparellas 6:3758685f4b75 156
GTsapparellas 6:3758685f4b75 157 // Analog Input pin of light intensity sensor set to A1.
GTsapparellas 6:3758685f4b75 158 AnalogIn sensorLight(A1);
GTsapparellas 6:3758685f4b75 159
GTsapparellas 6:3758685f4b75 160 // Analog Input pin of soil moisture sensor set to A3.
GTsapparellas 6:3758685f4b75 161 AnalogIn sensorSoilMoisture(A3);
mluis 0:a2929fa6e4f0 162
GTsapparellas 6:3758685f4b75 163 ///////////////////////////////////////////////////
GTsapparellas 7:8ffc2f64b0f8 164 // LMiC APPLICATION CALLBACKS //
GTsapparellas 7:8ffc2f64b0f8 165 /////////////////////////////////////////////////
GTsapparellas 7:8ffc2f64b0f8 166
GTsapparellas 7:8ffc2f64b0f8 167 /*
GTsapparellas 7:8ffc2f64b0f8 168 * os_getArtEui callback of type void.
GTsapparellas 7:8ffc2f64b0f8 169 *
GTsapparellas 7:8ffc2f64b0f8 170 * Copies application ID (8 bytes) of The Things Network Cloud Server into
GTsapparellas 7:8ffc2f64b0f8 171 * memory if OTAA(Over The Air Activation) is applied.
GTsapparellas 7:8ffc2f64b0f8 172 *
GTsapparellas 7:8ffc2f64b0f8 173 * Input parameters: unsigned char buf of APPEUI.
GTsapparellas 7:8ffc2f64b0f8 174 *
GTsapparellas 7:8ffc2f64b0f8 175 */
GTsapparellas 7:8ffc2f64b0f8 176 void os_getArtEui (u1_t* buf) {
GTsapparellas 7:8ffc2f64b0f8 177 #if ACTIVATION_METHOD == 1 // if OTAA (Over The Air Activation) is applied.
GTsapparellas 7:8ffc2f64b0f8 178 memcpy(buf, APPEUI, 8);
GTsapparellas 7:8ffc2f64b0f8 179 #endif
GTsapparellas 7:8ffc2f64b0f8 180 }// end of os_getArtEui callback.
GTsapparellas 7:8ffc2f64b0f8 181
GTsapparellas 7:8ffc2f64b0f8 182 /*
GTsapparellas 7:8ffc2f64b0f8 183 * os_getDevEui callback of type void.
GTsapparellas 7:8ffc2f64b0f8 184 *
GTsapparellas 7:8ffc2f64b0f8 185 * Copies device ID (8 bytes) of The Things Network Cloud Server into
GTsapparellas 7:8ffc2f64b0f8 186 * memory if OTAA(Over The Air Activation) is applied.
GTsapparellas 7:8ffc2f64b0f8 187 *
GTsapparellas 7:8ffc2f64b0f8 188 * Input parameters: unsigned char buf of DEVEUI.
GTsapparellas 7:8ffc2f64b0f8 189 *
GTsapparellas 7:8ffc2f64b0f8 190 */
GTsapparellas 7:8ffc2f64b0f8 191 void os_getDevEui (u1_t* buf) {
GTsapparellas 7:8ffc2f64b0f8 192 #if ACTIVATION_METHOD == 1 // if OTAA (Over The Air Activation) is applied.
GTsapparellas 7:8ffc2f64b0f8 193 memcpy(buf, DEVEUI, 8);
GTsapparellas 7:8ffc2f64b0f8 194 #endif
GTsapparellas 7:8ffc2f64b0f8 195 }// end of os_getDevEui callback.
GTsapparellas 7:8ffc2f64b0f8 196
GTsapparellas 7:8ffc2f64b0f8 197 /*
GTsapparellas 7:8ffc2f64b0f8 198 * os_getDevKey callback of type void.
GTsapparellas 7:8ffc2f64b0f8 199 *
GTsapparellas 7:8ffc2f64b0f8 200 * Copies device network session ID (16 bytes) of The Things Network Cloud Server
GTsapparellas 7:8ffc2f64b0f8 201 * into memory.
GTsapparellas 7:8ffc2f64b0f8 202 *
GTsapparellas 7:8ffc2f64b0f8 203 * Input parameters: unsigned char buf of NWKSKEY.
GTsapparellas 7:8ffc2f64b0f8 204 *
GTsapparellas 7:8ffc2f64b0f8 205 */
GTsapparellas 7:8ffc2f64b0f8 206 void os_getDevKey (u1_t* buf) {
GTsapparellas 7:8ffc2f64b0f8 207 memcpy(buf, NWKSKEY, 16);
GTsapparellas 7:8ffc2f64b0f8 208 }// end of os_getDevKey callback.
GTsapparellas 7:8ffc2f64b0f8 209
GTsapparellas 7:8ffc2f64b0f8 210 /*
GTsapparellas 7:8ffc2f64b0f8 211 * onEvent callback of type void.
GTsapparellas 7:8ffc2f64b0f8 212 *
GTsapparellas 7:8ffc2f64b0f8 213 * Outputs UART message depending on
GTsapparellas 7:8ffc2f64b0f8 214 * related event.
GTsapparellas 7:8ffc2f64b0f8 215 *
GTsapparellas 7:8ffc2f64b0f8 216 * NOTICE THAT: Not all events are being
GTsapparellas 7:8ffc2f64b0f8 217 * used due to significant set up
GTsapparellas 7:8ffc2f64b0f8 218 * of LMiC environment.
GTsapparellas 7:8ffc2f64b0f8 219 *
GTsapparellas 7:8ffc2f64b0f8 220 * Input parameters: ev_t event.
GTsapparellas 7:8ffc2f64b0f8 221 *
GTsapparellas 7:8ffc2f64b0f8 222 */
GTsapparellas 7:8ffc2f64b0f8 223 void onEvent (ev_t ev) {
GTsapparellas 7:8ffc2f64b0f8 224 //debug_event(ev);
GTsapparellas 7:8ffc2f64b0f8 225
GTsapparellas 7:8ffc2f64b0f8 226 switch(ev) { // Switch events.
GTsapparellas 7:8ffc2f64b0f8 227 case EV_SCAN_TIMEOUT:
GTsapparellas 7:8ffc2f64b0f8 228 printf("EV_SCAN_TIMEOUT\n"); // Scan timeout.
GTsapparellas 7:8ffc2f64b0f8 229 break;
GTsapparellas 7:8ffc2f64b0f8 230 case EV_BEACON_FOUND:
GTsapparellas 7:8ffc2f64b0f8 231 printf("EV_BEACON_FOUND\n"); // Beacon found.
GTsapparellas 7:8ffc2f64b0f8 232 break;
GTsapparellas 7:8ffc2f64b0f8 233 case EV_BEACON_MISSED:
GTsapparellas 7:8ffc2f64b0f8 234 printf("EV_BEACON_MISSED\n"); // Beacon missed.
GTsapparellas 7:8ffc2f64b0f8 235 break;
GTsapparellas 7:8ffc2f64b0f8 236 case EV_BEACON_TRACKED:
GTsapparellas 7:8ffc2f64b0f8 237 printf("EV_BEACON_TRACKED\n"); // Beacon tracked.
GTsapparellas 7:8ffc2f64b0f8 238 break;
GTsapparellas 7:8ffc2f64b0f8 239 case EV_JOINING:
GTsapparellas 7:8ffc2f64b0f8 240 printf("EV_JOINING\n"); // Joining the network.
GTsapparellas 7:8ffc2f64b0f8 241 break;
GTsapparellas 7:8ffc2f64b0f8 242 case EV_JOINED:
GTsapparellas 7:8ffc2f64b0f8 243 printf("EV_JOINED\n"); // Network joined.
GTsapparellas 7:8ffc2f64b0f8 244 break;
GTsapparellas 7:8ffc2f64b0f8 245 case EV_RFU1:
GTsapparellas 7:8ffc2f64b0f8 246 printf("EV_RFU1\n"); // RFU1 event.
GTsapparellas 7:8ffc2f64b0f8 247 break;
GTsapparellas 7:8ffc2f64b0f8 248 case EV_JOIN_FAILED:
GTsapparellas 7:8ffc2f64b0f8 249 printf("EV_JOIN_FAILED\n"); // Joining failed.
GTsapparellas 7:8ffc2f64b0f8 250 break;
GTsapparellas 7:8ffc2f64b0f8 251 case EV_REJOIN_FAILED:
GTsapparellas 7:8ffc2f64b0f8 252 printf("EV_REJOIN_FAILED\n"); // Re-joining failed.
GTsapparellas 7:8ffc2f64b0f8 253 break;
GTsapparellas 7:8ffc2f64b0f8 254 case EV_TXCOMPLETE:
GTsapparellas 7:8ffc2f64b0f8 255 printf("EV_TXCOMPLETE (waiting for RX windows)\n"); // Transmission complete.
GTsapparellas 7:8ffc2f64b0f8 256 if (LMIC.txrxFlags & TXRX_ACK) // Check if acknowledgment received.
GTsapparellas 7:8ffc2f64b0f8 257 {
GTsapparellas 7:8ffc2f64b0f8 258 printf("Received ack\n");
GTsapparellas 7:8ffc2f64b0f8 259 }
GTsapparellas 7:8ffc2f64b0f8 260 if(LMIC.dataLen) // Output playload's data length.
GTsapparellas 7:8ffc2f64b0f8 261 {
GTsapparellas 7:8ffc2f64b0f8 262 printf("Received ");
GTsapparellas 7:8ffc2f64b0f8 263 printf("%u", LMIC.dataLen);
GTsapparellas 7:8ffc2f64b0f8 264 printf(" bytes of payload\n");
GTsapparellas 7:8ffc2f64b0f8 265 }
GTsapparellas 7:8ffc2f64b0f8 266 break;
GTsapparellas 7:8ffc2f64b0f8 267 case EV_LOST_TSYNC:
GTsapparellas 7:8ffc2f64b0f8 268 printf("EV_LOST_TSYNC\n"); // Lost transmision sync.
GTsapparellas 7:8ffc2f64b0f8 269 break;
GTsapparellas 7:8ffc2f64b0f8 270 case EV_RESET:
GTsapparellas 7:8ffc2f64b0f8 271 printf("EV_RESET\n"); // Reset.
GTsapparellas 7:8ffc2f64b0f8 272 break;
GTsapparellas 7:8ffc2f64b0f8 273 case EV_RXCOMPLETE:
GTsapparellas 7:8ffc2f64b0f8 274 printf("EV_RXCOMPLETE\n"); // Reception complete.
GTsapparellas 7:8ffc2f64b0f8 275 break;
GTsapparellas 7:8ffc2f64b0f8 276 case EV_LINK_DEAD:
GTsapparellas 7:8ffc2f64b0f8 277 printf("EV_LINK_DEAD\n"); // Link dead.
GTsapparellas 7:8ffc2f64b0f8 278 break;
GTsapparellas 7:8ffc2f64b0f8 279 case EV_LINK_ALIVE:
GTsapparellas 7:8ffc2f64b0f8 280 printf("EV_LINK_ALIVE\n"); // Link alive.
GTsapparellas 7:8ffc2f64b0f8 281 break;
GTsapparellas 7:8ffc2f64b0f8 282 default:
GTsapparellas 7:8ffc2f64b0f8 283 printf("Unknown event\n"); // Default unknown event.
GTsapparellas 7:8ffc2f64b0f8 284 break;
GTsapparellas 7:8ffc2f64b0f8 285 }
GTsapparellas 7:8ffc2f64b0f8 286 }// end of onEvent callback.
GTsapparellas 7:8ffc2f64b0f8 287
GTsapparellas 7:8ffc2f64b0f8 288 ///////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 289 // LOCAL FUNCTIONS DECLARATIONS //
GTsapparellas 6:3758685f4b75 290 /////////////////////////////////////////////////
GTsapparellas 6:3758685f4b75 291
GTsapparellas 6:3758685f4b75 292 /*
GTsapparellas 7:8ffc2f64b0f8 293 * setUp function of type void.
GTsapparellas 7:8ffc2f64b0f8 294 *
GTsapparellas 7:8ffc2f64b0f8 295 * Initializes mbed OS, LMiC OS as well as
GTsapparellas 7:8ffc2f64b0f8 296 * disabling all channels but 0 (868.1 MHz) for single-channel
GTsapparellas 7:8ffc2f64b0f8 297 * gateway compatibility.
GTsapparellas 7:8ffc2f64b0f8 298 *
GTsapparellas 7:8ffc2f64b0f8 299 * Input parameters: None.
GTsapparellas 7:8ffc2f64b0f8 300 *
GTsapparellas 7:8ffc2f64b0f8 301 */
GTsapparellas 7:8ffc2f64b0f8 302 void setUp() {
GTsapparellas 7:8ffc2f64b0f8 303
GTsapparellas 7:8ffc2f64b0f8 304 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 305 printf("IoT smart monitoring device for agriculture using LoRaWAN technology\n\n");
GTsapparellas 7:8ffc2f64b0f8 306 #endif
GTsapparellas 7:8ffc2f64b0f8 307 // Initializes OS.
GTsapparellas 7:8ffc2f64b0f8 308 os_init();
GTsapparellas 7:8ffc2f64b0f8 309
GTsapparellas 7:8ffc2f64b0f8 310 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 311 printf("OS_INIT\n\n");
GTsapparellas 7:8ffc2f64b0f8 312 #endif
GTsapparellas 7:8ffc2f64b0f8 313
GTsapparellas 7:8ffc2f64b0f8 314 // Reset the MAC state. Session and pending data transfers are being discarded.
GTsapparellas 7:8ffc2f64b0f8 315 LMIC_reset();
GTsapparellas 7:8ffc2f64b0f8 316
GTsapparellas 7:8ffc2f64b0f8 317 // Set static session parameters. Instead of dynamically establishing a session
GTsapparellas 7:8ffc2f64b0f8 318 // by joining the network, precomputed session parameters are be provided.
GTsapparellas 7:8ffc2f64b0f8 319 LMIC_setSession (NETID, DEVADDR, (uint8_t*)NWKSKEY, (uint8_t*)APPSKEY);
GTsapparellas 7:8ffc2f64b0f8 320
GTsapparellas 7:8ffc2f64b0f8 321 // Disable data rate adaptation.
GTsapparellas 7:8ffc2f64b0f8 322 LMIC_setAdrMode(disableAdrMode);
GTsapparellas 7:8ffc2f64b0f8 323
GTsapparellas 7:8ffc2f64b0f8 324 // Disable link check validation.
GTsapparellas 7:8ffc2f64b0f8 325 LMIC_setLinkCheckMode(disableLinkCheck);
GTsapparellas 7:8ffc2f64b0f8 326
GTsapparellas 7:8ffc2f64b0f8 327 // Disable beacon tracking.
GTsapparellas 7:8ffc2f64b0f8 328 LMIC_disableTracking();
GTsapparellas 7:8ffc2f64b0f8 329
GTsapparellas 7:8ffc2f64b0f8 330 // Stop listening for downstream data (periodical reception) as LoRa Node
GTsapparellas 7:8ffc2f64b0f8 331 // is only transmitting data to the Gateway.
GTsapparellas 7:8ffc2f64b0f8 332 LMIC_stopPingable();
GTsapparellas 7:8ffc2f64b0f8 333
GTsapparellas 7:8ffc2f64b0f8 334 // Set data rate and transmit power.
GTsapparellas 7:8ffc2f64b0f8 335 LMIC_setDrTxpow(DR_SF7,txPower);
GTsapparellas 7:8ffc2f64b0f8 336
GTsapparellas 7:8ffc2f64b0f8 337 //fflush(stdout);
GTsapparellas 7:8ffc2f64b0f8 338
GTsapparellas 7:8ffc2f64b0f8 339 // If single-channel gateway is being used disable
GTsapparellas 7:8ffc2f64b0f8 340 // all the other channels except channel 0.
GTsapparellas 7:8ffc2f64b0f8 341 #ifdef SINGLE_CHANNEL_GATEWAY
GTsapparellas 7:8ffc2f64b0f8 342 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 343 printf(" ----->Disabling all channels but 0 (868.1 MHz) for single-channel gateway compatibility\n\n\n");
GTsapparellas 7:8ffc2f64b0f8 344 #endif
GTsapparellas 7:8ffc2f64b0f8 345
GTsapparellas 7:8ffc2f64b0f8 346 for (int i=1; i < MAX_EU_CHANNELS; i++)
GTsapparellas 7:8ffc2f64b0f8 347 {
GTsapparellas 7:8ffc2f64b0f8 348 LMIC_disableChannel(i);
GTsapparellas 7:8ffc2f64b0f8 349 }
GTsapparellas 7:8ffc2f64b0f8 350 #endif
GTsapparellas 7:8ffc2f64b0f8 351
GTsapparellas 7:8ffc2f64b0f8 352 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 353 printf("//////////Entering into TIME-TRIGGERED packet sending through LoRaWAN//////////\n");
GTsapparellas 7:8ffc2f64b0f8 354 printf("---------------------Packets to be sent every %u seconds----------------------\n\n", transmit_interval);
GTsapparellas 7:8ffc2f64b0f8 355 #endif
GTsapparellas 7:8ffc2f64b0f8 356 }// end of setUp function.
GTsapparellas 7:8ffc2f64b0f8 357
GTsapparellas 7:8ffc2f64b0f8 358 /*
GTsapparellas 6:3758685f4b75 359 * getTemperatureHumidity function of type void.
GTsapparellas 6:3758685f4b75 360 *
GTsapparellas 6:3758685f4b75 361 * Gets temperature (celcius) and humidity (relative humidity %)
GTsapparellas 6:3758685f4b75 362 * measurements using DHT library. Otherwise, print an error.
GTsapparellas 6:3758685f4b75 363 *
GTsapparellas 6:3758685f4b75 364 * Input parameters: float temperature
GTsapparellas 6:3758685f4b75 365 * float humidity
GTsapparellas 6:3758685f4b75 366 *
GTsapparellas 6:3758685f4b75 367 */
GTsapparellas 6:3758685f4b75 368 void getTemperatureHumidity(float& temperature, float& humidity) {
mluis 0:a2929fa6e4f0 369
GTsapparellas 6:3758685f4b75 370 // Set err variable to 0 (none).
GTsapparellas 6:3758685f4b75 371 uint8_t err = ERROR_NONE;
GTsapparellas 6:3758685f4b75 372 // Set humidity variable to 0.
GTsapparellas 6:3758685f4b75 373 humidity = 0.0f;
GTsapparellas 6:3758685f4b75 374 // Set temperature variable to 0.
GTsapparellas 6:3758685f4b75 375 temperature = 0.0f;
GTsapparellas 6:3758685f4b75 376
GTsapparellas 6:3758685f4b75 377 // Store sensor data (40 bits(16-bit temperature, 16-bit humidity and 8-bit
GTsapparellas 6:3758685f4b75 378 // CRC checksum)) into err variable.
GTsapparellas 6:3758685f4b75 379 err = sensorTempHum.readData();
GTsapparellas 6:3758685f4b75 380
GTsapparellas 6:3758685f4b75 381 if (err == ERROR_NONE) // if err equals to 0.
GTsapparellas 6:3758685f4b75 382 {
GTsapparellas 6:3758685f4b75 383 // Store float temperature value in celcius.
GTsapparellas 6:3758685f4b75 384 temperature = sensorTempHum.ReadTemperature(CELCIUS);
GTsapparellas 6:3758685f4b75 385 // Store float humidity value.
GTsapparellas 6:3758685f4b75 386 humidity = sensorTempHum.ReadHumidity();
GTsapparellas 6:3758685f4b75 387
GTsapparellas 6:3758685f4b75 388 // Output temperature and humidity values on UART Terminal
GTsapparellas 6:3758685f4b75 389 #if DEBUG_LEVEL == 1
GTsapparellas 6:3758685f4b75 390 printf("Temperature: %4.2f Celsius \r\n", temperature);
GTsapparellas 6:3758685f4b75 391 printf("Humidity: %4.2f % Relative Humidity \r\n", humidity);
GTsapparellas 6:3758685f4b75 392 #endif
GTsapparellas 6:3758685f4b75 393 }
GTsapparellas 6:3758685f4b75 394 else // if err occurs.
GTsapparellas 6:3758685f4b75 395 {
GTsapparellas 6:3758685f4b75 396 // Output error message on UART Terminal and flash the RED LED.
GTsapparellas 6:3758685f4b75 397 #if DEBUG_LEVEL == 1
GTsapparellas 6:3758685f4b75 398 printf("Error: %d\r\n", err);
GTsapparellas 6:3758685f4b75 399 //RED_LED = !RED_LED;
GTsapparellas 6:3758685f4b75 400 #endif
GTsapparellas 6:3758685f4b75 401 }
GTsapparellas 6:3758685f4b75 402 }// end of getTemperatureHumidity function.
mluis 0:a2929fa6e4f0 403
GTsapparellas 6:3758685f4b75 404 /*
GTsapparellas 6:3758685f4b75 405 * getLightIntensity function of type void.
GTsapparellas 6:3758685f4b75 406 *
GTsapparellas 6:3758685f4b75 407 * Gets the light's intensity analogue value at first instance
GTsapparellas 6:3758685f4b75 408 * and then converts it using 16-bit ADC converter into voltage
GTsapparellas 6:3758685f4b75 409 * counting from 0.0 to 5.0.
GTsapparellas 6:3758685f4b75 410 *
GTsapparellas 6:3758685f4b75 411 * Input parameters: float lightIntensityVoltage
GTsapparellas 6:3758685f4b75 412 *
GTsapparellas 6:3758685f4b75 413 */
GTsapparellas 6:3758685f4b75 414 void getLightIntensity(float& lightIntensityVoltage) {
GTsapparellas 6:3758685f4b75 415
GTsapparellas 6:3758685f4b75 416 // Set light intensity voltage variable to 0.
GTsapparellas 6:3758685f4b75 417 lightIntensityVoltage = 0.0f;
GTsapparellas 6:3758685f4b75 418 // Set light intensity analogue value to 0.
GTsapparellas 6:3758685f4b75 419 uint16_t lightIntensityAnalogue = 0;
GTsapparellas 6:3758685f4b75 420
GTsapparellas 6:3758685f4b75 421 // Read light intensity 16-bit analogue value.
GTsapparellas 6:3758685f4b75 422 lightIntensityAnalogue = sensorLight.read_u16();
GTsapparellas 6:3758685f4b75 423 //Convert the light intensity analog reading (which goes from 0 - 65536) to a voltage (0 - 5V).
GTsapparellas 6:3758685f4b75 424 lightIntensityVoltage = (float) lightIntensityAnalogue*(5.0/65536.0);
GTsapparellas 6:3758685f4b75 425
GTsapparellas 6:3758685f4b75 426 // Output light intensity voltage as well as resistance value on UART Terminal.
GTsapparellas 6:3758685f4b75 427 #if DEBUG_LEVEL == 1
GTsapparellas 6:3758685f4b75 428 float resistance = 0.0f;
GTsapparellas 6:3758685f4b75 429 // Groove's calculation for resistance value.
GTsapparellas 6:3758685f4b75 430 resistance = (float)(65536-lightIntensityAnalogue)*10/lightIntensityAnalogue;
GTsapparellas 6:3758685f4b75 431 printf("Light Intensity: %2.2f Volts -- ", lightIntensityVoltage);
GTsapparellas 6:3758685f4b75 432 printf("Resistance: %2.2f Kiloohm \r\n", resistance);
GTsapparellas 6:3758685f4b75 433 #endif
GTsapparellas 6:3758685f4b75 434 }// end of getLightIntensity function.
mluis 0:a2929fa6e4f0 435
GTsapparellas 6:3758685f4b75 436 /*
GTsapparellas 6:3758685f4b75 437 * getSoilMoisture function of type void.
GTsapparellas 6:3758685f4b75 438 *
GTsapparellas 6:3758685f4b75 439 * Gets the soil's moisture analogue value at first instance
GTsapparellas 6:3758685f4b75 440 * and then converts it using 16-bit ADC converter into voltage
GTsapparellas 6:3758685f4b75 441 * counting from 0.0 to 5.0.
GTsapparellas 6:3758685f4b75 442 *
GTsapparellas 6:3758685f4b75 443 * Input parameters: float lightOutputVoltage
mluis 1:60184eda0066 444 *
GTsapparellas 6:3758685f4b75 445 */
GTsapparellas 6:3758685f4b75 446 void getSoilMoisture(float& soilMoistureVoltage) {
GTsapparellas 6:3758685f4b75 447
GTsapparellas 6:3758685f4b75 448 // Set soil moisture voltage variable to 0.
GTsapparellas 6:3758685f4b75 449 soilMoistureVoltage = 0.0f;
GTsapparellas 6:3758685f4b75 450 // Set soil moisture analogue value to 0.
GTsapparellas 6:3758685f4b75 451 uint16_t soilMoistureAnalogue = 0;
GTsapparellas 6:3758685f4b75 452
GTsapparellas 6:3758685f4b75 453 // Read soil moisture 16-bit analogue value.
GTsapparellas 6:3758685f4b75 454 soilMoistureAnalogue = sensorSoilMoisture.read_u16();
GTsapparellas 7:8ffc2f64b0f8 455 // Convert the soil moisture analog reading (which goes from 0 - 65536) to a voltage (0 - 5V).
GTsapparellas 6:3758685f4b75 456 soilMoistureVoltage = (float) soilMoistureAnalogue*(5.0/65536.0);
GTsapparellas 6:3758685f4b75 457
GTsapparellas 6:3758685f4b75 458 // Output soil moisture voltage as well as soil moisture analogue value on UART Terminal.
GTsapparellas 6:3758685f4b75 459 #if DEBUG_LEVEL == 1
GTsapparellas 6:3758685f4b75 460 printf("Soil Moisture: %2.2f Volts -- ", soilMoistureVoltage);
GTsapparellas 6:3758685f4b75 461 printf("Analogue Value: %d \r\n", soilMoistureAnalogue);
GTsapparellas 6:3758685f4b75 462 #endif
GTsapparellas 6:3758685f4b75 463 }// end of getSoilMoisture function.
mluis 1:60184eda0066 464
GTsapparellas 7:8ffc2f64b0f8 465 /*
GTsapparellas 7:8ffc2f64b0f8 466 * transmit function of type void.
GTsapparellas 7:8ffc2f64b0f8 467 *
GTsapparellas 7:8ffc2f64b0f8 468 * Checking if channel is ready.
GTsapparellas 7:8ffc2f64b0f8 469 * If no, waiting until channel becomes free.
GTsapparellas 7:8ffc2f64b0f8 470 * If yes, calling getTemperatureHumidity,
GTsapparellas 7:8ffc2f64b0f8 471 * getLightIntensity and getSoilMoisture functions
GTsapparellas 7:8ffc2f64b0f8 472 * to gather measuring parameters. Then, prepares
GTsapparellas 7:8ffc2f64b0f8 473 * the LoRa packet and finally sending the packet
GTsapparellas 7:8ffc2f64b0f8 474 * using os_setTimedCallback LMiC callback.
GTsapparellas 7:8ffc2f64b0f8 475 *
GTsapparellas 7:8ffc2f64b0f8 476 * Input parameters: osjob_t* j
GTsapparellas 7:8ffc2f64b0f8 477 *
GTsapparellas 7:8ffc2f64b0f8 478 */
GTsapparellas 7:8ffc2f64b0f8 479 void transmit(osjob_t* j)
GTsapparellas 7:8ffc2f64b0f8 480 {
GTsapparellas 7:8ffc2f64b0f8 481 // Define sensor measuring parameters.
GTsapparellas 7:8ffc2f64b0f8 482 float temperature, humidity, lightIntensity, soilMoisture;
GTsapparellas 7:8ffc2f64b0f8 483
GTsapparellas 7:8ffc2f64b0f8 484 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 485 printf("txChannel: %u , Channel Ready? ", LMIC.txChnl);
GTsapparellas 6:3758685f4b75 486 #endif
GTsapparellas 7:8ffc2f64b0f8 487
GTsapparellas 7:8ffc2f64b0f8 488 if (LMIC.opmode & (1 << 7)) // Is channel ready for transmission?
GTsapparellas 6:3758685f4b75 489 {
GTsapparellas 6:3758685f4b75 490 printf("NO, waiting...\n\n");
GTsapparellas 6:3758685f4b75 491 }
GTsapparellas 6:3758685f4b75 492 else
GTsapparellas 6:3758685f4b75 493 {
GTsapparellas 7:8ffc2f64b0f8 494 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 495 printf("YES, sensor readings...\n\n");
GTsapparellas 7:8ffc2f64b0f8 496 #endif
GTsapparellas 7:8ffc2f64b0f8 497
GTsapparellas 7:8ffc2f64b0f8 498 // Gather sensor readings.
GTsapparellas 7:8ffc2f64b0f8 499 getTemperatureHumidity(temperature, humidity);
GTsapparellas 7:8ffc2f64b0f8 500 getLightIntensity(lightIntensity);
GTsapparellas 7:8ffc2f64b0f8 501 getSoilMoisture(soilMoisture);
GTsapparellas 6:3758685f4b75 502
GTsapparellas 7:8ffc2f64b0f8 503 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 504 printf(" ----->Preparing LoRa packet...\n");
GTsapparellas 7:8ffc2f64b0f8 505 #endif
GTsapparellas 7:8ffc2f64b0f8 506
GTsapparellas 7:8ffc2f64b0f8 507 // Prepare upstream data transmission at the next possible time.
GTsapparellas 7:8ffc2f64b0f8 508 // Multiply all sensor readings by 100.
GTsapparellas 7:8ffc2f64b0f8 509 int16_t temp = temperature*100;
GTsapparellas 7:8ffc2f64b0f8 510 int16_t hum = humidity*100;
GTsapparellas 7:8ffc2f64b0f8 511 int16_t light = lightIntensity*100;
GTsapparellas 7:8ffc2f64b0f8 512 int16_t soil = soilMoisture*100;
GTsapparellas 6:3758685f4b75 513
GTsapparellas 7:8ffc2f64b0f8 514 // Allocate measurements into LMIC frame array ready for transmission.
GTsapparellas 7:8ffc2f64b0f8 515 // Each sensor measurement allocates 2 positions in frame array.
GTsapparellas 7:8ffc2f64b0f8 516 // First, value is right shifted for 8 bits, while on the next
GTsapparellas 7:8ffc2f64b0f8 517 // array's position least significant bits are taken as the desired
GTsapparellas 7:8ffc2f64b0f8 518 // value for each sensor measurement.
GTsapparellas 7:8ffc2f64b0f8 519 // This procedure is required in order to send playload data
GTsapparellas 7:8ffc2f64b0f8 520 // to The Things Network Cloud Server.
GTsapparellas 7:8ffc2f64b0f8 521 // Data will then be converted in a meaningful way through
GTsapparellas 7:8ffc2f64b0f8 522 // All Things Talk ABCL custom JSON binary conversion script.
GTsapparellas 7:8ffc2f64b0f8 523 LMIC.frame[0] = temp >> 8;
GTsapparellas 7:8ffc2f64b0f8 524 LMIC.frame[1] = temp & 0xFF;
GTsapparellas 7:8ffc2f64b0f8 525 LMIC.frame[2] = hum >> 8;
GTsapparellas 7:8ffc2f64b0f8 526 LMIC.frame[3] = hum & 0xFF;
GTsapparellas 7:8ffc2f64b0f8 527 LMIC.frame[4] = light >> 8;
GTsapparellas 7:8ffc2f64b0f8 528 LMIC.frame[5] = light & 0xFF;
GTsapparellas 7:8ffc2f64b0f8 529 LMIC.frame[6] = soil >> 8;
GTsapparellas 7:8ffc2f64b0f8 530 LMIC.frame[7] = soil & 0xFF;
GTsapparellas 6:3758685f4b75 531
GTsapparellas 7:8ffc2f64b0f8 532 // Set the transmission data.
GTsapparellas 7:8ffc2f64b0f8 533 LMIC_setTxData2(LMIC_PORT, LMIC.frame, LMIC_FRAME_LENGTH, LMIC_CONFIRMED);
GTsapparellas 7:8ffc2f64b0f8 534
GTsapparellas 7:8ffc2f64b0f8 535 #if DEBUG_LEVEL == 1
GTsapparellas 7:8ffc2f64b0f8 536 printf(" ----->LoRa Packet READY\n\n");
GTsapparellas 7:8ffc2f64b0f8 537 printf(" ----->Sending LoRa packet %u of byte size %u\n\n", packetCounter++, LMIC_FRAME_LENGTH);
GTsapparellas 7:8ffc2f64b0f8 538 #endif
GTsapparellas 6:3758685f4b75 539 }
GTsapparellas 7:8ffc2f64b0f8 540 // Schedule a time-triggered job to run based on TRANSMIT_INTERVAL time value.
GTsapparellas 6:3758685f4b75 541 os_setTimedCallback(j, os_getTime()+sec2osticks(TRANSMIT_INTERVAL), transmit);
GTsapparellas 7:8ffc2f64b0f8 542
GTsapparellas 7:8ffc2f64b0f8 543 }// end of transmit function.
mluis 0:a2929fa6e4f0 544
GTsapparellas 7:8ffc2f64b0f8 545 /*
GTsapparellas 7:8ffc2f64b0f8 546 * loop function of type void.
GTsapparellas 7:8ffc2f64b0f8 547 *
GTsapparellas 7:8ffc2f64b0f8 548 * Calling transmit as well as os_runloop_once functions
GTsapparellas 7:8ffc2f64b0f8 549 * for a repeatedly time-triggered behaviour
GTsapparellas 7:8ffc2f64b0f8 550 * program execution.
GTsapparellas 7:8ffc2f64b0f8 551 *
GTsapparellas 7:8ffc2f64b0f8 552 * Input parameters: None.
GTsapparellas 7:8ffc2f64b0f8 553 *
GTsapparellas 7:8ffc2f64b0f8 554 */
GTsapparellas 7:8ffc2f64b0f8 555 void loop()
GTsapparellas 7:8ffc2f64b0f8 556 {
GTsapparellas 7:8ffc2f64b0f8 557 // Calling transmit local function for acquiring next transmission
GTsapparellas 7:8ffc2f64b0f8 558 // job of LoRa Node.
GTsapparellas 7:8ffc2f64b0f8 559 transmit(&sendjob);
mluis 0:a2929fa6e4f0 560
GTsapparellas 7:8ffc2f64b0f8 561 // Super loop running os_runloop_once LMiC callback in a time-triggered behaviour.
GTsapparellas 7:8ffc2f64b0f8 562 while(1)
GTsapparellas 7:8ffc2f64b0f8 563 {
GTsapparellas 7:8ffc2f64b0f8 564 // Calling LMiC os_runloop_once callback.
GTsapparellas 7:8ffc2f64b0f8 565 os_runloop_once();
GTsapparellas 7:8ffc2f64b0f8 566 // Delay of 20 ms.
GTsapparellas 7:8ffc2f64b0f8 567 wait_ms(20);
GTsapparellas 7:8ffc2f64b0f8 568 }
GTsapparellas 7:8ffc2f64b0f8 569 // Never arives here!
GTsapparellas 7:8ffc2f64b0f8 570
GTsapparellas 7:8ffc2f64b0f8 571 }// end of loop function.
GTsapparellas 6:3758685f4b75 572
GTsapparellas 7:8ffc2f64b0f8 573 /*
GTsapparellas 7:8ffc2f64b0f8 574 * main function of type integer.
GTsapparellas 7:8ffc2f64b0f8 575 *
GTsapparellas 7:8ffc2f64b0f8 576 * Calling setUp as well as loop functions
GTsapparellas 7:8ffc2f64b0f8 577 * for a repeatedly time-triggered behaviour
GTsapparellas 7:8ffc2f64b0f8 578 * program execution.
GTsapparellas 7:8ffc2f64b0f8 579 *
GTsapparellas 7:8ffc2f64b0f8 580 * Input parameters: integer argc.
GTsapparellas 7:8ffc2f64b0f8 581 * char **argv.
GTsapparellas 7:8ffc2f64b0f8 582 *
GTsapparellas 7:8ffc2f64b0f8 583 */
GTsapparellas 7:8ffc2f64b0f8 584 int main(int argc, char **argv)
GTsapparellas 7:8ffc2f64b0f8 585 {
GTsapparellas 7:8ffc2f64b0f8 586 // Calling setUp local function for OS initialization.
GTsapparellas 6:3758685f4b75 587 setUp();
GTsapparellas 7:8ffc2f64b0f8 588
GTsapparellas 7:8ffc2f64b0f8 589 // Super loop running loop local funcion in a time-triggered behaviour.
GTsapparellas 7:8ffc2f64b0f8 590 while(1)
GTsapparellas 7:8ffc2f64b0f8 591 {
GTsapparellas 7:8ffc2f64b0f8 592 loop();
GTsapparellas 7:8ffc2f64b0f8 593 }
GTsapparellas 7:8ffc2f64b0f8 594 // Never arrives here!
GTsapparellas 7:8ffc2f64b0f8 595
GTsapparellas 7:8ffc2f64b0f8 596 } // end of main function.