BLE - reading data from two electricity meters.

Hello everyone.
Using the code below, we managed to connect with electricity bimeters.
Unfortunately, I am a beginner and I do not know how to read the transmitted values.

#include "BLEDevice.h"
static BLEAddress connAddr = BLEAddress("00:00:00:00:00:00");
static BLEScan* pBLEScan;

static unsigned long ms;
static unsigned long lastms = 0;
static unsigned long interval = 10000;
static boolean doConnect = false;

class MyClientCallback : public BLEClientCallbacks {
  void onConnect(BLEClient* pClient) {
    Serial.println("onConnect");
    Serial.printf("device connected: %s\n", pClient->getPeerAddress().toString().c_str());
  }
  void onDisconnect(BLEClient* pClient) {
    Serial.println("onDisconnect");
    Serial.printf("device disconnected: %s\n", pClient->getPeerAddress().toString().c_str());
  }
};

bool connectToServer() {
  Serial.printf("forming a connection to device %s\n", connAddr.toString().c_str());
  BLEClient* pClient = BLEDevice::createClient();
  Serial.println("ble created client");
  pClient->setClientCallbacks(new MyClientCallback());
  if (pClient->connect(connAddr)) {
    Serial.println("connected to ble server");
  }
  else {
    Serial.println("unable to connect to ble server");
  }
  doConnect = false;
}
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    if (advertisedDevice.getAddress().equals(deviceAddr1) || advertisedDevice.getAddress().equals(deviceAddr2)) { // advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(serviceUUID)) {
      Serial.printf("connect to %s \n", advertisedDevice.getAddress().toString().c_str());
      Serial.printf("device: %s\n", advertisedDevice.toString().c_str());
      pBLEScan->stop();
      connAddr = advertisedDevice.getAddress();
      doConnect = true;
    }
  }
};

void setup() {  
  Serial.begin(115200);
  Serial.println("Starting Arduino BLE Client application...");
  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan();
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setInterval(1349);
  pBLEScan->setWindow(449);
  pBLEScan->setActiveScan(true);
}

void loop() {
  if (doConnect) {
    connectToServer();
  }
  ms = millis();
  if (ms >= lastms + interval) {
    pBLEScan->start(5, false);
  }
  delay(1000);
}

Starting Arduino BLE Client application...
connect to 47:71:f7:a7:25:93
device: Name: AT24CB-BLE, Address: 47:71:f7:a7:25:93, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
forming a connection to device 47:71:f7:a7:25:93
ble created client
onConnect
device connected: 47:71:f7:a7:25:93
connected to ble server
connect to 47:71:f7:a7:14:f2
device: Name: AT24CB-BLE, Address: 47:71:f7:a7:14:f2, manufacturer data: e23788a04771f7a614f2, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
forming a connection to device 47:71:f7:a7:14:f2
ble created client
onConnect
device connected: 47:71:f7:a7:14:f2
connected to ble server

You need to look at the data sheet for the meters and understand how to request and get a reading

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.