我正在使用粒子硼与智能锁集成,但我无法做到。我正在使用 Particle 的 BLE 接口连接到蓝牙并开始向锁发送消息,以及“监听”锁响应的回调,但我没有收到任何响应。我不知道我做错了什么,因为它似乎很简单:
代码:
#include "libsodium.h"
#include <string.h>
const size_t SCAN_RESULT_MAX = 30;
bool _utopicPaired = false;
BleCharacteristic utopicPairingCharacteristic;
BleUuid foundInitService;
BleUuid mldpDataPrivateChar("00035b03-58e6-07dd-021a-08123a000301"); // notify, write
BlePeerDevice utopic;
BleAddress utopicAddress;
BleScanResult scanResults[SCAN_RESULT_MAX];
int bleDevices = 0;
size_t nameLength = 0;
char nameBuffer[BLE_MAX_ADV_DATA_LEN];
void onDataPairedUtopic(const uint8_t* data, size_t len, const BlePeerDevice& utopic, void* context) {
Serial.print("UTOPIC LEN CALLBACK: ");
Serial.print(len);
Serial.print("\n");
_utopicPaired = true;
}
setup(){
utopicPairingCharacteristic.onDataReceived(onDataPairedUtopic, NULL);
}
void loop() {
bleDevices = BLE.scan(scanResults, SCAN_RESULT_MAX);
for (int i=0; i<bleDevices; i++) {
nameLength = scanResults[i].advertisingData.deviceName(nameBuffer, BLE_MAX_ADV_DATA_LEN);
String name = scanResults[i].advertisingData.deviceName();
size_t svcCount = scanResults[i].advertisingData.serviceUUID(&foundInitService, 1);
if (nameLength > 0 ) {
if (strcmp(nameBuffer, "UTOPIC") == 0) {
utopicAddress.operator=(scanResults[i].address);
utopic = BLE.connect(utopicAddress);
if (utopic.connected()){
if(utopic.getCharacteristicByUUID(utopicPairingCharacteristic, mldpDataPrivateChar)){
while (_utopicPaired == false)
{
size_t msgOk = utopicPairingCharacteristic.setValue("!");
Serial.print("\nMessage ok UTOPIC: ");
Serial.print(msgOk);
Serial.print("\n");
delay(2000);
}
} else {
Serial.printlnf("Characteristic UTOPIC not found");
}
}
}
}
}
}
}
编辑:
我通过电子邮件向智能锁的支持人员发送了电子邮件,他们告诉我他们不授予除手机之外的任何其他蓝牙设备的权限。他们怎么知道它是什么类型的设备?有什么办法可以让锁以为我的设备是手机?