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:
Wed Apr 04 17:24:44 2018 +0000
Revision:
9:f3e9b3a6eded
Parent:
8:f307640ed331
Child:
10:0a4ad1388e05
version 1.0 (completed)

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