darrylb123 / ESP32_SMA-Inverter-MQTT

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

refactoring, fixes and ha device discovery in mqtt #6

Closed keerekeerweere closed 10 months ago

keerekeerweere commented 10 months ago

using platform.io refactored into cpp code device, relay status fixed mqtt home assistant device discovery working

darrylb123 commented 10 months ago

I struggled with the Wifi configuration with ESPTouch. I suppose you put all your credentials in the #defines. I would like to have a sensible default when the ESP32 is first flashed. With no #defines for configuration. I then couldn't get the web page to display. In the end, I wiped my platformio install and re-installed via vscode. Seems to be fine now. I need to get my head around platformio. I've added timezone support using hours from UTC. Need to implement DST too.

darrylb123 commented 10 months ago

I've done some more work to allow adding to the HA Energy dashboard. Also copied your decoding map impletmentation for the esphome code. Do you want to add your name to the MIT license on the code files? Do you intend to maintain your fork, or just keep forking this code for changes in future? The README needs some work now as I don't think references to the Arduino setting are correct.

keerekeerweere commented 10 months ago

Hey,

Greetings

darrylb123 commented 10 months ago

Sounds like your long term plans are a lot more than I intended. Perhaps the best strategy is to retire my code and allow you to maintain it. I'm not very expert in git so I will need help merging my new code into your fork.

Right now, I'm working on the esptouch wifi settings. The same code works perfectly with Arduino. I expect the problems will be the expressif version in platformio. I've had to rebuild platformio a couple of times due to weird WiFi issues. Got any hints?

On Thu, Aug 31, 2023, 8:42 PM keerekeerweere @.***> wrote:

Hey,

  • interesting additions, especially the simplified enery management. I'll pickup them up for now.
  • One of my prio's would be to have OTA working. I've tried that in a branch but got timeout after initial handshake to start the OTA.
  • FYI: also played with the github actions. I have an automated build using the default config values. That should allow users to just download the binary firmware.elf and upload directly to their esp32 boards, some web upload action.
  • also every commit/push creates a release (for now, should be more fine-grained later on).
  • I'll be maintaining the fork, for now at least. Gives me some room to play with.
  • The readme file, yes, definitively needs some extra info. Also how to get started easily.
  • Another suggestion would be to notify the 'upstream' repo's that their work evolved.
  • eventually we could get in touch with the sbfspot maintainers to possibly merge up, since quite some codebase could actually by shared. in one of my attempts I even tried to add esp32 as an additional platform next to Linux or Windows, but it was a bit difficult to do it in a couple of hours only. But with their help that might just be possible. esp32 won't handle the storage like a windows/linux sqlite or mysql does, but could very well do that on an externaly hosted db if requried.

Greetings

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/6#issuecomment-1700798700, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVKWZQOW3CKBSHVHVULXYBTCDANCNFSM6AAAAAA4BYVT4M . You are receiving this because you modified the open/close state.Message ID: @.***>

darrylb123 commented 10 months ago

well it didn't work perfectly in Arduino, same wifi init log messages. Seems like the smartconfig problem was with my phone (Pixel 6A). A reboot of the phone and it works fine. I did change it so that it was less noisy on the serial port. Was printing a . every 500ms so it was a log line per . Now every 2000.

keerekeerweere commented 10 months ago

Yes sure, just remove the action under the .GitHub folder, or maybe you can disable it.

btw: it’s not (yet) working on my repo either. Still needs some fixes to get the version increment working correctly

darrylb123 commented 10 months ago

Yes, sorry. Discovered it a minute after I raised the comment. Went back and deleted it but the email had gone.

On Sat, 2 Sep 2023, 5:40 pm keerekeerweere, @.***> wrote:

Yes sure, just remove the action under the .GitHub folder, or maybe you can disable it.

btw: it’s not (yet) working on my repo either. Still needs some fixes to get the version increment working correctly

— Reply to this email directly, view it on GitHub https://github.com/darrylb123/ESP32_SMA-Inverter-MQTT/pull/6#issuecomment-1703754420, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTSUVOBS7RL3ABR4EIMWZTXYLPH3ANCNFSM6AAAAAA4BYVT4M . You are receiving this because you modified the open/close state.Message ID: @.***>

darrylb123 commented 10 months ago

At least once a day, it seems to hang until rebooted. I have the esp32 connected to the usb port on a Mikrotik router for power and discovered I can monitor the serial in a browser. I waited until it failed again and checked the output: 2023-09-03 03:43:46.0029 D ESP32_SMA_Inverter HasL2pckt: 0x7E?=0x00 0x656003FF?=0x01007004 2023-09-03 03:43:49.0935 D ESP32_SMA_Inverter
L1 Rec=18 bytes pkL=0x001f=31 Cmd=0x0002 2023-09-03 03:43:49.0935 D ESP32_SMA_Inverter HasL2pckt: 0x7E?=0x00 0x656003FF?=0x01007004 2023-09-03 03:43:52.0913 D ESP32_SMA_Inverter
L1 Rec=18 bytes pkL=0x001f=31 Cmd=0x0002 2023-09-03 03:43:52.0912 D ESP32_SMA_Inverter HasL2pckt: 0x7E?=0x00 0x656003FF?=0x01007004

It never seems to exit a do/while loop in getPacket(). It doesn't do it with my original code and I don't believe this has been touched, other than refactoring. I've put a limit of 20 retries in it for the moment...

A reset fixes it. I have my original code running on an inverter that does not have sbfspot also monitoring it. My sbfspot runs every 10 min so occasionally they might collide which triggers the issue. Sbfspot continues working though.

keerekeerweere commented 10 months ago

Hey, that seems weird.

I’ll integrate the max retries too. Good suggestion.

In any case seems related to the connect function…

darrylb123 commented 10 months ago

I haven't had failure with the retry limit in place. I'd say you were seeing the same unbounded retries error. I scan at 60 seconds to give sbfspot a chance.

Each morning, It can be 15 minutes after the sun comes up before the poll rate changes from 15min back to the configured scan rate. In the latest commit I have forced polling between 6AM and 6PM. If the publish sees power, it will scan at the configured rate anyway.

darrylb123 commented 10 months ago

Tidied the logic around night/day polling. Uses the grid relay or whether it is between 6AM and 6PM. You should be able to merge it into yours without any collisions.

darrylb123 commented 10 months ago

Changed to W for power, same as sbfspot. Had the same hang in getPacket() yesterday. I did catch a logged message that showed 4% bluetooth so I've changed it to reboot if the counter overruns. I'm now logging the output so hopefully get better data if it happens again.

darrylb123 commented 10 months ago

I've been capturing the log. Had one of the bluetooth signal issues which seems to hang getPacket(). The retry limit then reboot fixed it. image