GPS to Pulga
Diff: source/main.cpp
- Revision:
- 24:595155aa83c3
- Parent:
- 23:7f1c9c1a4c57
- Child:
- 25:ecdee9ef9939
diff -r 7f1c9c1a4c57 -r 595155aa83c3 source/main.cpp --- a/source/main.cpp Mon Dec 30 18:38:40 2019 +0000 +++ b/source/main.cpp Fri Jan 03 09:28:20 2020 +0000 @@ -7,26 +7,34 @@ #include "mbed.h" /***Definições do Arquétipo***/ -int comm=1; // Selecionar: 0 para nenhum, 1 para BLE, 2 para Lora ou 3 para Lorawan +int comm=2; // Selecionar: 0 para nenhum, 1 para BLE, 2 para Lora ou 3 para Lorawan int sensors=0; // Selecionar: 0 para nenhum, 1 para sensor ambiental, 2 para sensor de luz, 3 para sensor de movimento. int peripherals=0; // Selecionar: 0 para nenhum, 1 para GPS /***Global Variables***/ -float sensor_get = 0; +float sensor_get_0 = 0; +float sensor_get_1 = 0; +float sensor_get_2 = 0; +float sensor_get_3 = 0; +float sensor_get_4 = 0; + uint32_t sens00 = 0; uint32_t sens01 = 0; uint32_t sens02 = 0; int cont=0; int read_sens=0; - - +int lat=0; +int lon=0; +int latitude=0; +int longitude=0; /***SPECIFIC INCLUDES***/ //BLE Includes + #include "platform/Callback.h" #include "events/EventQueue.h" #include "platform/NonCopyable.h" @@ -39,19 +47,30 @@ #include "ble/GattServer.h" #include "BLEProcess.h" + + +//Lorawan Includes + +#include "lorawan/LoRaWANInterface.h" +#include "lorawan/system/lorawan_data_structures.h" +#include "trace_helper.h" +#include "lora_radio_helper.h" + +DigitalOut led1(P1_13); +InterruptIn button1(P1_11); + //Sensors Includes - #include "BME280.h" #include "Si1133.h" #include "BMX160.txt" +#include "gps.txt" /***DEFINES***/ //Sensors and Peripherals -DigitalOut led1(P1_13); -InterruptIn button1(P1_11); -BME280 sensor_amb(P0_13, P0_15, 0x77 << 1) ; + +BME280 sensor_amb(P0_13, P0_15, 0x77 << 1); Si1133 sensor_light(P0_13, P0_15); @@ -65,67 +84,67 @@ if (sens==1) { sensor_amb.initialize(); - sensor_get = sensor_amb.getTemperature(); + sensor_get_0 = sensor_amb.getTemperature(); - if (comm==1){ - sens00 = sensor_get; + //if (comm==1){ + sens00 = sensor_get_0; sens00 = (sens00 < 0 ? 0 : sens00); sens00 = (sens00 > 255 ? 255 : sens00); printf("Temp = %u\n", sens00); - } + // } - printf("Temp = %f\n", sensor_get); + printf("Temp = %f\n", sensor_get_0); - sensor_get = sensor_amb.getPressure(); + sensor_get_1 = sensor_amb.getPressure(); if (comm==1){ - sens01 = sensor_get/10; + sens01 = sensor_get_1/10; sens01 = (sens01 < 0 ? 0 : sens01); sens01 = (sens01 > 255 ? 255 : sens01); printf("Pres = %u\n", sens01); } - printf("Pres = %f\n", sensor_get); + printf("Pres = %f\n", sensor_get_1); - sensor_get = sensor_amb.getHumidity(); + sensor_get_2 = sensor_amb.getHumidity(); if (comm==1){ - sens02 = sensor_get; + sens02 = sensor_get_2; sens02 = (sens02 < 0 ? 0 : sens02); sens02 = (sens02 > 255 ? 255 : sens02); printf("Hum = %u\n", sens02); } - printf("Hum = %f\n", sensor_get); + printf("Hum = %f\n", sensor_get_2); } if (sens==2) { if(sensor_light.open()){ - sensor_get = sensor_light.get_light_level(); + sensor_get_3 = sensor_light.get_light_level(); if (comm==1){ - sens00 = sensor_get; + sens00 = sensor_get_3; sens00 = (sens00 < 0 ? 0 : sens00); sens00 = (sens00 > 255 ? 255 : sens00); printf("Light Level = %u\n", sens00); } - printf("Light Level = %f\n", sensor_get); + printf("Light Level = %f\n", sensor_get_3); } } if (sens==3) { if(sensor_light.open()){ - sensor_get = sensor_light.get_uv_index(); + sensor_get_4 = sensor_light.get_uv_index(); if (comm==1){ - sens01 = sensor_get/10; + sens01 = sensor_get_4/10; sens01 = (sens01 < 0 ? 0 : sens01); sens01 = (sens01 > 255 ? 255 : sens01); printf("UV Index = %u\n", sens01); } - printf("Uv Index = %f\n", sensor_get); + printf("Uv Index = %f\n", sensor_get_4); } } @@ -135,10 +154,24 @@ } } + - +void GPS_Read(void) +{ + gps_print_local(); + // send_nav_pvt(); + //lon= gps_send_long (); + printf ("gps longitude=%d \n",lon); + //lat= gps_send_lat (); + printf ("gps latitude=%d \n",lat); + //if(lat!=0 && lon!=0){ + longitude=lon; + latitude=lat; + //} + } #include "BLE.txt" +#include "Lorawan.txt" int Communication(int comm){ @@ -150,10 +183,34 @@ BLEProcess ble_process(event_queue, ble_interface); ble_process.on_init(callback(&demo_service, &MyService::start)); ble_process.start(); - event_queue.dispatch_forever(); + event_queue.dispatch_forever(); } - return 0; - } + + if(comm==2){ + + setup_trace(); + lorawan_status_t retcode; + + if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { + printf("\r\n LoRa initialization failed! \r\n"); + return -1;} + callbacks.events = mbed::callback(lora_event_handler); + lorawan.add_app_callbacks(&callbacks); + if (lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) + != LORAWAN_STATUS_OK) { + return -1;} + if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { + printf("\r\n enable_adaptive_datarate failed! \r\n"); + return -1;} + retcode = lorawan.connect(); + if (retcode == LORAWAN_STATUS_OK || + retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { + } else { + return -1;} + ev_queue.dispatch_forever(); + } + return 0; +} void button1_pressed() { printf("Teste dos Periféricos\n"); @@ -176,6 +233,8 @@ int main() { BMX160_config(); + gps_config(); + gps_config_gnss (); //button1.fall(&button1_pressed); //button1.rise(&button1_released); Communication (comm);