From f06888a18e8ab4249bb756b899a3b3cad3a6f99b Mon Sep 17 00:00:00 2001 From: richonguzman Date: Tue, 11 Jul 2023 07:30:18 -0400 Subject: [PATCH] 1.1.2 --- src/LoRa_APRS_Tracker.cpp | 8 ++++-- src/ble_utils.cpp | 52 +++++++++++++++++++++++++++++++++++++++ src/ble_utils.h | 12 +++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/ble_utils.cpp create mode 100644 src/ble_utils.h diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 895d40f..ac70b78 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -2,6 +2,7 @@ #include #endif #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "lora_utils.h" #include "msg_utils.h" #include "gps_utils.h" +#include "ble_utils.h" #include "display.h" #include "SPIFFS.h" #include "utils.h" @@ -27,6 +29,7 @@ Configuration Config; PowerManagement powerManagement; HardwareSerial neo6m_gps(1); TinyGPSPlus gps; +NimBLECharacteristic* pCharacteristic; OneButton userButton = OneButton(BUTTON_PIN, true, true); int myBeaconsIndex = 0; @@ -79,11 +82,12 @@ void setup() { GPS_Utils::setup(); LoRa_Utils::setup(); - WiFi.mode(WIFI_OFF); + /*WiFi.mode(WIFI_OFF); btStop(); logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "WiFi and BT controller stopped"); esp_bt_controller_disable(); - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "BT controller disabled"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "BT controller disabled");*/ + BLE_Utils::setup(); userButton.attachClick(BUTTON_Utils::singlePress); userButton.attachLongPressStart(BUTTON_Utils::longPress); diff --git a/src/ble_utils.cpp b/src/ble_utils.cpp new file mode 100644 index 0000000..6a599ae --- /dev/null +++ b/src/ble_utils.cpp @@ -0,0 +1,52 @@ +#include "ble_utils.h" +#include + +#define SERVICE_UUID "0000180A-0000-1000-8000-00805F9B34FB" +#define CHARACTERISTIC_UUID "00002A29-0000-1000-8000-00805F9B34FB" + +extern NimBLECharacteristic* pCharacteristic; + +class MyCallbacks : public NimBLECharacteristicCallbacks { + void onWrite(NimBLECharacteristic* pChar) { + std::string receivedData = pChar->getValue(); // Read the data from the characteristic + //Serial.print("Received message: "); Serial.println(receivedData.c_str()); + String receivedString = ""; + for (int i=0; isetValue("hola tambien"); + pCharacteristic->notify(); + } else if (receivedString=="/send message") { + Serial.println("Send Message To..."); + pCharacteristic->setValue("Send Message To..."); + pCharacteristic->notify(); + } else if (receivedString=="CD2RXU-7") { + Serial.println("Sending message to CD2RXU-7..."); + pCharacteristic->setValue("Sending message to CD2RXU-7..."); + pCharacteristic->notify(); + } + } +}; + + +namespace BLE_Utils { + +void setup() { + NimBLEDevice::init("Tracker BLE Test"); + NimBLEServer* pServer = NimBLEDevice::createServer(); + NimBLEService* pService = pServer->createService(SERVICE_UUID); + pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::NOTIFY); + + pCharacteristic->setCallbacks(new MyCallbacks()); + pService->start(); + + NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising(); + pAdvertising->addServiceUUID(SERVICE_UUID); + pAdvertising->start(); + + Serial.println("Waiting for BLE central to connect..."); +} + +} diff --git a/src/ble_utils.h b/src/ble_utils.h new file mode 100644 index 0000000..0436587 --- /dev/null +++ b/src/ble_utils.h @@ -0,0 +1,12 @@ +#ifndef BLE_UTILS_H_ +#define BLE_UTILS_H_ + +#include + +namespace BLE_Utils { + +void setup(); + +} + +#endif \ No newline at end of file