From a4a4e7f9fb8c3851981c004b5b8ae1e0dae01086 Mon Sep 17 00:00:00 2001 From: richonguzman Date: Sun, 12 Nov 2023 19:19:22 -0300 Subject: [PATCH] BLE message send --- src/LoRa_APRS_Tracker.cpp | 3 ++ src/ble_utils.cpp | 63 +++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index ed2c22a..b513531 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -59,6 +59,9 @@ bool bluetoothConnected = false; bool bluetoothActive = Config.bluetooth; bool sendBleToLoRa = false; String bleLoRaPacket = ""; +int bleMsgCompose = 0; +String bleMsgAddresse = ""; +String bleMsgTxt = ""; bool messageLed = false; uint32_t messageLedTime = millis(); diff --git a/src/ble_utils.cpp b/src/ble_utils.cpp index e966ee3..56b0fa7 100644 --- a/src/ble_utils.cpp +++ b/src/ble_utils.cpp @@ -1,6 +1,7 @@ #include "ble_utils.h" #include -#include "lora_utils.h" +//#include "lora_utils.h" +#include "msg_utils.h" #include "logger.h" #include "display.h" @@ -13,6 +14,9 @@ NimBLECharacteristic* pCharacteristic; extern logging::Logger logger; extern bool sendBleToLoRa; extern String bleLoRaPacket; +extern int bleMsgCompose; +extern String bleMsgAddresse; +extern String bleMsgTxt; class MyCallbacks : public NimBLECharacteristicCallbacks { void onWrite(NimBLECharacteristic* pChar) { @@ -22,24 +26,36 @@ class MyCallbacks : public NimBLECharacteristicCallbacks { 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(); - } else if (receivedString=="test") { - Serial.println("Sending message TEST..."); - pCharacteristic->setValue("Sending TEST message"); - pCharacteristic->notify(); - bleLoRaPacket = "CD2RXU-7>APLRT1,WIDE1-1::XQ3OP-7 :Test con Bluetooth BLE"; - sendBleToLoRa = true; + if (bleMsgCompose > 0) { + switch (bleMsgCompose) { + case 1: + Serial.println("Adressee : " + receivedString); + bleMsgAddresse = receivedString; + bleMsgCompose = 2; + pCharacteristic->setValue("Adressee : " + receivedString); + pCharacteristic->notify(); + pCharacteristic->setValue("Message ..."); + pCharacteristic->notify(); + break; + case 2: + Serial.println("Message : " + receivedString); + bleMsgTxt = receivedString; + pCharacteristic->setValue("Msg -> " + bleMsgAddresse + " : " + receivedString); + pCharacteristic->notify(); + sendBleToLoRa = true; + break; + } + } else { + if (receivedString == "hola") { + Serial.println("hola tambien"); + pCharacteristic->setValue("hola tambien"); + pCharacteristic->notify(); + } else if (receivedString=="/msg") { + bleMsgCompose = 1; + Serial.println("Send Message To..."); + pCharacteristic->setValue("Send Message To..."); + pCharacteristic->notify(); + } } } }; @@ -67,12 +83,13 @@ namespace BLE_Utils { if (!sendBleToLoRa) { return; } - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "BT TX", "%s", bleLoRaPacket.c_str()); - show_display("BT Tx >>", "", bleLoRaPacket, 1000); - - LoRa_Utils::sendNewPacket(bleLoRaPacket); + show_display("BLE Tx >>", "", bleLoRaPacket, 1000); + MSG_Utils::sendMessage(bleMsgAddresse,bleMsgTxt); + bleMsgCompose = 0; + bleMsgAddresse = ""; + bleMsgTxt = ""; sendBleToLoRa = false; }