![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Updated version for LoraWan GEII IUT
Dependencies: Servo Cayenne-LPP
main.cpp@64:1e20d66960c3, 2022-03-04 (annotated)
- Committer:
- alainpegatoquet
- Date:
- Fri Mar 04 09:50:35 2022 +0000
- Revision:
- 64:1e20d66960c3
- Parent:
- 63:cd8ab5860303
Maj des drivers mbed-os et mbed-lora-radio-drv
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:7037ed05f54f | 1 | /** |
mbed_official | 0:7037ed05f54f | 2 | * Copyright (c) 2017, Arm Limited and affiliates. |
mbed_official | 0:7037ed05f54f | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbed_official | 0:7037ed05f54f | 4 | * |
mbed_official | 0:7037ed05f54f | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 0:7037ed05f54f | 6 | * you may not use this file except in compliance with the License. |
mbed_official | 0:7037ed05f54f | 7 | * You may obtain a copy of the License at |
mbed_official | 0:7037ed05f54f | 8 | * |
mbed_official | 0:7037ed05f54f | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 0:7037ed05f54f | 10 | * |
mbed_official | 0:7037ed05f54f | 11 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 0:7037ed05f54f | 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 0:7037ed05f54f | 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 0:7037ed05f54f | 14 | * See the License for the specific language governing permissions and |
mbed_official | 0:7037ed05f54f | 15 | * limitations under the License. |
mbed_official | 0:7037ed05f54f | 16 | */ |
mbed_official | 0:7037ed05f54f | 17 | #include <stdio.h> |
alainpegatoquet | 64:1e20d66960c3 | 18 | #include "driver_mbed_TH02.h" |
superphil06 | 57:5ec0379d69d6 | 19 | #include "CayenneLPP.h" |
mbed_official | 0:7037ed05f54f | 20 | #include "lorawan/LoRaWANInterface.h" |
mbed_official | 0:7037ed05f54f | 21 | #include "lorawan/system/lorawan_data_structures.h" |
mbed_official | 0:7037ed05f54f | 22 | #include "events/EventQueue.h" |
mbed_official | 0:7037ed05f54f | 23 | |
mbed_official | 0:7037ed05f54f | 24 | // Application helpers |
mbed_official | 0:7037ed05f54f | 25 | #include "DummySensor.h" |
mbed_official | 0:7037ed05f54f | 26 | #include "trace_helper.h" |
mbed_official | 0:7037ed05f54f | 27 | #include "lora_radio_helper.h" |
superphil06 | 58:81c66fac6476 | 28 | #include "Servo.h" |
mbed_official | 0:7037ed05f54f | 29 | |
mbed_official | 0:7037ed05f54f | 30 | using namespace events; |
mbed_official | 0:7037ed05f54f | 31 | |
mbed_official | 12:5015dfead3f2 | 32 | // Max payload size can be LORAMAC_PHY_MAXPAYLOAD. |
mbed_official | 12:5015dfead3f2 | 33 | // This example only communicates with much shorter messages (<30 bytes). |
mbed_official | 12:5015dfead3f2 | 34 | // If longer messages are used, these buffers must be changed accordingly. |
mbed_official | 12:5015dfead3f2 | 35 | uint8_t tx_buffer[30]; |
mbed_official | 12:5015dfead3f2 | 36 | uint8_t rx_buffer[30]; |
mbed_official | 0:7037ed05f54f | 37 | |
superphil06 | 57:5ec0379d69d6 | 38 | #define MAX_SIZE 200 // depends on spreading factor and frequency used |
superphil06 | 57:5ec0379d69d6 | 39 | |
superphil06 | 57:5ec0379d69d6 | 40 | CayenneLPP Payload(MAX_SIZE); |
superphil06 | 57:5ec0379d69d6 | 41 | |
alainpegatoquet | 64:1e20d66960c3 | 42 | // Dummy values |
superphil06 | 57:5ec0379d69d6 | 43 | float celsius = -4.1; |
superphil06 | 57:5ec0379d69d6 | 44 | float accel[] = {1.234, -1.234, 0}; |
superphil06 | 57:5ec0379d69d6 | 45 | float rh = 30; |
superphil06 | 57:5ec0379d69d6 | 46 | float hpa = 1014.1; |
superphil06 | 57:5ec0379d69d6 | 47 | float latitude = 42.3519; |
superphil06 | 57:5ec0379d69d6 | 48 | float longitude = -87.9094; |
superphil06 | 57:5ec0379d69d6 | 49 | float altitude=10; |
superphil06 | 57:5ec0379d69d6 | 50 | |
superphil06 | 57:5ec0379d69d6 | 51 | int size = 0; |
superphil06 | 57:5ec0379d69d6 | 52 | |
superphil06 | 57:5ec0379d69d6 | 53 | |
alainpegatoquet | 64:1e20d66960c3 | 54 | //DigitalOut Alarme (PC_13); // alarme LED output |
alainpegatoquet | 64:1e20d66960c3 | 55 | DigitalOut Alarme (LED2); // alarme LED output |
alainpegatoquet | 64:1e20d66960c3 | 56 | Servo Myservo(PA_7); // servomotor output |
alainpegatoquet | 64:1e20d66960c3 | 57 | //TH02 MyTH02 (I2C_SDA,I2C_SCL,TH02_I2C_ADDR<<1);// connect hsensor on RX2 TX2 |
alainpegatoquet | 64:1e20d66960c3 | 58 | |
mbed_official | 0:7037ed05f54f | 59 | /* |
mbed_official | 0:7037ed05f54f | 60 | * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing |
mbed_official | 0:7037ed05f54f | 61 | */ |
alainpegatoquet | 64:1e20d66960c3 | 62 | #define TX_TIMER 10000 |
mbed_official | 0:7037ed05f54f | 63 | |
mbed_official | 0:7037ed05f54f | 64 | /** |
mbed_official | 0:7037ed05f54f | 65 | * Maximum number of events for the event queue. |
mbed_official | 12:5015dfead3f2 | 66 | * 10 is the safe number for the stack events, however, if application |
mbed_official | 0:7037ed05f54f | 67 | * also uses the queue for whatever purposes, this number should be increased. |
mbed_official | 0:7037ed05f54f | 68 | */ |
alainpegatoquet | 64:1e20d66960c3 | 69 | #define MAX_NUMBER_OF_EVENTS 10 |
mbed_official | 0:7037ed05f54f | 70 | |
mbed_official | 0:7037ed05f54f | 71 | /** |
mbed_official | 0:7037ed05f54f | 72 | * Maximum number of retries for CONFIRMED messages before giving up |
mbed_official | 0:7037ed05f54f | 73 | */ |
mbed_official | 0:7037ed05f54f | 74 | #define CONFIRMED_MSG_RETRY_COUNTER 3 |
mbed_official | 0:7037ed05f54f | 75 | |
mbed_official | 0:7037ed05f54f | 76 | /** |
mbed_official | 0:7037ed05f54f | 77 | * Dummy pin for dummy sensor |
mbed_official | 0:7037ed05f54f | 78 | */ |
mbed_official | 0:7037ed05f54f | 79 | #define PC_9 0 |
mbed_official | 0:7037ed05f54f | 80 | |
mbed_official | 0:7037ed05f54f | 81 | |
mbed_official | 0:7037ed05f54f | 82 | /** |
mbed_official | 0:7037ed05f54f | 83 | * This event queue is the global event queue for both the |
mbed_official | 0:7037ed05f54f | 84 | * application and stack. To conserve memory, the stack is designed to run |
mbed_official | 0:7037ed05f54f | 85 | * in the same thread as the application and the application is responsible for |
mbed_official | 0:7037ed05f54f | 86 | * providing an event queue to the stack that will be used for ISR deferment as |
mbed_official | 0:7037ed05f54f | 87 | * well as application information event queuing. |
mbed_official | 0:7037ed05f54f | 88 | */ |
mbed_official | 46:a124538e2891 | 89 | static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE); |
mbed_official | 0:7037ed05f54f | 90 | |
mbed_official | 0:7037ed05f54f | 91 | /** |
mbed_official | 0:7037ed05f54f | 92 | * Event handler. |
mbed_official | 0:7037ed05f54f | 93 | * |
mbed_official | 0:7037ed05f54f | 94 | * This will be passed to the LoRaWAN stack to queue events for the |
mbed_official | 0:7037ed05f54f | 95 | * application which in turn drive the application. |
mbed_official | 0:7037ed05f54f | 96 | */ |
mbed_official | 0:7037ed05f54f | 97 | static void lora_event_handler(lorawan_event_t event); |
mbed_official | 0:7037ed05f54f | 98 | |
mbed_official | 0:7037ed05f54f | 99 | /** |
mbed_official | 46:a124538e2891 | 100 | * Constructing Mbed LoRaWANInterface and passing it the radio object from lora_radio_helper. |
mbed_official | 0:7037ed05f54f | 101 | */ |
mbed_official | 2:dc95ac6d6d4e | 102 | static LoRaWANInterface lorawan(radio); |
mbed_official | 0:7037ed05f54f | 103 | |
mbed_official | 0:7037ed05f54f | 104 | /** |
mbed_official | 0:7037ed05f54f | 105 | * Application specific callbacks |
mbed_official | 0:7037ed05f54f | 106 | */ |
mbed_official | 0:7037ed05f54f | 107 | static lorawan_app_callbacks_t callbacks; |
mbed_official | 0:7037ed05f54f | 108 | |
superphil06 | 58:81c66fac6476 | 109 | void servo(uint8_t uAngle) |
superphil06 | 58:81c66fac6476 | 110 | { |
superphil06 | 58:81c66fac6476 | 111 | |
alainpegatoquet | 64:1e20d66960c3 | 112 | } |
superphil06 | 58:81c66fac6476 | 113 | |
mbed_official | 0:7037ed05f54f | 114 | /** |
mbed_official | 0:7037ed05f54f | 115 | * Entry point for application |
mbed_official | 0:7037ed05f54f | 116 | */ |
mbed_official | 46:a124538e2891 | 117 | int main(void) |
mbed_official | 0:7037ed05f54f | 118 | { |
mbed_official | 0:7037ed05f54f | 119 | // setup tracing |
mbed_official | 0:7037ed05f54f | 120 | setup_trace(); |
mbed_official | 0:7037ed05f54f | 121 | |
mbed_official | 0:7037ed05f54f | 122 | // stores the status of a call to LoRaWAN protocol |
mbed_official | 0:7037ed05f54f | 123 | lorawan_status_t retcode; |
mbed_official | 0:7037ed05f54f | 124 | |
mbed_official | 0:7037ed05f54f | 125 | // Initialize LoRaWAN stack |
mbed_official | 2:dc95ac6d6d4e | 126 | if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { |
mbed_official | 0:7037ed05f54f | 127 | printf("\r\n LoRa initialization failed! \r\n"); |
mbed_official | 0:7037ed05f54f | 128 | return -1; |
mbed_official | 0:7037ed05f54f | 129 | } |
mbed_official | 0:7037ed05f54f | 130 | |
mbed_official | 0:7037ed05f54f | 131 | printf("\r\n Mbed LoRaWANStack initialized \r\n"); |
mbed_official | 0:7037ed05f54f | 132 | |
mbed_official | 0:7037ed05f54f | 133 | // prepare application callbacks |
mbed_official | 0:7037ed05f54f | 134 | callbacks.events = mbed::callback(lora_event_handler); |
mbed_official | 2:dc95ac6d6d4e | 135 | lorawan.add_app_callbacks(&callbacks); |
mbed_official | 0:7037ed05f54f | 136 | |
mbed_official | 0:7037ed05f54f | 137 | // Set number of retries in case of CONFIRMED messages |
mbed_official | 2:dc95ac6d6d4e | 138 | if (lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) |
mbed_official | 46:a124538e2891 | 139 | != LORAWAN_STATUS_OK) { |
mbed_official | 0:7037ed05f54f | 140 | printf("\r\n set_confirmed_msg_retries failed! \r\n\r\n"); |
mbed_official | 0:7037ed05f54f | 141 | return -1; |
mbed_official | 0:7037ed05f54f | 142 | } |
mbed_official | 0:7037ed05f54f | 143 | |
mbed_official | 0:7037ed05f54f | 144 | printf("\r\n CONFIRMED message retries : %d \r\n", |
mbed_official | 0:7037ed05f54f | 145 | CONFIRMED_MSG_RETRY_COUNTER); |
mbed_official | 0:7037ed05f54f | 146 | |
mbed_official | 0:7037ed05f54f | 147 | // Enable adaptive data rate |
mbed_official | 2:dc95ac6d6d4e | 148 | if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { |
mbed_official | 0:7037ed05f54f | 149 | printf("\r\n enable_adaptive_datarate failed! \r\n"); |
mbed_official | 0:7037ed05f54f | 150 | return -1; |
mbed_official | 0:7037ed05f54f | 151 | } |
mbed_official | 0:7037ed05f54f | 152 | |
mbed_official | 0:7037ed05f54f | 153 | printf("\r\n Adaptive data rate (ADR) - Enabled \r\n"); |
mbed_official | 0:7037ed05f54f | 154 | |
mbed_official | 2:dc95ac6d6d4e | 155 | retcode = lorawan.connect(); |
mbed_official | 0:7037ed05f54f | 156 | |
mbed_official | 0:7037ed05f54f | 157 | if (retcode == LORAWAN_STATUS_OK || |
mbed_official | 46:a124538e2891 | 158 | retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { |
mbed_official | 0:7037ed05f54f | 159 | } else { |
mbed_official | 0:7037ed05f54f | 160 | printf("\r\n Connection error, code = %d \r\n", retcode); |
mbed_official | 0:7037ed05f54f | 161 | return -1; |
mbed_official | 0:7037ed05f54f | 162 | } |
mbed_official | 0:7037ed05f54f | 163 | |
mbed_official | 0:7037ed05f54f | 164 | printf("\r\n Connection - In Progress ...\r\n"); |
mbed_official | 0:7037ed05f54f | 165 | |
mbed_official | 0:7037ed05f54f | 166 | // make your event queue dispatching events forever |
mbed_official | 0:7037ed05f54f | 167 | ev_queue.dispatch_forever(); |
mbed_official | 3:8c7198d1a2a1 | 168 | |
mbed_official | 3:8c7198d1a2a1 | 169 | return 0; |
mbed_official | 0:7037ed05f54f | 170 | } |
mbed_official | 0:7037ed05f54f | 171 | |
superphil06 | 61:3cb7cf8226cf | 172 | /************************************************************************************************************* |
mbed_official | 0:7037ed05f54f | 173 | * Sends a message to the Network Server |
superphil06 | 61:3cb7cf8226cf | 174 | *************************************************************************************************************/ |
mbed_official | 0:7037ed05f54f | 175 | static void send_message() |
alainpegatoquet | 64:1e20d66960c3 | 176 | { |
alainpegatoquet | 64:1e20d66960c3 | 177 | int iTime; |
alainpegatoquet | 64:1e20d66960c3 | 178 | uint16_t packet_len; |
superphil06 | 58:81c66fac6476 | 179 | int16_t retcode; |
superphil06 | 57:5ec0379d69d6 | 180 | |
alainpegatoquet | 64:1e20d66960c3 | 181 | float fTemp,fHumid; |
mbed_official | 0:7037ed05f54f | 182 | |
alainpegatoquet | 64:1e20d66960c3 | 183 | // Read Sensor temp and humidity values |
alainpegatoquet | 64:1e20d66960c3 | 184 | fTemp = myTH02.ReadTemperature(); |
alainpegatoquet | 64:1e20d66960c3 | 185 | printf("Temp=%.2f\t",fTemp); |
alainpegatoquet | 64:1e20d66960c3 | 186 | fHumid = myTH02.ReadHumidity(); |
alainpegatoquet | 64:1e20d66960c3 | 187 | printf("Humidity=%.2f\n",fHumid); |
alainpegatoquet | 64:1e20d66960c3 | 188 | |
alainpegatoquet | 64:1e20d66960c3 | 189 | // Payload is in Cayenne format |
superphil06 | 57:5ec0379d69d6 | 190 | Payload.reset(); |
alainpegatoquet | 64:1e20d66960c3 | 191 | size = Payload.addTemperature(1, (float) fTemp); // Add Temp in payload |
alainpegatoquet | 64:1e20d66960c3 | 192 | size = size+ Payload.addRelativeHumidity(2, fHumid); // Add Humidity in payload |
superphil06 | 58:81c66fac6476 | 193 | |
alainpegatoquet | 64:1e20d66960c3 | 194 | // Send complete message with cayenne format |
alainpegatoquet | 64:1e20d66960c3 | 195 | retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, Payload.getBuffer(), Payload.getSize(), |
alainpegatoquet | 64:1e20d66960c3 | 196 | MSG_UNCONFIRMED_FLAG); |
mbed_official | 0:7037ed05f54f | 197 | |
mbed_official | 0:7037ed05f54f | 198 | if (retcode < 0) { |
mbed_official | 0:7037ed05f54f | 199 | retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n") |
mbed_official | 46:a124538e2891 | 200 | : printf("\r\n send() - Error code %d \r\n", retcode); |
mbed_official | 26:f07f5febf97f | 201 | |
mbed_official | 26:f07f5febf97f | 202 | if (retcode == LORAWAN_STATUS_WOULD_BLOCK) { |
mbed_official | 26:f07f5febf97f | 203 | //retry in 3 seconds |
mbed_official | 26:f07f5febf97f | 204 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
mbed_official | 26:f07f5febf97f | 205 | ev_queue.call_in(3000, send_message); |
mbed_official | 26:f07f5febf97f | 206 | } |
mbed_official | 26:f07f5febf97f | 207 | } |
mbed_official | 0:7037ed05f54f | 208 | return; |
mbed_official | 0:7037ed05f54f | 209 | } |
mbed_official | 0:7037ed05f54f | 210 | |
mbed_official | 0:7037ed05f54f | 211 | printf("\r\n %d bytes scheduled for transmission \r\n", retcode); |
mbed_official | 12:5015dfead3f2 | 212 | memset(tx_buffer, 0, sizeof(tx_buffer)); |
mbed_official | 0:7037ed05f54f | 213 | } |
mbed_official | 0:7037ed05f54f | 214 | |
mbed_official | 0:7037ed05f54f | 215 | /** |
mbed_official | 0:7037ed05f54f | 216 | * Receive a message from the Network Server |
mbed_official | 0:7037ed05f54f | 217 | */ |
mbed_official | 0:7037ed05f54f | 218 | static void receive_message() |
alainpegatoquet | 64:1e20d66960c3 | 219 | { |
alainpegatoquet | 64:1e20d66960c3 | 220 | int num_port, iPosition=0,iIndex,iEtatAlarme; |
mbed_official | 47:b6d132f1079f | 221 | uint8_t port; |
mbed_official | 47:b6d132f1079f | 222 | int flags; |
mbed_official | 47:b6d132f1079f | 223 | int16_t retcode = lorawan.receive(rx_buffer, sizeof(rx_buffer), port, flags); |
mbed_official | 0:7037ed05f54f | 224 | |
mbed_official | 0:7037ed05f54f | 225 | if (retcode < 0) { |
mbed_official | 0:7037ed05f54f | 226 | printf("\r\n receive() - Error code %d \r\n", retcode); |
mbed_official | 0:7037ed05f54f | 227 | return; |
mbed_official | 0:7037ed05f54f | 228 | } |
mbed_official | 0:7037ed05f54f | 229 | |
mbed_official | 47:b6d132f1079f | 230 | printf(" RX Data on port %u (%d bytes): ", port, retcode); |
mbed_official | 0:7037ed05f54f | 231 | for (uint8_t i = 0; i < retcode; i++) { |
superphil06 | 59:7b58c5775a56 | 232 | printf("%02x", rx_buffer[i]); |
mbed_official | 0:7037ed05f54f | 233 | } |
alainpegatoquet | 64:1e20d66960c3 | 234 | |
alainpegatoquet | 64:1e20d66960c3 | 235 | // printf("\n test value=%d", port); |
alainpegatoquet | 64:1e20d66960c3 | 236 | // *****************************code todo here ******************************************** |
alainpegatoquet | 64:1e20d66960c3 | 237 | switch (port) { |
superphil06 | 61:3cb7cf8226cf | 238 | case 3: // control led |
alainpegatoquet | 64:1e20d66960c3 | 239 | printf("\n led=%d", (int)rx_buffer[0]); |
alainpegatoquet | 64:1e20d66960c3 | 240 | //if ((rx_buffer[0]-0x30)==0) |
alainpegatoquet | 64:1e20d66960c3 | 241 | if (rx_buffer[0]==0) |
alainpegatoquet | 64:1e20d66960c3 | 242 | iEtatAlarme=0; |
alainpegatoquet | 64:1e20d66960c3 | 243 | else |
alainpegatoquet | 64:1e20d66960c3 | 244 | iEtatAlarme=1; |
superphil06 | 62:10ba6387b44c | 245 | Alarme.write(iEtatAlarme); |
alainpegatoquet | 64:1e20d66960c3 | 246 | |
alainpegatoquet | 64:1e20d66960c3 | 247 | printf("\n alarme=%d",iEtatAlarme); |
alainpegatoquet | 64:1e20d66960c3 | 248 | break; |
alainpegatoquet | 64:1e20d66960c3 | 249 | case 4: // control servomotor |
alainpegatoquet | 64:1e20d66960c3 | 250 | for (iIndex=0; iIndex<retcode; iIndex++) { |
alainpegatoquet | 64:1e20d66960c3 | 251 | iPosition = iPosition*10 + (rx_buffer[iIndex]-0x30); // convert receive string to angular position |
alainpegatoquet | 64:1e20d66960c3 | 252 | } |
alainpegatoquet | 64:1e20d66960c3 | 253 | |
alainpegatoquet | 64:1e20d66960c3 | 254 | printf("\n Servo position =%d",iPosition); |
alainpegatoquet | 64:1e20d66960c3 | 255 | Myservo.position ( iPosition-45 ); // set servo motor position from 0 to 180 |
alainpegatoquet | 64:1e20d66960c3 | 256 | break; |
alainpegatoquet | 64:1e20d66960c3 | 257 | default: |
alainpegatoquet | 64:1e20d66960c3 | 258 | printf("\n port inconnu =%d",(int)port); |
alainpegatoquet | 64:1e20d66960c3 | 259 | break; |
alainpegatoquet | 64:1e20d66960c3 | 260 | } |
alainpegatoquet | 64:1e20d66960c3 | 261 | |
alainpegatoquet | 64:1e20d66960c3 | 262 | // ***************************** end code todo here ***************************************** |
mbed_official | 12:5015dfead3f2 | 263 | memset(rx_buffer, 0, sizeof(rx_buffer)); |
mbed_official | 0:7037ed05f54f | 264 | } |
mbed_official | 0:7037ed05f54f | 265 | |
mbed_official | 0:7037ed05f54f | 266 | /** |
mbed_official | 0:7037ed05f54f | 267 | * Event handler |
mbed_official | 0:7037ed05f54f | 268 | */ |
mbed_official | 0:7037ed05f54f | 269 | static void lora_event_handler(lorawan_event_t event) |
mbed_official | 0:7037ed05f54f | 270 | { |
alainpegatoquet | 64:1e20d66960c3 | 271 | printf("\r\nEventCode = %d \r\n", event); |
mbed_official | 0:7037ed05f54f | 272 | switch (event) { |
mbed_official | 0:7037ed05f54f | 273 | case CONNECTED: |
mbed_official | 0:7037ed05f54f | 274 | printf("\r\n Connection - Successful \r\n"); |
mbed_official | 0:7037ed05f54f | 275 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
mbed_official | 0:7037ed05f54f | 276 | send_message(); |
mbed_official | 0:7037ed05f54f | 277 | } else { |
mbed_official | 0:7037ed05f54f | 278 | ev_queue.call_every(TX_TIMER, send_message); |
mbed_official | 0:7037ed05f54f | 279 | } |
mbed_official | 0:7037ed05f54f | 280 | |
mbed_official | 0:7037ed05f54f | 281 | break; |
mbed_official | 0:7037ed05f54f | 282 | case DISCONNECTED: |
mbed_official | 0:7037ed05f54f | 283 | ev_queue.break_dispatch(); |
mbed_official | 0:7037ed05f54f | 284 | printf("\r\n Disconnected Successfully \r\n"); |
mbed_official | 0:7037ed05f54f | 285 | break; |
mbed_official | 0:7037ed05f54f | 286 | case TX_DONE: |
mbed_official | 0:7037ed05f54f | 287 | printf("\r\n Message Sent to Network Server \r\n"); |
mbed_official | 0:7037ed05f54f | 288 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
mbed_official | 0:7037ed05f54f | 289 | send_message(); |
mbed_official | 0:7037ed05f54f | 290 | } |
mbed_official | 0:7037ed05f54f | 291 | break; |
mbed_official | 0:7037ed05f54f | 292 | case TX_TIMEOUT: |
mbed_official | 0:7037ed05f54f | 293 | case TX_ERROR: |
mbed_official | 0:7037ed05f54f | 294 | case TX_CRYPTO_ERROR: |
mbed_official | 0:7037ed05f54f | 295 | case TX_SCHEDULING_ERROR: |
mbed_official | 0:7037ed05f54f | 296 | printf("\r\n Transmission Error - EventCode = %d \r\n", event); |
mbed_official | 0:7037ed05f54f | 297 | // try again |
mbed_official | 0:7037ed05f54f | 298 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
mbed_official | 0:7037ed05f54f | 299 | send_message(); |
mbed_official | 0:7037ed05f54f | 300 | } |
mbed_official | 0:7037ed05f54f | 301 | break; |
mbed_official | 0:7037ed05f54f | 302 | case RX_DONE: |
mbed_official | 0:7037ed05f54f | 303 | printf("\r\n Received message from Network Server \r\n"); |
mbed_official | 0:7037ed05f54f | 304 | receive_message(); |
mbed_official | 0:7037ed05f54f | 305 | break; |
mbed_official | 0:7037ed05f54f | 306 | case RX_TIMEOUT: |
alainpegatoquet | 64:1e20d66960c3 | 307 | printf("\r\n timeout in reception - Code = %d \r\n", event); |
superphil06 | 59:7b58c5775a56 | 308 | break; |
mbed_official | 0:7037ed05f54f | 309 | case RX_ERROR: |
mbed_official | 0:7037ed05f54f | 310 | printf("\r\n Error in reception - Code = %d \r\n", event); |
mbed_official | 0:7037ed05f54f | 311 | break; |
mbed_official | 0:7037ed05f54f | 312 | case JOIN_FAILURE: |
mbed_official | 0:7037ed05f54f | 313 | printf("\r\n OTAA Failed - Check Keys \r\n"); |
mbed_official | 0:7037ed05f54f | 314 | break; |
mbed_official | 26:f07f5febf97f | 315 | case UPLINK_REQUIRED: |
mbed_official | 26:f07f5febf97f | 316 | printf("\r\n Uplink required by NS \r\n"); |
mbed_official | 26:f07f5febf97f | 317 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { |
mbed_official | 26:f07f5febf97f | 318 | send_message(); |
mbed_official | 26:f07f5febf97f | 319 | } |
mbed_official | 26:f07f5febf97f | 320 | break; |
mbed_official | 0:7037ed05f54f | 321 | default: |
mbed_official | 0:7037ed05f54f | 322 | MBED_ASSERT("Unknown Event"); |
mbed_official | 0:7037ed05f54f | 323 | } |
mbed_official | 0:7037ed05f54f | 324 | } |
mbed_official | 0:7037ed05f54f | 325 | |
mbed_official | 0:7037ed05f54f | 326 | // EOF |