emonTH2 firmware fails to compile under platformio

I’ve just bought an additional emonTH2 to go with the four I already have. Of course, I need to flash new firmware to enable it to send on device id 27.

It’s ages since I played with PlatformIO, so I did the following to get a known good image before I started editing.

git clone https://github.com/openenergymonitor/emonth2
cd emonth2/firmware
pio run

it threw the following errors:

Processing lpl (platform: atmelavr; framework: arduino; board: uno)
-------------------------------------------------------------------------------------------------------------------------------------
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x97 in position 8: invalid start byte:
  File "/usr/local/Cellar/platformio/6.1.16/libexec/lib/python3.12/site-packages/platformio/builder/main.py", line 100:
    env = DefaultEnvironment(**DEFAULT_ENV_OPTIONS)
  File "/Users/garethhowell/.platformio/packages/tool-scons/scons-local-4.8.1/SCons/Defaults.py", line 82:
    _default_env = SCons.Environment.Environment(*args, **kwargs)
  File "/Users/garethhowell/.platformio/packages/tool-scons/scons-local-4.8.1/SCons/Environment.py", line 1208:
    platform(self)
  File "/Users/garethhowell/.platformio/packages/tool-scons/scons-local-4.8.1/SCons/Platform/__init__.py", line 138:
    return self.generate(*args, **kw)
  File "/Users/garethhowell/.platformio/packages/tool-scons/scons-local-4.8.1/SCons/Platform/darwin.py", line 58:
    lines = f.readlines()
  File "<frozen codecs>", line 322:

==================================================== [FAILED] Took 0.47 seconds ====================================================

Environment    Status    Duration
-------------  --------  ------------
lpl            FAILED    00:00:00.468
=============================================== 1 failed, 0 succeeded in 00:00:00.468 ===============================================

This is on a Mac running Sonoma and with python 3.11.

EDIT: I should have added that this is all within VSCode; which is my editor of choice.

I’ve just tested, it seems to work fine for me running PlatformIO Core, version 6.1.16

~/Documents/emonth2/firmware$ pio run 
Processing lpl (platform: atmelavr; framework: arduino; board: uno)
--------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR (4.0.0) > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES: 
 - framework-arduino-avr @ 5.1.0 
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
Converting emonth2.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 14 compatible libraries
Scanning dependencies...
Dependency Graph
|-- RFM69 @ 1.5.2+sha.d726805
|-- rfmTxLib @ 0.0.0+20240226133814.sha.a6ebb80
|-- rf69 @ 1.0.0+sha.1631384
|-- emonEProm @ 1.0.0+sha.b104ce5
|-- JeeLib @ 0.0.0+sha.6df2d8d
|-- Si7021 @ 0.0.0+sha.06fadfb
|-- OneWire @ 2.3.8
|-- DallasTemperature @ 3.11.0
|-- EEPROM @ 2.0
|-- Wire @ 1.0
|-- SPI @ 1.0
Building in release mode
Compiling .pio/build/lpl/src/emonth2.ino.cpp.o
/home/glyn/Documents/emonth2/firmware/emonth2_config.ino: In function 'void getSettings()':
/home/glyn/Documents/emonth2/firmware/emonth2_config.ino:162:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
         if (pass_result = getPass())
             ~~~~~~~~~~~~^~~~~~~~~~~
Linking .pio/build/lpl/firmware.elf
Checking size .pio/build/lpl/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  50.1% (used 1026 bytes from 2048 bytes)
Flash: [=======   ]  66.7% (used 21500 bytes from 32256 bytes)
========================= [SUCCESS] Took 2.64 seconds =========================

Environment    Status    Duration
-------------  --------  ------------
lpl            SUCCESS   00:00:02.637
========================= 1 succeeded in 00:00:02.637 =========================

Thanks, Glyn
You don’t say if this was on a Mac or not. In the end I just updated the emonTH2 from the serial monitor.

Ah sorry, I use Linux Ubuntu. I don’t have access to a mac. Glad you got it sorted :+1: