Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ESP32_S2_MINI, improve device support flexibility, improve debug logging and fix web control interface. #248

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Contributor

@andrewleech andrewleech commented Dec 13, 2023

This MR contains a whole bunch of changes in separate commits, let me know if you'd prefer them split out into separate MR's.

  • Allow specifying the UART number to use (ie different uart for debug and hvac connectsion).
  • Allow specifying the particular uart TX and RX pins for hvac
  • Enable debug logging if hvac uart doesn't conflict.
  • Send debug logging over mqtt as well (can be viewed in HA mqtt inspector)
  • Add support for ESP32-S2-MINI
  • Specify firmware binary name and display it on web upgrade page.
  • Fix a couple of issues with the web control page.

This all started when I wanted to upgrade an older unit I had running and it took me a while to remember what hardware I used. I thought it'd be handy to show the correct / expected build on the firmware upgrade page, eg.
image

I then wanted to test my changes on a separate esp32 module rather than the one tucked up in my aircon, but the only one I had handy was a newer esp32-s2, so I added support for that.

The default Serial object on the S3 is the internal USB port, not a uart. So I added support for specifying the desired UART via: build_flags = -DHVAC_UART=0

Finally I was having some more issues so wanted serial logging; now that hvac can be configured to run on a separate uart, I decided to make debug logging automatically enabled if HVAC is on a different uart to the default Serial output.

Copy link

@floatplane floatplane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love the idea of displaying board info, had some thoughts about alternative ways to achieve that!


# Allow the name of the binary to be reported by the webapp
env.Append(CPPDEFINES=[
("PIO_BINARY", binary_name)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think PIO_BINARY would be set for someone who compiles the sketch in the Arduino IDE, right? I mean, the clue is in the name 😄

I'm not a maintainer on this project, just an interested bystander - but instead of displaying a filename (which can change in future updates if someone decides to change the naming structure), WDYT about just showing the board info? It looks like the preprocessor gets a couple of helpful defines at compile time - here's what's generated when compiling in the IDE for my D1 Mini :

"-DARDUINO_BOARD=\"ESP8266_WEMOS_D1MINI\""
"-DARDUINO_BOARD_ID=\"d1_mini_clone\""

I got this by enabling verbose compile output in the Arduino IDE. It looks like these are set in platformio builds as well? Grepping for ARDUINO_BOARD_ID in my Arduino libraries folder looks promising:

❯ rg ARDUINO_BOARD_ID
packages/esp8266/hardware/esp8266/3.1.1/libraries/ESP8266mDNS/src/LEAmDNS.cpp
35:#ifndef ARDUINO_BOARD_ID
36:#define ARDUINO_BOARD_ID "generic"
1275:                || (!addServiceTxt(hService, "board", ARDUINO_BOARD_ID))
 
packages/esp8266/hardware/esp8266/3.1.1/platform.txt
131:recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DA>
134:recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_leve>
137:recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DA>
 
packages/esp8266/hardware/esp8266/3.1.1/tools/platformio-build.py
130:        ("ARDUINO_BOARD_ID", '\\"%s\\"' % env.BoardConfig().id),

I feel like displaying the board info would meet the need of "remind me what piece of hardware this is" without requiring any build hacking or prebuild scripts. I do think it's a great idea to display board info in the UI!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, I had no idea it was even possible to build this in Arduino ide (I've never used that before).

I did see those defines when I had verbose build enabled myself, but personally I didn't think they gave enough info, doesn't show which build profile was actually used etc.

Best of both however would be to use the PIO define if it exists, else the C code could fallback to the Arduino define.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, doing both makes sense to me! seems like they could just be on separate lines. there’s plenty of room on that page.

filename: PIO_BINARY | (not set)
target: ARDUINO_BOARD | (not set)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting, I had no idea it was even possible to build this in Arduino ide (I've never used that before).

it does seem like I need to get hip to using PlatformIO…I’m a total dabbler in the embedded world 🤣

@andrewleech andrewleech changed the title Add flexibility to device support Add support for ESP32_S2_MINI, improve device support flexibility, improve debug logging and fix web control interface. Feb 9, 2024
@andrewleech
Copy link
Contributor Author

I've spent some time today fixing the web control interface, I had found on an older unit as well as this S2 based one that many commands from the web control page just didn't seem to stick, or ended up selecting the wrong thing.

settings updates in change_states() were failing as the String.c_str() values go out of scope too quickly.
The scope of changes is now more tightly controlled.

The control web page now auto-refreshes when settings changes are received from the hvac unit, either from external changes, mqtt changes or just delayed responses to web changes.

This should also fix #182

@andrewleech
Copy link
Contributor Author

ps. For anyone who wants to build this project without needing to install / configure PlatformIO I've got it building and flashing my esp32 board in docker with this little bash script:

IMAGE=shaguarger/platformio:6.1.9

if [ -z "$(docker ps -f "name=mitsubishi2mqtt" -f "status=running" -q )" ]; then

docker run --rm -d --name mitsubishi2mqtt -ti --privileged --net=host -v /dev:/dev \
  -v `pwd`:/workspace -w /workspace \
  $IMAGE sleep infinity

fi

docker exec -ti mitsubishi2mqtt pio run -e ESP32-S2-MINI -t upload

@andrewleech
Copy link
Contributor Author

My S2 MINI build is bow installed in a HVAC unit and needed a couple of extra fixes, these are now included in this branch.

@andrewleech
Copy link
Contributor Author

... But looking at the CI here, it appears some of my debug logging changes don't work on 8266, I'll have to look into that.

@andrewleech andrewleech force-pushed the device-support branch 2 times, most recently from cc817ae to 276db8b Compare April 30, 2024 06:54
settings updates in change_states() were failing as the
String.c_str() values go out of scope too quickly.
The scope of changes is now more tightly controlled.

More details are also logged if debug logging is enabled.

The control web page now auto-refreshes when settings changes
are received from the hvac unit, either from external changes,
mqtt changes or just delayed responses to web changes.
@andrewleech
Copy link
Contributor Author

Ok all the compatibility issues have been resolved, this change set should now work well on all platforms. It's been tested and is in active use on two HVAC units, running the esp32 and esp32s2 builds.
Web UI control works great now. I was previously also getting glitches with vane control from mqtt/ha on a previous release on esp32 which is also resolved with this build.
The debug messages over mqtt also help quite a lot at times.
The UART pins can also now be chosen for any platforms, but the default remains the same as official release / arduino default pins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants