Marumbo Sichinga / Mbed 2 deprecated SmartWatchTopicDisplay

Dependencies:   mbed

Committer:
marumbo
Date:
Sun Jul 11 18:17:00 2021 +0000
Revision:
5:235bf7c41262
Parent:
4:63bf2f3d54a5
Child:
6:288c9d9d59e4
Final changes made for interrupt. and sending to Lora need to verify channel as data is not being seen in activity;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marumbo 5:235bf7c41262 1 #include "mbed.h"
marumbo 0:0b9e73d44412 2 #include "C12832.h"
marumbo 0:0b9e73d44412 3 #include "Sht31.h"
marumbo 0:0b9e73d44412 4 #include <string>
marumbo 0:0b9e73d44412 5 #include "mbed_trace.h"
marumbo 0:0b9e73d44412 6 #include "mbed_events.h"
marumbo 0:0b9e73d44412 7 #include "LoRaWANInterface.h"
marumbo 0:0b9e73d44412 8 #include "SX1276_LoRaRadio.h"
marumbo 3:ab4d9bcf8dd1 9
marumbo 0:0b9e73d44412 10 // Device credentials, register device as OTAA in The Things Network and copy credentials here
marumbo 0:0b9e73d44412 11 static uint8_t DEV_EUI[] = { 0x26, 0x10, 0x20, 0x20, 0x11, 0x11, 0x20, 0x20 };
marumbo 0:0b9e73d44412 12 static uint8_t APP_EUI[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x03, 0x74, 0x72 };
marumbo 0:0b9e73d44412 13 static uint8_t APP_KEY[] = { 0x75, 0x57, 0x56, 0x65, 0xB1, 0x8A, 0x17, 0x52, 0x1B, 0x2D, 0x45, 0xD9, 0xFC, 0x90, 0x9E, 0x05 };
marumbo 3:ab4d9bcf8dd1 14
marumbo 0:0b9e73d44412 15 // The port we're sending and receiving on
marumbo 0:0b9e73d44412 16 #define MBED_CONF_LORA_APP_PORT 15
marumbo 3:ab4d9bcf8dd1 17
marumbo 0:0b9e73d44412 18 // Peripherals (LoRa radio, temperature sensor and button)
marumbo 0:0b9e73d44412 19 SX1276_LoRaRadio radio(D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9, NC, NC, NC, NC, A4, NC, NC);
marumbo 0:0b9e73d44412 20 static EventQueue ev_queue;
marumbo 3:ab4d9bcf8dd1 21
marumbo 0:0b9e73d44412 22 // Constructing Mbed LoRaWANInterface and passing it down the radio object.
marumbo 0:0b9e73d44412 23 static LoRaWANInterface lorawan(radio);
marumbo 3:ab4d9bcf8dd1 24
marumbo 0:0b9e73d44412 25 // Application specific callbacks
marumbo 0:0b9e73d44412 26 static lorawan_app_callbacks_t callbacks;
marumbo 3:ab4d9bcf8dd1 27
marumbo 0:0b9e73d44412 28 // LoRaWAN stack event handler
marumbo 0:0b9e73d44412 29 static void lora_event_handler(lorawan_event_t event);
marumbo 3:ab4d9bcf8dd1 30
marumbo 0:0b9e73d44412 31 static void send_message(int topicId, long int duration, string group) {
marumbo 0:0b9e73d44412 32 uint8_t tx_buffer[50] = { 0 };
marumbo 2:a128db827b61 33
marumbo 3:ab4d9bcf8dd1 34 string deviceId = "My Device";
marumbo 2:a128db827b61 35 long int timestamp = 1234567892;
marumbo 2:a128db827b61 36 int value = 2;
marumbo 3:ab4d9bcf8dd1 37 sprintf((char*) tx_buffer, "{\"deviceId\":\"%s\",\"TopicId\":%d,\"Group\":%s}}", deviceId.c_str(), topicId, group.c_str());
marumbo 0:0b9e73d44412 38 // Sending strings over LoRaWAN is not recommended
marumbo 2:a128db827b61 39 // sprintf((char*) tx_buffer, "{\"topicId\":%d, \"duration\":%ld,\"group\":\"%s\"}", topicId, duration, group.c_str());
marumbo 0:0b9e73d44412 40 int packet_len = strlen((char*) tx_buffer);
marumbo 0:0b9e73d44412 41 printf("Sending %d bytes: \"%s\"\n", packet_len, tx_buffer);
marumbo 0:0b9e73d44412 42 int16_t retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, MSG_UNCONFIRMED_FLAG);
marumbo 0:0b9e73d44412 43 // for some reason send() returns -1... I cannot find out why, the stack returns the right number. I feel that this is some weird Emscripten quirk
marumbo 0:0b9e73d44412 44 if (retcode < 0) {
marumbo 0:0b9e73d44412 45 retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - duty cycle violation\n")
marumbo 0:0b9e73d44412 46 : printf("send() - Error code %d\n", retcode);
marumbo 2:a128db827b61 47 return;
marumbo 0:0b9e73d44412 48 }
marumbo 2:a128db827b61 49
marumbo 0:0b9e73d44412 50 printf("%d bytes scheduled for transmission\n", retcode);
marumbo 2:a128db827b61 51 callbacks.events = mbed::callback(lora_event_handler);
marumbo 2:a128db827b61 52 lorawan.add_app_callbacks(&callbacks);
marumbo 0:0b9e73d44412 53 }
marumbo 3:ab4d9bcf8dd1 54
marumbo 0:0b9e73d44412 55 int initialize_lora() {
marumbo 0:0b9e73d44412 56 if (DEV_EUI[0] == 0x0 && DEV_EUI[1] == 0x0 && DEV_EUI[2] == 0x0 && DEV_EUI[3] == 0x0 && DEV_EUI[4] == 0x0 && DEV_EUI[5] == 0x0 && DEV_EUI[6] == 0x0 && DEV_EUI[7] == 0x0) {
marumbo 0:0b9e73d44412 57 printf("Set your LoRaWAN credentials first!\n");
marumbo 2:a128db827b61 58 return -1;
marumbo 0:0b9e73d44412 59 }
marumbo 2:a128db827b61 60 printf("Initializing LORA!\n");
marumbo 0:0b9e73d44412 61 // Enable trace output for this demo, so we can see what the LoRaWAN stack does
marumbo 0:0b9e73d44412 62 mbed_trace_init();
marumbo 0:0b9e73d44412 63 if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
marumbo 0:0b9e73d44412 64 printf("LoRa initialization failed!\n");
marumbo 2:a128db827b61 65 return -1;
marumbo 0:0b9e73d44412 66 }
marumbo 0:0b9e73d44412 67 // prepare application callbacks
marumbo 0:0b9e73d44412 68 callbacks.events = mbed::callback(lora_event_handler);
marumbo 0:0b9e73d44412 69 lorawan.add_app_callbacks(&callbacks);
marumbo 0:0b9e73d44412 70 // Disable adaptive data rating
marumbo 0:0b9e73d44412 71 if (lorawan.disable_adaptive_datarate() != LORAWAN_STATUS_OK) {
marumbo 0:0b9e73d44412 72 printf("disable_adaptive_datarate failed!\n");
marumbo 2:a128db827b61 73 return -1;
marumbo 0:0b9e73d44412 74 }
marumbo 0:0b9e73d44412 75 lorawan.set_datarate(5); // SF7BW125
marumbo 0:0b9e73d44412 76 lorawan_connect_t connect_params;
marumbo 0:0b9e73d44412 77 connect_params.connect_type = LORAWAN_CONNECTION_OTAA;
marumbo 0:0b9e73d44412 78 connect_params.connection_u.otaa.dev_eui = DEV_EUI;
marumbo 0:0b9e73d44412 79 connect_params.connection_u.otaa.app_eui = APP_EUI;
marumbo 0:0b9e73d44412 80 connect_params.connection_u.otaa.app_key = APP_KEY;
marumbo 0:0b9e73d44412 81 connect_params.connection_u.otaa.nb_trials = 3;
marumbo 3:ab4d9bcf8dd1 82
marumbo 0:0b9e73d44412 83 lorawan_status_t retcode = lorawan.connect(connect_params);
marumbo 3:ab4d9bcf8dd1 84
marumbo 0:0b9e73d44412 85 if (retcode == LORAWAN_STATUS_OK ||
marumbo 0:0b9e73d44412 86 retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
marumbo 0:0b9e73d44412 87 } else {
marumbo 0:0b9e73d44412 88 printf("Connection error, code = %d\n", retcode);
marumbo 2:a128db827b61 89 return -1;
marumbo 0:0b9e73d44412 90 }
marumbo 3:ab4d9bcf8dd1 91
marumbo 0:0b9e73d44412 92 printf("Connection - In Progress ...\r\n");
marumbo 0:0b9e73d44412 93 // make your event queue dispatching events forever
marumbo 0:0b9e73d44412 94 ev_queue.dispatch_forever();
marumbo 0:0b9e73d44412 95 return 0;
marumbo 0:0b9e73d44412 96 }
marumbo 3:ab4d9bcf8dd1 97
marumbo 3:ab4d9bcf8dd1 98
marumbo 3:ab4d9bcf8dd1 99
marumbo 0:0b9e73d44412 100 //declare lcd
marumbo 0:0b9e73d44412 101 C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11);
marumbo 3:ab4d9bcf8dd1 102
marumbo 0:0b9e73d44412 103 //humidity and temperature sensor
marumbo 0:0b9e73d44412 104 Sht31 sht31(I2C_SDA, I2C_SCL);
marumbo 3:ab4d9bcf8dd1 105
marumbo 0:0b9e73d44412 106 //declare components
marumbo 2:a128db827b61 107 //InterruptIn pushButton(BUTTON1); //p11
marumbo 0:0b9e73d44412 108 InterruptIn pushButton(p11);
marumbo 0:0b9e73d44412 109 DigitalOut whiteLed(p8);
marumbo 0:0b9e73d44412 110 DigitalOut redLed(p9);
marumbo 0:0b9e73d44412 111 DigitalOut blueLed(p10);
marumbo 3:ab4d9bcf8dd1 112 DigitalOut led2(LED2);
marumbo 3:ab4d9bcf8dd1 113
marumbo 0:0b9e73d44412 114 void State1();
marumbo 0:0b9e73d44412 115 void State2();
marumbo 0:0b9e73d44412 116 void Mode1();
marumbo 0:0b9e73d44412 117 void Mode2();
marumbo 0:0b9e73d44412 118 void CheckDirection();
marumbo 0:0b9e73d44412 119 void PrintContent();
marumbo 0:0b9e73d44412 120 void StartButtonTimer();
marumbo 0:0b9e73d44412 121 void StopButtonTimer();
marumbo 0:0b9e73d44412 122 void DurationCheck();
marumbo 0:0b9e73d44412 123 void NextTopic();
marumbo 3:ab4d9bcf8dd1 124
marumbo 0:0b9e73d44412 125 //topics and content
marumbo 0:0b9e73d44412 126 string content[5][2]= {{"Topic 1","Content 1"},{"Topic 2","Content 2"},{"Topic 3","Content 3"},{"Topic 4","Content 4"},{"Topic 5","Content 5"}};
marumbo 0:0b9e73d44412 127 string companyName = "Godfrey&SonsTech";
marumbo 3:ab4d9bcf8dd1 128
marumbo 0:0b9e73d44412 129
marumbo 0:0b9e73d44412 130 int direction = 0; // Forward is 0 False and Reverse 1true
marumbo 2:a128db827b61 131 int current_topic = 0;;
marumbo 0:0b9e73d44412 132 time_t loraTimerStart;
marumbo 0:0b9e73d44412 133 time_t loraTimerStop;
marumbo 0:0b9e73d44412 134 time_t buttonTimerStart;
marumbo 0:0b9e73d44412 135 time_t buttonTimerStop;
marumbo 0:0b9e73d44412 136 int loraDuration = 0;
marumbo 0:0b9e73d44412 137 int buttonDuration = 0;
marumbo 3:ab4d9bcf8dd1 138 Ticker flipper;
marumbo 3:ab4d9bcf8dd1 139
marumbo 3:ab4d9bcf8dd1 140
marumbo 0:0b9e73d44412 141 void PrintTemperatureAndTime() {
marumbo 0:0b9e73d44412 142
marumbo 0:0b9e73d44412 143 time_t seconds = time(NULL);
marumbo 0:0b9e73d44412 144
marumbo 0:0b9e73d44412 145 float temp = sht31.readTemperature();
marumbo 0:0b9e73d44412 146 float humidity = sht31.readHumidity();
marumbo 0:0b9e73d44412 147 lcd.locate(3, 3);
marumbo 0:0b9e73d44412 148 lcd.printf("Temperature: %.2f C", temp);
marumbo 0:0b9e73d44412 149
marumbo 0:0b9e73d44412 150 lcd.locate(3, 13);
marumbo 0:0b9e73d44412 151 lcd.printf("Date/Time: %s", ctime(&seconds));
marumbo 0:0b9e73d44412 152 // turn on LED if the temperature is above 25 degrees
marumbo 0:0b9e73d44412 153 }
marumbo 0:0b9e73d44412 154
marumbo 0:0b9e73d44412 155 void WelcomeMessage(string companyName){
marumbo 0:0b9e73d44412 156 lcd.cls();
marumbo 0:0b9e73d44412 157 lcd.locate(3, 3);
marumbo 0:0b9e73d44412 158 lcd.printf("Welcome");
marumbo 0:0b9e73d44412 159 lcd.locate(3, 13);
marumbo 0:0b9e73d44412 160 lcd.printf(companyName.c_str());
marumbo 0:0b9e73d44412 161 wait(5);
marumbo 0:0b9e73d44412 162 lcd.cls();
marumbo 0:0b9e73d44412 163
marumbo 0:0b9e73d44412 164 //call Mode1
marumbo 0:0b9e73d44412 165 Mode1();
marumbo 0:0b9e73d44412 166
marumbo 0:0b9e73d44412 167 }
marumbo 0:0b9e73d44412 168 // create an instance of LCD
marumbo 0:0b9e73d44412 169 void Display(string lcdPrint) {
marumbo 0:0b9e73d44412 170 lcd.cls(); // Clear LCD
marumbo 0:0b9e73d44412 171 lcd.locate(3,5); // get cursor to position x=3px and y=5px
marumbo 0:0b9e73d44412 172 lcd.printf(lcdPrint.c_str()); // Write text into LCD buffer
marumbo 0:0b9e73d44412 173 // Clear LCD
marumbo 0:0b9e73d44412 174 }
marumbo 3:ab4d9bcf8dd1 175
marumbo 0:0b9e73d44412 176 void StartButtonTimer(){
marumbo 0:0b9e73d44412 177 printf("Button Timer start \n");
marumbo 0:0b9e73d44412 178 buttonTimerStart = time(NULL);
marumbo 4:63bf2f3d54a5 179 printf("Button timer start: %ld \n",buttonTimerStart);
marumbo 0:0b9e73d44412 180 wait(0.5);
marumbo 0:0b9e73d44412 181
marumbo 0:0b9e73d44412 182
marumbo 0:0b9e73d44412 183 }
marumbo 3:ab4d9bcf8dd1 184
marumbo 0:0b9e73d44412 185 void StopButtonTimer(){
marumbo 0:0b9e73d44412 186 printf("Button timer stop \n");
marumbo 0:0b9e73d44412 187 loraTimerStop =time(NULL);
marumbo 0:0b9e73d44412 188 buttonTimerStop = time(NULL);
marumbo 3:ab4d9bcf8dd1 189 printf("Button timer stop: %ld \n",buttonTimerStop);
marumbo 0:0b9e73d44412 190 wait(0.5);
marumbo 0:0b9e73d44412 191
marumbo 0:0b9e73d44412 192 loraDuration = loraTimerStop - loraTimerStart;
marumbo 0:0b9e73d44412 193
marumbo 0:0b9e73d44412 194 buttonDuration = buttonTimerStop - buttonTimerStart;
marumbo 4:63bf2f3d54a5 195 printf("Duration Lora: %d \n", loraDuration);
marumbo 4:63bf2f3d54a5 196 printf("Duration Button: %d \n", buttonDuration);
marumbo 0:0b9e73d44412 197
marumbo 0:0b9e73d44412 198 DurationCheck();
marumbo 0:0b9e73d44412 199
marumbo 0:0b9e73d44412 200 }
marumbo 3:ab4d9bcf8dd1 201
marumbo 0:0b9e73d44412 202 void NextTopic(){
marumbo 0:0b9e73d44412 203 if(direction == 0){
marumbo 2:a128db827b61 204 if(current_topic == 4){
marumbo 0:0b9e73d44412 205 current_topic = -1;
marumbo 0:0b9e73d44412 206 }
marumbo 0:0b9e73d44412 207 current_topic++;
marumbo 0:0b9e73d44412 208 }
marumbo 0:0b9e73d44412 209
marumbo 0:0b9e73d44412 210 if(direction ==1){
marumbo 2:a128db827b61 211 if(current_topic == 0){
marumbo 0:0b9e73d44412 212 current_topic = 5;
marumbo 0:0b9e73d44412 213 }
marumbo 0:0b9e73d44412 214 current_topic --;
marumbo 0:0b9e73d44412 215 }
marumbo 0:0b9e73d44412 216
marumbo 0:0b9e73d44412 217 Mode2();
marumbo 0:0b9e73d44412 218 }
marumbo 3:ab4d9bcf8dd1 219
marumbo 0:0b9e73d44412 220 void DurationCheck(){
marumbo 0:0b9e73d44412 221 printf("duration check details: \n");
marumbo 0:0b9e73d44412 222 printf("Duration Lora: %d \n", loraDuration);
marumbo 0:0b9e73d44412 223 printf("Duration Button: %d \n", buttonDuration);
marumbo 0:0b9e73d44412 224
marumbo 2:a128db827b61 225 if(loraDuration> 5) {
marumbo 0:0b9e73d44412 226 //add lora sending function
marumbo 0:0b9e73d44412 227 printf("Id: %d, duration: %d \n", current_topic, loraDuration );
marumbo 2:a128db827b61 228 send_message(current_topic, loraDuration, "Grp2");
marumbo 0:0b9e73d44412 229 }
marumbo 0:0b9e73d44412 230
marumbo 2:a128db827b61 231 if(buttonDuration < 3)
marumbo 0:0b9e73d44412 232 {
marumbo 0:0b9e73d44412 233 //call next topic
marumbo 0:0b9e73d44412 234 NextTopic();
marumbo 0:0b9e73d44412 235 }
marumbo 0:0b9e73d44412 236
marumbo 2:a128db827b61 237 if(buttonDuration >= 3 && buttonDuration <= 5){
marumbo 0:0b9e73d44412 238 direction = !direction;
marumbo 0:0b9e73d44412 239 NextTopic();
marumbo 0:0b9e73d44412 240 }
marumbo 0:0b9e73d44412 241
marumbo 2:a128db827b61 242 if(buttonDuration > 5){
marumbo 0:0b9e73d44412 243 Display("Reset to factory ....");
marumbo 0:0b9e73d44412 244 wait(10);
marumbo 0:0b9e73d44412 245 WelcomeMessage(companyName);
marumbo 0:0b9e73d44412 246
marumbo 0:0b9e73d44412 247 }
marumbo 0:0b9e73d44412 248
marumbo 0:0b9e73d44412 249 }
marumbo 3:ab4d9bcf8dd1 250
marumbo 3:ab4d9bcf8dd1 251
marumbo 0:0b9e73d44412 252 void State1(){
marumbo 0:0b9e73d44412 253 current_topic = 0;
marumbo 0:0b9e73d44412 254 PrintTemperatureAndTime();
marumbo 0:0b9e73d44412 255 wait(3);
marumbo 0:0b9e73d44412 256 State2();
marumbo 0:0b9e73d44412 257 }
marumbo 3:ab4d9bcf8dd1 258
marumbo 0:0b9e73d44412 259 void State2(){
marumbo 0:0b9e73d44412 260 printf("state 2 .. \n");
marumbo 0:0b9e73d44412 261
marumbo 0:0b9e73d44412 262 while(current_topic< 5){
marumbo 0:0b9e73d44412 263 printf("current topic %d \n", current_topic);
marumbo 0:0b9e73d44412 264 Display(content[current_topic][0]);
marumbo 0:0b9e73d44412 265 wait(2);
marumbo 0:0b9e73d44412 266 current_topic ++;
marumbo 0:0b9e73d44412 267 }
marumbo 0:0b9e73d44412 268
marumbo 0:0b9e73d44412 269 State1();
marumbo 0:0b9e73d44412 270 }
marumbo 3:ab4d9bcf8dd1 271
marumbo 0:0b9e73d44412 272 void PrintContent(){
marumbo 3:ab4d9bcf8dd1 273 Display(content[current_topic][1]);
marumbo 3:ab4d9bcf8dd1 274
marumbo 0:0b9e73d44412 275 }
marumbo 3:ab4d9bcf8dd1 276
marumbo 0:0b9e73d44412 277 void CheckDirection(){
marumbo 4:63bf2f3d54a5 278 pushButton.rise(callback(&StartButtonTimer));
marumbo 4:63bf2f3d54a5 279 pushButton.fall(callback(&StopButtonTimer));
marumbo 5:235bf7c41262 280 loraTimerStart = time(NULL);
marumbo 0:0b9e73d44412 281
marumbo 4:63bf2f3d54a5 282 while(1) {
marumbo 0:0b9e73d44412 283 if(direction == 0) //O is a forward direction
marumbo 0:0b9e73d44412 284 {
marumbo 0:0b9e73d44412 285 redLed = 0;
marumbo 0:0b9e73d44412 286 blueLed = 1;
marumbo 0:0b9e73d44412 287 PrintContent();
marumbo 0:0b9e73d44412 288 }
marumbo 0:0b9e73d44412 289
marumbo 0:0b9e73d44412 290 if(direction == 1) //O is a forward direction
marumbo 0:0b9e73d44412 291 {
marumbo 0:0b9e73d44412 292 redLed = 1;
marumbo 0:0b9e73d44412 293 blueLed = 0;
marumbo 0:0b9e73d44412 294 PrintContent();
marumbo 0:0b9e73d44412 295 }
marumbo 4:63bf2f3d54a5 296
marumbo 4:63bf2f3d54a5 297 wait_ms(200);
marumbo 4:63bf2f3d54a5 298 }
marumbo 0:0b9e73d44412 299 }
marumbo 3:ab4d9bcf8dd1 300
marumbo 3:ab4d9bcf8dd1 301 void BlinkWhiteLed() {
marumbo 3:ab4d9bcf8dd1 302
marumbo 3:ab4d9bcf8dd1 303 whiteLed = !whiteLed;
marumbo 3:ab4d9bcf8dd1 304 led2 = !led2;
marumbo 3:ab4d9bcf8dd1 305
marumbo 3:ab4d9bcf8dd1 306
marumbo 0:0b9e73d44412 307 }
marumbo 3:ab4d9bcf8dd1 308
marumbo 0:0b9e73d44412 309 void Mode1(){
marumbo 3:ab4d9bcf8dd1 310
marumbo 3:ab4d9bcf8dd1 311 printf("Mode 1... \n");
marumbo 2:a128db827b61 312 printf("current topic %s \n", content[current_topic][0].c_str());
marumbo 3:ab4d9bcf8dd1 313
marumbo 3:ab4d9bcf8dd1 314 flipper.attach(&BlinkWhiteLed, 1.0);
marumbo 3:ab4d9bcf8dd1 315 pushButton.fall(callback(&Mode2));
marumbo 3:ab4d9bcf8dd1 316
marumbo 3:ab4d9bcf8dd1 317 State1();
marumbo 0:0b9e73d44412 318 }
marumbo 3:ab4d9bcf8dd1 319
marumbo 0:0b9e73d44412 320 void Mode2(){
marumbo 3:ab4d9bcf8dd1 321
marumbo 0:0b9e73d44412 322 printf("Mode 2... \n");
marumbo 0:0b9e73d44412 323 printf("current topic %s \n", content[current_topic][0].c_str());
marumbo 4:63bf2f3d54a5 324 flipper.detach();
marumbo 5:235bf7c41262 325 whiteLed = 0;
marumbo 4:63bf2f3d54a5 326
marumbo 0:0b9e73d44412 327 lcd.cls();
marumbo 4:63bf2f3d54a5 328 wait_ms(500);
marumbo 0:0b9e73d44412 329 CheckDirection();
marumbo 4:63bf2f3d54a5 330
marumbo 0:0b9e73d44412 331
marumbo 0:0b9e73d44412 332 }
marumbo 3:ab4d9bcf8dd1 333
marumbo 3:ab4d9bcf8dd1 334 int main() {
marumbo 0:0b9e73d44412 335
marumbo 0:0b9e73d44412 336 Display("Initializing ..............");
marumbo 0:0b9e73d44412 337 initialize_lora();
marumbo 0:0b9e73d44412 338 WelcomeMessage(companyName);
marumbo 3:ab4d9bcf8dd1 339
marumbo 0:0b9e73d44412 340 }
marumbo 3:ab4d9bcf8dd1 341
marumbo 2:a128db827b61 342 // Event handler
marumbo 0:0b9e73d44412 343 static void lora_event_handler(lorawan_event_t event) {
marumbo 0:0b9e73d44412 344 switch (event) {
marumbo 0:0b9e73d44412 345 case CONNECTED:
marumbo 0:0b9e73d44412 346 printf("Connection - Successful\n");
marumbo 2:a128db827b61 347 ev_queue.break_dispatch();
marumbo 0:0b9e73d44412 348 break;
marumbo 0:0b9e73d44412 349 case DISCONNECTED:
marumbo 0:0b9e73d44412 350 ev_queue.break_dispatch();
marumbo 0:0b9e73d44412 351 printf("Disconnected Successfully\n");
marumbo 0:0b9e73d44412 352 break;
marumbo 0:0b9e73d44412 353 case TX_DONE:
marumbo 0:0b9e73d44412 354 printf("Message Sent to Network Server\n");
marumbo 2:a128db827b61 355 ev_queue.break_dispatch();
marumbo 0:0b9e73d44412 356 break;
marumbo 0:0b9e73d44412 357 case TX_TIMEOUT:
marumbo 0:0b9e73d44412 358 case TX_ERROR:
marumbo 0:0b9e73d44412 359 case TX_CRYPTO_ERROR:
marumbo 0:0b9e73d44412 360 case TX_SCHEDULING_ERROR:
marumbo 2:a128db827b61 361 ev_queue.break_dispatch();
marumbo 0:0b9e73d44412 362 printf("Transmission Error - EventCode = %d\n", event);
marumbo 0:0b9e73d44412 363 break;
marumbo 0:0b9e73d44412 364 case JOIN_FAILURE:
marumbo 0:0b9e73d44412 365 printf("OTAA Failed - Check Keys\n");
marumbo 0:0b9e73d44412 366 break;
marumbo 0:0b9e73d44412 367 default:
marumbo 0:0b9e73d44412 368 MBED_ASSERT("Unknown Event");
marumbo 0:0b9e73d44412 369 }
marumbo 2:a128db827b61 370 }