Skip to content

Mi Jia (MJ_HT_V1) reading #419

@eos1d3

Description

@eos1d3

I am trying to use ESP32 with PlatformIO (using Platform Espressif 32, 1.9.0) to scan
Mi Jia.

But from ZgatewayBT.ino, I find there is advertisedDevice.getServiceDataCount() and advertisedDevice.getServiceData(j) This means there are more than just one data in the callback. But the current ESP32 library does not have these, with only advertisedDevice.getServiceData().

That is why I can get UUID 0000180f-0000-1000-8000-00805f9b34fb data only. But no sensor data.

And would you please tell me which ESP library are you using? And how to read those data?

Thanks!

I am using example code to scan:

#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

int scanTime = 5; //In seconds
BLEScan* pBLEScan;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      
      Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
    }
};

void setup() {
  Serial.begin(115200);
  Serial.println("Scanning...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan(); //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);  // less or equal setInterval value
}

void loop() {
  // put your main code here, to run repeatedly:
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  Serial.print("Devices found: ");
  Serial.println(foundDevices.getCount());
  Serial.println("Scan done!");
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
  delay(2000);
}

And I get only this:
Advertised Device: Name: MJ_HT_V1, Address: 58:2d:34:34:0f:a1, serviceUUID: 0000180f-0000-1000-8000-00805f9b34fb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions