darrylb123 / ESP32_SMA-Inverter-MQTT

Arduino project to read SMA Inverter data via ESP32 bluetooth
MIT License
6 stars 4 forks source link

Testing/001 jsondochandling #3

Closed keerekeerweere closed 1 year ago

keerekeerweere commented 1 year ago

first refactored and working version

darrylb123 commented 1 year ago

Just noticed this. Looks very interesting. Are you going to merge it back with a pull request?

BTW, I added expire_after directives to the auto configure. I'm happy to wait until you are ready to merge before I make any other changes.

keerekeerweere commented 1 year ago

Hi, thanks for your interest. Was doing a PR towards another repo and launched this PR almost by mistake, that's why I closed it again :-)

If you're interested sure, I'll launch the PR taking the latest version into account.

FYI: will also include some other fixes that I encountered while making this code compatible with esphome and home assistant, since that's my goal.

darrylb123 commented 1 year ago

I'm very interested in your work. I would like to know what the fixes were, just out of interest. I will test your repo later. How would you like to handle my changes yesterday? I could roll them back so your pr applies cleanly then add them again manually.

Also, I don't seem to get any data from the line relay and inverter status, even though the data structure etc seems the same as sbfspot which works correctly. I hadn't looked too hard though.

On Sun, 30 Jul 2023, 7:48 pm keerekeerweere, @.***> wrote:

Hi, thanks for your interest. Funny thing is was doing a PR towards another repo and launched this PR almost by mistake, that's why I closed it again :-)

If you're interested sure, I'll launch the PR taking the latest version into account.

FYI: will also include some other fixes that I encountered while making this code compatible with esphome and home assistant, since that's my goal.

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/3#issuecomment-1657094075, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVPY3DKLFMACOSSSBETXSYUXFANCNFSM6AAAAAA2V7POR4 . You are receiving this because you commented.Message ID: @.***>

darrylb123 commented 1 year ago

