#include #include #include #include const char* LOG_TAG = "ESP32OmBle"; const BLEUUID serviceUUID("ecbe3980-c9a2-11e1-b1bd-0002a5d5c51b"); const BLEUUID CommandChannelUUID("b305b680-aee7-11e1-a730-0002a5d5c51b"); void notifyCallback( BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) { Serial.print("Notify callback for characteristic "); Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str()); Serial.print(" of data length "); Serial.println(length); Serial.print("data: "); for(int i = 0; isetAuthenticationMode(ESP_LE_AUTH_REQ_SC_BOND); //also available ESP_LE_AUTH_NO_BOND, ESP_LE_AUTH_REQ_SC_MITM, ESP_LE_AUTH_BOND, ESP_LE_AUTH_NO_BOND ESP_LOGI(LOG_TAG, "try bonding"); securityP->setCapability(ESP_IO_CAP_NONE); securityP->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK); securityP->setRespEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK); securityP->setKeySize(16); securityP->setRespEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK); BLEClient* clientP = BLEDevice::createClient(); BLEAddress omronMacAddress = BLEAddress("11:22:33:44:55:66"); clientP->connect(omronMacAddress); BLERemoteService* RemoteServiceP = clientP->getService(serviceUUID); BLERemoteCharacteristic* unlockChannelCharacteristicP = RemoteServiceP->getCharacteristic(CommandChannelUUID); if(unlockChannelCharacteristicP->canNotify()){ unlockChannelCharacteristicP->registerForNotify(notifyCallback); }else{ ESP_LOGI(LOG_TAG, "noNotify possible"); } uint8_t bytes[] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unlockChannelCharacteristicP->writeValue(bytes, sizeof(bytes), true); delay(200000); }