Egy -elvileg- nagyon egyszerű projektben vagyok: két esp32-est szeretnék rávenni, hogy beszélgessenek bluetooth-on.
Nem menik nekik a dolog. >>Amúgy egy egyszerű házi weather station kültéri egységének az adatait (hőm+pára) szeretném a beltéri egységre továbbítani.
Telón tudom fogni a server-esp32 által küldött hőmérsékleti jelet!! >> (nrf Connect app-al)
Telóról tudok küldeni is cliens-esp32-nek infót... (bár ez elvileg nem kell)
Neten/youtubeon is néztem.. találtam pár embert akinek szintén nem sikerült
De két esp32 beszélgetése nem megy. Valaki készített már ilyet?!?
Alább a küldő/server esp 32-re tett kód (ezt tudom fogni telóval és ezt szeretném fogni egy másik - vevő/cliens esp32vel
köszi bármi segélységet előre is!
Bence
Kód: Egész kijelölése
//Libraries needed for BLE
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
// ====== Homero resze =========
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C kommunikacio
unsigned long delayTime;
// ========== homero vege ===================
//BLE characteristics
BLECharacteristic *pCharacteristic;
bool deviceConnected = false;
int txValue = 0;
//int txValue2 = 0;
//Defining the service & characteristics
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
//Class for servercallbacks (Wether the device is connected or not)
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
//================================================================
void setup(void) {
// Debugging informatie via de Serial monitor
Serial.begin(115200);
// Create the BLE Device
BLEDevice::init("Kulso Homero 1_1"); // Bluetooth name
// Create the BLE Server
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY
);
//BLE2902 needed to notify
pCharacteristic->addDescriptor(new BLE2902());
// Start the service
pService->start();
// Start advertising (showing your ble name to connect to)
pServer->getAdvertising()->start();
Serial.println("Waiting for a client connection to notify...");
// ===== Homero resz ======
bool status;
status = bme.begin(0x76);
// ===== Homero resz vege ======
}
void loop(void) {
//If the device is connected then start sending the characteristics
if (deviceConnected) {
//sikerult beirni a homersekletet h kuldje
txValue = (bme.readTemperature());
// Conversion of txValue
char txString[8];
dtostrf(txValue, 1, 2, txString);
//Setting the value to the characteristic
pCharacteristic->setValue(txString);
//pCharacteristic2->setValue2(txString2);
//Sending/notifying the connected client
pCharacteristic->notify();
Serial.println("Homerseklet: " + String(txString));
Serial.println();
delay(3000);
}
}