1.1.2
This commit is contained in:
parent
ee28049ade
commit
f06888a18e
|
|
@ -2,6 +2,7 @@
|
|||
#include <esp_bt.h>
|
||||
#endif
|
||||
#include <Arduino.h>
|
||||
#include <NimBLEDevice.h>
|
||||
#include <OneButton.h>
|
||||
#include <TinyGPS++.h>
|
||||
#include <logger.h>
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
#include "ble_utils.h"
|
||||
#include <NimBLEDevice.h>
|
||||
|
||||
#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; i<receivedData.length()-2;i++) {
|
||||
receivedString += receivedData[i];
|
||||
}
|
||||
if (receivedString == "hola") {
|
||||
Serial.println("hola tambien");
|
||||
pCharacteristic->setValue("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...");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef BLE_UTILS_H_
|
||||
#define BLE_UTILS_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace BLE_Utils {
|
||||
|
||||
void setup();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue