logo elektroda
logo elektroda
X
logo elektroda

How to Download Data from Electricity Meters via ESP32 Bluetooth?

globalinfo 1320 23
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19267817
    globalinfo
    Level 13  
    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  
    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?
  • #3 19268483
    khoam
    Level 42  
    There is a BluetoothSerial class available in Arduino Core for ESP32 that you can use for such things. Example: Link .
  • #4 19270534
    powerT
    Level 9  
    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  
    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.
  • ADVERTISEMENT
  • #6 19277750
    khoam
    Level 42  
    globalinfo wrote:
    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.
    .
    Do you know the format of this transmitted data?
  • #7 19277905
    globalinfo
    Level 13  
    This is where the problem is I don't really know how to recognise it.
  • Helpful post
    #8 19277994
    khoam
    Level 42  
    The description of the protocol is here: Link .

    I would also suggest that you ask the moderator to move this thread to the "automatics" section. The issue is multi-domain.
  • #9 19278129
    globalinfo
    Level 13  
    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  
    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  
    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  
    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  
    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
    khoam
    Level 42  
    globalinfo wrote:
    In the attached picture you can see the active bluetooth symbol.
    .
    So in the next step, using the class BluetoothSerial 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 necessary data. The BluetoothSerial class is "handled" analogously to the Serial class and there are quite a few examples on the web.
    Link .
    Link .
  • #15 19281700
    globalinfo
    Level 13  
    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  
    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  
  • ADVERTISEMENT
  • #18 19292557
    khoam
    Level 42  
    globalinfo wrote:
    I have a question as to 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.
    .
    Yes, but not at the same time.
  • #19 19292669
    globalinfo
    Level 13  
    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  
    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  
    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  
    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.
Summary generated by the language model.
ADVERTISEMENT