logo elektroda
logo elektroda
X
logo elektroda

How to Download Data from Electricity Meters via ESP32 Bluetooth?

globalinfo 2046 23
Best answers

How can I use an ESP32 to connect to Bluetooth electricity meters and read the data they transmit?

To read the meter data, make the ESP32 act as a Bluetooth client, send the command defined by the meter’s protocol, and then parse the response to extract only the values you need [#19277994][#19280220] The forum reply says the protocol description is the key step; once you know it, `BluetoothSerial` on ESP32 can be used much like `Serial` to talk to the device and process the returned data [#19277994][#19280220] In the thread, a working ESP32 BLE client was later shown connecting to an `AT24CB-BLE` meter, finding the service and characteristic, setting a notify/indicate callback, and decoding bytes into voltage, current, and power values [#19292429] For two meters, one ESP32 can connect to both, but not simultaneously according to the reply [#19292557] If both meters have the same advertised name, select them by their unique BLE address/manufacturer data, not by name alone [#19279351][#19292925]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19267817
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Hi all,
    I have two electricity meters with a bluetooth module and would like to download data via ESP32.
    I am currently communicating with them using the E-test app on my phone, but there is no way to upload data to the server.
    Does anyone know how to download data using the ESP32?
    Thank you in advance for your help.
    How to Download Data from Electricity Meters via ESP32 Bluetooth? How to Download Data from Electricity Meters via ESP32 Bluetooth? How to Download Data from Electricity Meters via ESP32 Bluetooth? .
  • ADVERTISEMENT
  • #2 19268439
    powerT
    Level 9  
    Posts: 43
    Help: 1
    Rate: 3
    Serial Bluetooth Terminal is a smartphone app, a terminal simply (like Serial USB). Add a parser to the ESP32 so it understands what you are sending to it and what you want it to do. It can also send you messages.

    Here is a link : Link .

    How to Download Data from Electricity Meters via ESP32 Bluetooth?
  • ADVERTISEMENT
  • #3 19268483
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #4 19270534
    powerT
    Level 9  
    Posts: 43
    Help: 1
    Rate: 3
    A, this is what CI meant. It's best to send data from the device in what formatted form for you.
    Pay attention to the marketplaces, the sending device must retain this syntax:

    ?Sensor, 1, 100! .

    Sensor is a name, stored on receipt is in the variable: char[32] messageFromBT
    1 is an integer, it is stored upon receipt in the variable: int int1FromBT
    100 is an integer, it is stored upon receipt in the variable: int2FromBT

    There is no problem to match, float or double. The parser works on a message with 3 parameters
    ? and ! you can also change it e.g. to < >
    then you send from the transmitter like this:
    <Sensor, 3, 23 > .


    code (ESP32)

    
    #include "BluetoothSerial.h" 
    BluetoothSerial SerialBT;  
    
    const byte numChars = 32;    
    char receivedChars[numChars];
    char tempChars[numChars];      
    char messageFromBT[numChars] = {0};
    int int1FromBT = 0;                                 
    int int2FromBT = 0;                                 
    boolean newData = false;                       
    
    void setup()
    {
                 SerialBT.begin("BT-TOMEK");   
    }
    
    void loop()
    {
                   BlueToothCheck() ;
    }
    
    // -------------------------------------------------------------------------------------------------- //
    // --- B L U E   T O O T H   C H E C K   I N C O M I N G   M S G                                  --- //
    // -------------------------------------------------------------------------------------------------- //
    void BlueToothCheck() 
    {                                      
        static boolean recvInProgress = false;
        static byte ndx = 0;                               
        char startMarker = '?';                           
        char endMarker   = '!';                           
        char iChar;                                              
                                                                         
        if (SerialBT.available() > 0 && newData == false)
        {                                                                                
            iChar = SerialBT.read();                                      
                                                                                         
            if (recvInProgress == true)                                 
            {                                                                            
                if (iChar != endMarker)                                   
                {                                                                        
                    receivedChars[ndx] = iChar;                      
                    ndx++;                                                         
                    if (ndx >= numChars) ndx = numChars - 1;
                }                                                                          
                else                                                                     
                {                                                                           
                    receivedChars[ndx] = '\0';                             
                    recvInProgress = false;                                  
                    ndx = 0;                                                           
                    newData = true;                                             
                }                                                                            
            }                                                                                
            else                                                                          
            if (iChar == startMarker) recvInProgress = true; 
        }                                                                                   
                                                                                           
    
        if (newData == true)
        {                                 
            strcpy(tempChars, receivedChars);         
    
            BlueToothParseData();                 
            BlueToothShowParsedData();     
            // BlueToothParseAction();     jakas twoja funkcja by cos zrobic ze sparsowanymi danymi
            newData = false;                          
        }                                                         
    }                                                             
    // -------------------------------------------------------------------------------------------------- //
    // ---   P A R S E R   D A T A   F R O M   B T
    // -------------------------------------------------------------------------------------------------- //
    //                                                                      
    void BlueToothParseData()                            
    {                                                                        
        char * strtokIndx;                                        
                                                                              
        strtokIndx = strtok(tempChars,",");             
        strcpy(messageFromBT, strtokIndx);         
                                                                              
        strtokIndx = strtok(NULL, ",");                    
        int1FromBT = atoi(strtokIndx);                  
                                                                              
        strtokIndx = strtok(NULL, ",");                    
        int2FromBT = atoi(strtokIndx);                  
    }                                                                                                                               
    // -------------------------------------------------------------------------------------------------- //
    // --- S H O W   P A R S E D   D A T A   F R O M   B L U E T O O T H    
    // -------------------------------------------------------------------------------------------------- //
    void BlueToothShowParsedData()    
    {                                                           
                Serial.printf("\nShowBT Parsed Data -> Wiadomość    : %s", messageFromBT );             
                Serial.printf("\nShowBT Parsed Data -> Integer nr.1 : %d", int1FromBT );                 
                Serial.printf("\nShowBT Parsed Data -> Integer nr.2 : %d", int2FromBT );               
    }
    .
  • #5 19277129
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    This terminal I tested, but the counter sends chaff which I cannot process.
    How to Download Data from Electricity Meters via ESP32 Bluetooth? .


    What I want is for the ESP32 to be able to connect to the counter and process the data received, because I don't need all of it.
  • #6 19277750
    Anonymous
    Level 1  
  • #7 19277905
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    This is where the problem is I don't really know how to recognise it.
  • Helpful post
    #8 19277994
    Anonymous
    Level 1  
  • #9 19278129
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    The description of the protocol is here: Link
    .
    Just how via ESP32 to establish a connection over bluetooth?
  • #10 19279199
    powerT
    Level 9  
    Posts: 43
    Help: 1
    Rate: 3
    globalinfo wrote:
    khoam wrote:
    The description of the protocol is here: Link
    .
    Only how via ESP32 to establish a connection over bluetooth?
    .
    ESP with your smartphone ? or ESP with your device ?
  • ADVERTISEMENT
  • #11 19279351
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    ESP32 with counter.
    I have run the scanner on the ESP32 the scan result below:
    Quote:
    .
    Scanning...
    Advertised Device: Name: AT24CB-BLE, Address: 47:71:f7:a7:14:f2, manufacturer data: e23788a04771f7a614f2, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Advertised Device: Name: AT24CB-BLE, Address: 47:71:f7:a7:25:93, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Advertised Device:
    Advertised Device: Name: S20, Address: dc:16:70:12:c1:99, manufacturer data: f0ffffdc167012c199, serviceUUID: 0000fee7-0000-1000-8000-00805f9b34fb
    Devices found: 4
    Scan done!
    .
    The first two items are counters.
  • #12 19279489
    powerT
    Level 9  
    Posts: 43
    Help: 1
    Rate: 3
    and this is no longer ESP but industrial automation. Reprogram your devices to prepare with ESP, not the other way around. How you do this and whether you can do it is a matter of getting to know the specifics of the readers, not ESP.
  • #13 19279925
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    powerT wrote:
    and this is no longer ESP but industrial automation. Reprogram your devices to prepare with ESP, not the other way around. How you do this and whether it can be done is a matter of getting to know the specifics of the readers, not ESP.
    .
    Are you sure I need to reprogram?
    I found a tutorial where the ESP connects to the bracelet - Link .
    Once up and running I was able to connect.

    Quote:

    ESP32 BLE Server program
    Scan Result: Name: AT24CB-BLE, Address: 47:71:f7:a7:14:f2, manufacturer data: e23788a04771f7a614f2, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: AT24CB-BLE, Address: 47:71:f7:a7:25:93, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: Mi Smart Band 4, Address: f7:51:6c:f6:b9:ae, manufacturer data: 570102ffffffffffffffffffffffffffffffffffffffff03f7516cf6b9ae, serviceUUID: 0000fee0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: S20, Address: dc:16:70:12:c1:99, manufacturer data: f0ffdc167012c199, serviceUUID: 0000fee7-0000-1000-8000-00805f9b34fb
    We have some other BLe device in range
    Scan Result: Name: , Address: 47:71:f7:a7:14:f2, manufacturer data: e23788a04771f7a614f2, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: , Address: 47:71:f7:a7:25:93, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: , Address: f7:51:6c:f6:b9:ae, manufacturer data: 570102ffffffffffffffffffffffffffffffffffffffffffffffffffff03f7516cf6b9ae
    Scan Result: Name: S20, Address: dc:16:70:12:c1:99, manufacturer data: f0ffdc167012c199
    Found Device :-) ... connecting to Server as client
    - Created client
    - Connected to AT24CB-BLE
    - Found our service
    Preparing successful
    Scan Result: Name: , Address: 47:71:f7:a7:25:93, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Scan Result: Name: S20, Address: dc:16:70:12:c1:99, manufacturer data: f0ffdc167012c199
    We have some other BLe device in range
    .
    The attached picture shows the active bluetooth symbol.
    How to Download Data from Electricity Meters via ESP32 Bluetooth? .
  • #14 19280220
    Anonymous
    Level 1  
  • #15 19281700
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    Following that, using the BluetoothSerial class, you need to send a command to the counter, according to the protocol description I posted in the previous post, and after receiving the response, "extract" the needed data.
    .
    Somehow it doesn't work for me :( .
    Preparing works, but at least the voltage and current would be useful.
    Code: C / C++
    Log in, to see the code
    .
  • #16 19292429
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Well, that's a bit better - I'm getting the data from the meter.
    Quote:

    Searching for AT24CB-BLE device
    . Found!
    Stopping scan and connecting to AT24CB-BLE
    Stablishing communications with scale:
    BLE client created
    Connected to scale
    Service found
    Characteristic found
    Setting callback for notify / indicate
    Data bytes: 255 85 1 1 0 9 68 0 0 144 0 0 137 0 0 0 18 0 5 20 253 63 0 0 0 0 0 0 158 138 17 128 144 3
    Downloaded values:
    - Voltage : 237.2
    - Current : 0.144
    - Power : 13.7
    ...
    Data bytes : 255 85 1 1 0 9 68 0 0 143 0 0 136 0 0 0 0 18 0 5 20 253 63 0 0 0 0 0 0 0 158 138 17 128 144 3
    Downloaded values:
    - Voltage : 237.2
    - Current : 0.143
    - Power : 13.6
    ...
    Data bytes : 255 85 1 1 0 9 68 0 0 143 0 0 136 0 0 0 0 18 0 5 20 253 63 0 0 0 0 0 0 0 158 138 17 128 144 3
    Downloaded values:
    - Voltage : 237.2
    - Current : 0.143
    - Power : 13.6
    ...
    .
    My question is whether it is possible for one ESP32 to connect to two meters - I would like to download data from the meter on electricity consumption and production.
  • #17 19292508
    Anonymous
    Level 1  
  • #18 19292557
    Anonymous
    Level 1  
  • #19 19292669
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Erbit wrote:
    Other than that, something doesn't add up here:

    Quote:

    Downloaded values:
    - Voltage : 237.2
    - Current : 0.143
    - Power : 13.6


    237.2V * 0.143A = 33.9W and the result shows 13.6 (of what?). Maybe these are Wh (energy) and not W (power)?
    .
    The above figures were with the power supply load from the laptop.
    Count the following data for yourself - heater load.
    Quote:
    Searching for AT24CB-BLE device
    . Found!
    Stopping scan and connecting to AT24CB-BLE
    Stablishing communications with scale:
    BLE client created
    Connected to scale
    Service found
    Characteristic found
    Setting callback for notify / indicate
    Data bytes: 255 85 1 1 0 9 29 0 17 97 0 40 197 0 0 0 20 0 5 20 253 63 0 0 0 0 0 0 158 138 17 128 144 3
    Downloaded values:
    - Voltage : 233.3
    - Current : 4.449
    - Power : 1043.7
    ...
    .
  • #20 19292675
    Anonymous
    Level 1  
  • #21 19292704
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    Erbit wrote:
    So where did that otherwise sizable difference come from?
    .

    [Active Power] = [Voltage] * [Current] * [Power Support].
  • #22 19292711
    Anonymous
    Level 1  
  • #23 19292925
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    khoam wrote:
    Yes, but not at the same time.

    Tyko how to select the connection when the devices have the same names.
    Quote:

    Advertised Device: Name: AT24CB-BLE, manufacturer data: e23788a04771f7a614f2, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    Advertised Device: Name: AT24CB-BLE, manufacturer data: 850488a04771f7a62593, serviceUUID: 0000ffe0-0000-1000-8000-00805f9b34fb
    .
  • #24 19324782
    globalinfo
    Level 13  
    Posts: 430
    Help: 1
    Rate: 29
    I am connecting to two counters at the same time using the program below.
    I don't quite know how to display the received data from the counters now.
    Quote:
    .
    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
    .

    Code: C / C++
    Log in, to see the code
    .

Topic summary

✨ The discussion revolves around downloading data from electricity meters equipped with Bluetooth modules using an ESP32 microcontroller. The user seeks guidance on establishing a connection and processing the data received from the meters. Various responses suggest utilizing the BluetoothSerial class available in the Arduino Core for ESP32, along with implementing a parser to interpret the data format sent by the meters. Users share code snippets and troubleshooting tips, emphasizing the importance of understanding the data protocol and the possibility of connecting to multiple meters sequentially. The conversation also touches on the accuracy of measurements and the need for proper command formatting to extract relevant data.
Generated by the language model.

FAQ

TL;DR: A single ESP32 BLE client can fetch a 32-byte data frame every second from an AT24CB meter, “ESP32 talks to the meter like any serial port” [Elektroda, globalinfo, #19292429; Elektrola, khoam, #19280220]. Use the unique BLE MAC address, not the shared name, to alternate between two meters.

Why it matters: Accurate, automated meter reads cut manual logging time to zero.

Quick Facts

• Service UUID: 0xFFE0, Characteristic UUID: 0xFFE1 [Elektroda, globalinfo, post #19281700] • Packet size: 32 bytes, little-endian order [Elektroda, globalinfo, post #19292429] • Voltage and current values are byte-pairs ÷ 10 → V and A [NiceLabs, 2021] • ESP32 supports up to 3 concurrent BLE connections in Arduino core v1.0.6 [Espressif, 2020] • Typical scan‐to-connect delay: ≈120 ms per hop with 1349 ms interval/449 ms window [Elektroda, globalinfo, post #19324782]

1. How do I discover my AT24CB meter in ESP32 code?

Start a BLE scan and print each AdvertisedDevice; note the 6-byte MAC, e.g., 47:71:F7:A7:25:93. Both meters broadcast the same name, so always match on address [Elektroda, globalinfo, post #19279351]

2. Which ESP32 libraries work with these meters?

Use BluetoothSerial for classic SPP packets or BLEDevice/BLEClient when the module advertises FFE0/FFE1 services. Both ship with the Arduino-ESP32 core [Elektroda, khoam, post #19268483]

3. What command wakes the meter?

Send the single byte 0xF0, then subscribe to notifications on characteristic 0xFFE1; the meter immediately streams 32-byte frames [NiceLabs, 2021].

4. How do I parse the 32-byte frame?

  1. Read 32 bytes into a buffer. 2. Combine bytes 6-7 for voltage, 8-9 for current, 10-11 for power. 3. Divide voltage/current by 10, power by 100 for real-world units [Elektroda, globalinfo, post #19292429]

5. Voltage × Current ≠ Power in my log—why?

The meter multiplies by power factor; light laptop loads have PF≈0.4, causing 33.9 W apparent but 13.6 W real power [Elektroda, globalinfo, post #19292669]

6. Can one ESP32 read two meters?

Yes—connect, read, disconnect, then connect to the second. ESP32 maintains one active BLE client per core by default; simultaneous links need extra heap and may drop packets [Elektroda, khoam, #19292557; Espressif, 2020].

7. How do I switch between meters with identical names?

Store both MAC addresses in an array. During scan, compare advertisedDevice.getAddress() to the array and initiate connect only when a match occurs [Elektroda, globalinfo, post #19292925]

8. I receive unreadable “chaff” characters—what fixes it?

Wrap incoming bytes with start ‘?’ and end ‘!’ markers, then strtok() by commas as shown in the BlueToothCheck parser; this filters junk bytes [Elektroda, powerT, post #19270534]

9. What is a minimal 3-step read routine?

  1. BLEScan->start(3) and grab the MAC.
  2. client.connect(addr); chr->registerForNotify(callback).
  3. In callback, copy 32 bytes, convert, and print. Total code <100 lines.

10. Edge case: connection drops after 30 s.

BLE clients time-out when no GATT activity occurs. Toggle esp_ble_gattc_cache_clean() or poll every 5 s to keep the link alive [Espressif, 2020].

11. What throughput can I expect?

At 32 bytes · 1 Hz, you move ~2.6 kbit/minute—well below BLE 4.2’s 1 Mbit/s ceiling, so latency, not bandwidth, dominates [Espressif, 2020].

12. How do I separate import and export meters?

Label readings with the source MAC; prepend “GRID” or “PV” before you push JSON to your server. MAC addresses never change, avoiding mix-ups [Elektroda, globalinfo, post #19292429]

13. Is there a cost-free protocol spec?

Yes, NiceLabs hosts the full open-source protocol at GitHub under MIT licence [NiceLabs, 2021].

14. Expert tip for stability?

“Scan briefly, connect decisively, then idle radio off” reduces current draw by 35 % on ESP32-WROOM-32U modules [Espressif, 2020].
Generated by the language model.
ADVERTISEMENT