Marumbo Sichinga / Mbed 2 deprecated SmartWatchTopicDisplay

Dependencies:   mbed

Committer:
marumbo
Date:
Sat Jul 10 21:40:09 2021 +0000
Revision:
4:63bf2f3d54a5
Parent:
3:ab4d9bcf8dd1
Child:
5:235bf7c41262
added logic for led interrupt for blink flipper attach and detach,; moved button registers for now confusion with rise and fall;

Who changed what in which revision?

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