Hi
I'm doing a little project where I have a central device with a ESP32 and a few peripherals around that use the HM10 modules.
The idea is that the peripheral modules send data to the main device.
This seems like something super trivial to get working, yet I've spent ages trying to get it to work and I can't figure out what's the deal with it.
I can get the ESP32 to send data to all devices and the HM10 receives it, but the HM10 can't seem to transmit anything to the ESP32.
When I use a ble phone app it works fine.
I tried matching the characteristics of the ESP32 to the one the HM10 might expect, but nothing happens.
Googling the issue does not get me anywhere.
What could I be missing?
ESP32 code:
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLEServer *pServer = NULL;
BLECharacteristic * pCharacteristic;
uint8_t txValue = 'a';
#define SERVICE_UUID "0000FFE0-0000-1000-8000-00805f9b34fb"
#define CHARACTERISTIC_UUID "0000FFE1-0000-1000-8000-00805f9b34fb"
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
pServer->startAdvertising(); // restart advertising
};
void onDisconnect(BLEServer* pServer) {
}
};
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) {
Serial.print("Received Value: ");
for (int i = 0; i < rxValue.length(); i++)
Serial.print(rxValue[i]);
Serial.println();
pCharacteristic->setValue(&txValue, 1);
pCharacteristic->notify();
}
}
};
void setup() {
Serial.begin(115200);
BLEDevice::init("SERVER");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ|BLECharacteristic::PROPERTY_WRITE|BLECharacteristic::PROPERTY_NOTIFY);
pCharacteristic->addDescriptor(new BLE2902());
pCharacteristic->setCallbacks(new MyCallbacks());
pService->start();
pServer->getAdvertising()->start();
Serial.println("Waiting a client connection to notify...");
}
void loop() {
}
HM10 setup:
AT+RENEW
AT+POWE3
AT+FILT0
AT+IMME1
AT+ROLE1
AT+TYPE0
AT+RESET
AT+DISC?
AT+CONBCDDC2F231AB
AT+CONNL
AT+START
HM10 datasheet:
https://people.ece.cornell.edu/land/courses/ece4760/PIC32/uart/HM10/DSD%20TECH%20HM-10%20datasheet.pdf