BLE test1
This commit is contained in:
parent
b4ee49c731
commit
9007022abd
|
|
@ -33,6 +33,7 @@ lib_deps =
|
||||||
jgromes/RadioLib @ 6.1.0
|
jgromes/RadioLib @ 6.1.0
|
||||||
adafruit/Adafruit Unified Sensor@^1.1.9
|
adafruit/Adafruit Unified Sensor@^1.1.9
|
||||||
adafruit/Adafruit BME280 Library@^2.2.2
|
adafruit/Adafruit BME280 Library@^2.2.2
|
||||||
|
h2zero/NimBLE-Arduino@^1.4.1
|
||||||
|
|
||||||
check_tool = cppcheck
|
check_tool = cppcheck
|
||||||
check_flags =
|
check_flags =
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include "APRSPacketLib.h"
|
#include "APRSPacketLib.h"
|
||||||
|
#include "ble_utils.h"
|
||||||
|
|
||||||
|
|
||||||
Configuration Config;
|
Configuration Config;
|
||||||
|
|
@ -126,7 +127,8 @@ void setup() {
|
||||||
|
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "WiFi controller stopped");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "WiFi controller stopped");
|
||||||
BLUETOOTH_Utils::setup();
|
//BLUETOOTH_Utils::setup();
|
||||||
|
BLE_Utils::setup();
|
||||||
|
|
||||||
if (!Config.simplifiedTrackerMode) {
|
if (!Config.simplifiedTrackerMode) {
|
||||||
userButton.attachClick(BUTTON_Utils::singlePress);
|
userButton.attachClick(BUTTON_Utils::singlePress);
|
||||||
|
|
@ -165,7 +167,7 @@ void loop() {
|
||||||
MSG_Utils::checkReceivedMessage(LoRa_Utils::receivePacket());
|
MSG_Utils::checkReceivedMessage(LoRa_Utils::receivePacket());
|
||||||
MSG_Utils::ledNotification();
|
MSG_Utils::ledNotification();
|
||||||
STATION_Utils::checkListenedTrackersByTimeAndDelete();
|
STATION_Utils::checkListenedTrackersByTimeAndDelete();
|
||||||
BLUETOOTH_Utils::sendToLoRa();
|
//BLUETOOTH_Utils::sendToLoRa();
|
||||||
|
|
||||||
int currentSpeed = (int) gps.speed.kmph();
|
int currentSpeed = (int) gps.speed.kmph();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "ble_utils.h"
|
||||||
|
#include <NimBLEDevice.h>
|
||||||
|
|
||||||
|
#define SERVICE_UUID "0000180A-0000-1000-8000-00805F9B34FB"
|
||||||
|
#define CHARACTERISTIC_UUID "00002A29-0000-1000-8000-00805F9B34FB"
|
||||||
|
|
||||||
|
NimBLEServer* pServer;
|
||||||
|
NimBLECharacteristic* pCharacteristic;
|
||||||
|
bool newDataReceived = false;
|
||||||
|
|
||||||
|
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