Cloned your repo. Ran into a few issues, I assume mostly due to case sensitivity on linux (which I use). I have almost no experience with platformio (other than to compile tasmota). After fixing the case errors, I got this link error inside the expressif bluetooth library. /home/xxxxxx/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/espwroom32/libe2e/libBluetoothSerial.a(BluetoothSerial.cpp.o):(.literal._ZL8_stop_btv+0x18): undefined reference to `esp_spp_disconnect'

darrylb123 commented 1 year ago

$ git diff diff --git a/src/ESP32_SMA_Inverter_App.cpp b/src/ESP32_SMA_Inverter_App.cpp index 33682e6..383048b 100644 --- a/src/ESP32_SMA_Inverter_App.cpp +++ b/src/ESP32_SMA_Inverter_App.cpp @@ -214,7 +214,7 @@ void ESP32_SMA_Inverter_App::loadConfiguration() { appConfig.scanRate = doc["scanRate"] | 60 ; appConfig.hassDisc = doc["hassDisc"] | true ; appConfig.timezone = doc["timezone"] | "";

diff --git a/src/SMA_Inverter.cpp b/src/SMA_Inverter.cpp index f9b94f5..d3a9a5d 100644 --- a/src/SMA_Inverter.cpp +++ b/src/SMA_Inverter.cpp @@ -24,7 +24,7 @@ SOFTWARE.

include

include "SMA_Inverter.h"

-#include "SMA_utils.h" +#include "SMA_Utils.h"

include "BluetoothSerial.h"

include "ESP32_SMA_Inverter_App.h"

(END) +++ b/src/ESP32_SMA_Inverter_App.cpp @@ -214,7 +214,7 @@ void ESP32_SMA_Inverter_App::loadConfiguration() { appConfig.scanRate = doc["scanRate"] | 60 ; appConfig.hassDisc = doc["hassDisc"] | true ; appConfig.timezone = doc["timezone"] | "";

diff --git a/src/SMA_Inverter.cpp b/src/SMA_Inverter.cpp index f9b94f5..d3a9a5d 100644 --- a/src/SMA_Inverter.cpp +++ b/src/SMA_Inverter.cpp @@ -24,7 +24,7 @@ SOFTWARE.

include

include "SMA_Inverter.h"

-#include "SMA_utils.h" +#include "SMA_Utils.h"

include "BluetoothSerial.h"

include "ESP32_SMA_Inverter_App.h"

keerekeerweere commented 1 year ago

yes indeed, did some work on a branch here to finalize. I'll get back to you for an update and provide a version that's ok.

As for the plan of action. Let's get back to your initial version with the expire_after and work from that. I'll re-play the changes on a version that contains that modification and see how far I can get.

darrylb123 commented 1 year ago

Ok, the changes a pretty straight forward.

On Mon, 31 Jul 2023, 6:19 pm keerekeerweere, @.***> wrote:

yes indeed, did some work on a branch here to finalize. I'll get back to you for an update and a version that's ok.

As for the plan of action. Let's get back to your initial version with the expire_after and work from that. I'll re-play the changes on a version that contains that modification and see how far I can get.

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/3#issuecomment-1657894842, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVNJF6IJ6Z2JTZJNTWLXS5S7VANCNFSM6AAAAAA2V7POR4 . You are receiving this because you commented.Message ID: @.***>

darrylb123 commented 1 year ago

How are you going with it? I went to have a look at your progress and the repo is gone.

keerekeerweere commented 1 year ago

indeed, had some merge issues for the pull request. So I recreated the clone of the repo and now you should have a compiling version. haven't tested it yet. https://github.com/keerekeerweere/ESP32_SMA-Inverter-MQTT

FYI: also succeeded in creating a esphome compatible version, meaning it can be configured and deployed directly from homeassistants' esphome plugin. but that's another story. some issues remain there too. https://github.com/keerekeerweere/esphome_smabluetooth

keerekeerweere commented 1 year ago

fwiw, "Also, I don't seem to get any data from the line relay and inverter status," this is fixed in the esphome version, with 'translated return codes and such". Haven't had a chance to backport this into the fresh fork of this repo

darrylb123 commented 1 year ago

Just cloned your fork and tried a compile. I use Linux and tripped over a filename case. -#include "SMA_utils.h" +#include "SMA_Utils.h"

Won't link though. I'm not at all familiar with platformio and I'm not sure whether it's getting the correct library version?? libBluetoothSerial.a(BluetoothSerial.cpp.o):(.literal._ZL8_stop_btv+0x18): undefined reference to `esp_spp_disconnect'

keerekeerweere commented 1 year ago

ok, fixed the SMA_utils case thing. I believe platform.io is using this version of the BluetoothSerial https://github.com/espressif/arduino-esp32/tree/master/libraries/BluetoothSerial

if you want to try platform.io, just use vscode and add the platform.io plugin, the platformio.ini file should take care of the rest. I recently also used clion (much better a c++ coding and refactoring than vscode but a less intuitive on the platformio usage)

here is my vscode build output: `Processing espwroom32 (platform: espressif32; board: lolin_d32; framework: arduino)

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin_d32.html PLATFORM: Espressif 32 (6.3.2) > WEMOS LOLIN D32 HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa) PACKAGES:

darrylb123 commented 1 year ago

Found that if I remove my old platformio install and pulled a new set, the link errors went away. I started with a wiped esp32 and no wifi credentials in Config.h as i usually use ESPTouch to set the wifi login. I found I had to include the Wifi.Begin test logic inside the #ifdef

ifdef WIFI_SSID

//overriding ssid and hostname logD("wifi begin with ssid(%s) and password (.......)", WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); for (int w=0; w<=10 || WiFi.status() != WL_CONNECTED; w++) { delay(500); logD(".wifi."); }

else

WiFi.begin();

endif

logD("Using config");

keerekeerweere commented 1 year ago

changed to an intermediate version. compiles and has most of the fixes and doesn't crash any more.

2023-08-14 17:45:46.0930 I ESP32_SMA_MQTT { "Serial": 2100xxxxx1, "BTStrength": 70.98, "Uac": [ 237.90, 0.00, 0.00 ], "Iac": [ 0.59, 0.00, 0.00 ], "Pac": 0.14, "Udc": [ 260.59 , 0.00 ], "Idc": [ 0.58 , 0.00 ], "Wdc": [ 0.15 , 0.00 ], "Freq": 49.96, "EToday": 10.79, "ETotal": 24227.27, "InvTemp": 56.70, "DevStatus": 307, "GridRelay": 51 }

darrylb123 commented 1 year ago

Looking good. I went looking for the timezone code as the time was wrong for me (+10). You're obviously thinking about it. Were you thinking about Australia/Brisbane or +10

darrylb123 commented 1 year ago

Also, now that I'm getting meaningful data for GridRelay and Device Status. I checked SBFSpot and saw the lookup into the TAGDefsxx.h. Mine was returning 51 (Closed) for the grid relay and 307 (Ok) for device status. Should we just grab the most common tags from the list to return something useful??

keerekeerweere commented 1 year ago

Yes the rename of the codes into text is something interesting. I have done it on the esphome repo already. Might add that later on here too. Things seem to be working quite good now. change the hass autodiscovery and state topics quite somewhat to get them more clearly. Had some issues inside home assistant but it was due to the missing device configuration in the auto discovery topics, also fixed now. image

keerekeerweere commented 1 year ago

we should consider merging perhaps into a single repo ?

darrylb123 commented 1 year ago

Yes. How do you want to do it?

On Tue, 15 Aug 2023, 10:32 pm keerekeerweere, @.***> wrote:

we should consider merging perhaps into a single repo ?

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/3#issuecomment-1678854226, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVO7C2YGJG4GQ4OT3PDXVNT57ANCNFSM6AAAAAA2V7POR4 . You are receiving this because you commented.Message ID: @.***>

darrylb123 commented 1 year ago

I found and fixed a bug in the web configuration page when displaying the current AC V and A. I'll wait until we decide what we're doing with the single repo before applying. Here it is though: @@ -273,16 +273,16 @@ table, th, td {\ snprintf(tempstr, sizeof(tempstr), "MQTT Topic%s\n\

BT Signal Strength%4.1f %\n\ - Uac%15.1f V\n\ - Iac%15.1f A\n\ - Pac%15.1f kW\n\ + UacA: %15.1f ,B: %15.1f ,C: %15.1f V\n\ + IacA: %15.1f ,B: %15.1f ,C: %15.1f A\n\ + Pac%15.2f kW\n\ UdcString 1: %15.1f V, String 2: %15.1f V\n\ IdcString 1: %15.1f A, String 2: %15.1f A\n\ WdcString 1: %15.1f kW, String 2: %15.1f kW\n" , fulltopic , dispData.BTSigStrength - , dispData.Uac - , dispData.Iac + , dispData.Uac[0], dispData.Uac[1], dispData.Uac[2] + , dispData.Iac[0], dispData.Iac[1], dispData.Iac[2] , dispData.Pac , dispData.Udc[0], dispData.Udc[1] , dispData.Idc[0], dispData.Idc[1]
darrylb123 commented 1 year ago

Are you going to submit a pull request? I'd like to make a change to the HA auto configuration code.

keerekeerweere commented 1 year ago

Hi, just submitted the pull request. FYI: HA auto discovery already works on the version of the pull request :-)

darrylb123 commented 1 year ago

Yes, but I need to add device type so the kWh ends up in the energy tab.

On Tue, 29 Aug 2023, 4:04 am keerekeerweere, @.***> wrote:

Hi, just submitted the pull request. FYI: HA auto discovery already works on the version of the pull request :-)

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/3#issuecomment-1696118849, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVIQZ74MNSFPN6RHQB3XXTMT3ANCNFSM6AAAAAA2V7POR4 . You are receiving this because you commented.Message ID: @.***>