TransWikia.com

Integrating STM32 device with smart lock via BLE

Internet of Things Asked on August 23, 2021

I am using a Particle Boron to integrate with a Smart lock but I am not being able to do it. I’m using Particle’s BLE interface to connect to Bluetooth and start sending messages to the lock, and a callback to ‘listen’ for the lock’s response, but I get no response. I don’t know what I’m doing wrong since it seems to be pretty straight forward:

Code:

#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");
            }
          }
          }
        }
      }
    }
}

EDIT:

I emailed the smart lock’s support and they told me they do not give permissions to any other Bluetooth devices except mobile phones. How can they know what type of device it is? Is there any way to make the lock think my device is a phone?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP