EmonTX4 - Recovering from failed flash

Ok, so I am finally installing my 6 CT expansion board today. I have done the hardware part, soldered the header, very carefully connected CT7 before refitting the faceplate and put the EmonTX4 back on the wall.

I have been using it over serial to the EmonPi, so the instruction from the shop to use a specific build that would spit out valid serial strings that EmonHub would recognise, its the same instructions as the forum here:Trystan’s post on 12CT over serial

So following this guide in the manual:
https://docs.openenergymonitor.org/emontx4/6ct_expansion_board.html#firmware-guide

Alongside the firmware manual page:
https://docs.openenergymonitor.org/emontx4/firmware.html#how-to-compile-and-upload-firmware

I set the 12 CT values and followed the steps, compiled the firmware, loaded with avrdude (again using the manual guidance):

avrdude -C/opt/openenergymonitor/EmonScripts/update/avrdude.conf -v -pavr128db48 -carduino -D -P/dev/ttyUSB0 -b115200 -Uflash:w:EmonTx4_DB_12CT_WiFi.ino.hex 

All went OK and I started to see values again over serial, but lost some values that I had before like temperature and pulse (not using pulse, plan to use temp) but I was seeing 12 values over serial for power.

I then went to configure EmonHub for Radio on node 28/29 as I want to move the EmonPi now physically (to clear down the wall near the main CU which is in the WC).

It seems that the minimal firmware I was pointed to:
https://github.com/openenergymonitor/emontx4/tree/main/firmware/EmonTx4_DB_12CT_WiFi

Is minimal and has no RF enabled?

Went back to the manual and used the example file, changed the CT values to match my setup and compiled again as I did before (board/chip/port all set as per manual and before).

Copied over to EmonPi, ran avrdude as before, but flash just stopped at 51%…

pi@emonpi:~/12ct_wireless $ avrdude -C/opt/openenergymonitor/EmonScripts/update/avrdude.conf -v -pavr128db48 -carduino -D -P/dev/ttyUSB0 -b115200 -Uflash:w:EmonTx4DB_rf_copy_PW_April24.ino.hex 

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/opt/openenergymonitor/EmonScripts/update/avrdude.conf"
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyUSB0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 115200
avrdude-original: Using autoreset DTR on GPIO Pin 7
                  AVR Part                      : AVR128DB48
                  Chip Erase delay              : 0 us
                  PAGEL                         : P00
                  BS2                           : P00
                  RESET disposition             : dedicated
                  RETRY pulse                   : SCK
                  serial program mode           : yes
                  parallel program mode         : yes
                  Timeout                       : 0
                  StabDelay                     : 0
                  CmdexeDelay                   : 0
                  SyncLoops                     : 0
                  ByteDelay                     : 0
                  PollIndex                     : 0
                  PollValue                     : 0x00
                  Memory Detail                 :

                                           Block Poll               Page                       Polled
                    Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
                    ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
                    signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                    prodsig        0     0     0    0 no        125  125      0     0     0 0x00 0x00
                    fuses          0     0     0    0 no          9   16      0     0     0 0x00 0x00
                    fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse6          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse7          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse8          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    lock           0     0     0    0 no          4    1      0     0     0 0x00 0x00
                    data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
                    flash          0     0     0    0 no     131072  512      0     0     0 0x00 0x00
                    eeprom         0     0     0    0 no        512   32      0     0     0 0x00 0x00

                  Programmer Type : Arduino
                  Description     : Arduino
                  Hardware Version: 3
                  Firmware Version: 25.1
                  Vtarget         : 0.3 V
                  Varef           : 0.3 V
                  Oscillator      : 28.800 kHz
                  SCK period      : 3.3 us

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude-original: Device signature = 0x1e970c (probably avr128db48)
avrdude-original: reading input file "EmonTx4DB_rf_copy_PW_April24.ino.hex"
avrdude-original: input file EmonTx4DB_rf_copy_PW_April24.ino.hex auto detected as Intel Hex
avrdude-original: writing flash (17188 bytes):

Writing | ##########################                         | 51% 1.26sstrace: |autoreset: Broken pipe

Which was worrying… I left it alone but nothing changed, something has gone wrong.

Can’t see any errors in the process, and the steps I followed from the manual are identical to the ones I followed the first time with the serial sketch just using the File > Examples > emonLibDB > Examples > EmonTx4DB_rf as the starting point.

I CTRL-C this in the end as it didn’t move. Tried to re-load the default firmware to get back to a starting position as per the manual guide for pre-complied fw loading:

pi@emonpi:~/12ct_wireless $ avrdude -C/opt/openenergymonitor/EmonScripts/update/avrdude.conf -v -pavr128db48 -carduino -D -P/dev/ttyUSB0 -b115200 -Uflash:w:EmonTxV4_LPL.hex:i 

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/opt/openenergymonitor/EmonScripts/update/avrdude.conf"
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyUSB0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 115200
avrdude-original: Using autoreset DTR on GPIO Pin 7
                  AVR Part                      : AVR128DB48
                  Chip Erase delay              : 0 us
                  PAGEL                         : P00
                  BS2                           : P00
                  RESET disposition             : dedicated
                  RETRY pulse                   : SCK
                  serial program mode           : yes
                  parallel program mode         : yes
                  Timeout                       : 0
                  StabDelay                     : 0
                  CmdexeDelay                   : 0
                  SyncLoops                     : 0
                  ByteDelay                     : 0
                  PollIndex                     : 0
                  PollValue                     : 0x00
                  Memory Detail                 :

                                           Block Poll               Page                       Polled
                    Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
                    ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
                    signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                    prodsig        0     0     0    0 no        125  125      0     0     0 0x00 0x00
                    fuses          0     0     0    0 no          9   16      0     0     0 0x00 0x00
                    fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse6          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse7          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    fuse8          0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    lock           0     0     0    0 no          4    1      0     0     0 0x00 0x00
                    data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
                    flash          0     0     0    0 no     131072  512      0     0     0 0x00 0x00
                    eeprom         0     0     0    0 no        512   32      0     0     0 0x00 0x00

                  Programmer Type : Arduino
                  Description     : Arduino

Currently I am here - is there a way to reset the EmonTX or recover from a failed flash?

Not sure where I went wrong, as it all went OK the first time (serial only) I assume it’s a problem with the second time I complied from the example but now a bit stuck - any tips how to recover appreciated!

In case its relevant, the other change was to flash my EmonPi (original) to the LowPowerLabs firmware, so it can talk to the EmonTX4, the next step was to then get the EmonTX V3’s and change them over as at the moment all my TX are on JeeLib classic still.

I have just noticed that I am getting this error in EmonHub constantly now, I actually just tried to flash the JeeLib Classic back on the EmonPi so I can get logging back again on the EmonTX3 but still see the same messages - so maybe I was foolish anyway an the EmonTX not reporting over radio was another problem with that change and not that the original serial FW does not do radio packets!

Errors:

2024-04-06 16:33:22,715 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2024-04-06 16:33:22,716 INFO     MainThread Opening hub...
2024-04-06 16:33:30,753 WARNING  RFM2Pi     1 RX data length: 40 is not valid for datacodes ['h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'L']
2024-04-06 16:33:40,654 WARNING  RFM2Pi     4 RX data length: 40 is not valid for datacodes ['h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'L']
2024-04-06 16:33:50,485 WARNING  RFM2Pi     6 RX data length: 40 is not valid for datacodes ['h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'L']
2024-04-06 16:34:00,373 WARNING  RFM2Pi     8 RX data length: 40 is not valid for datacodes ['h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'h', 'L']

EDIT: Ok this is an undocumented change in the CM FW, my EmonPi is 2016 vintage and so has an old config line.

This post explained the change:
https://community.openenergymonitor.org/t/emonpi-continuous-sampling-firmware-no-readings/23221/7

I would note that the manual is outdated and still contains the lines/format that I had in my emonhub as a legacy set of values:
https://community.openenergymonitor.org/t/emonpi-continuous-sampling-firmware-no-readings/23221/7

From Manual and my historic config:

[[5]]
    nodename = emonPi
    [[[rx]]]
        names = power1,power2,power1_plus_power2,Vrms,T1,T2,T3,T4,T5,T6,pulseCount
        datacodes = h, h, h, h, h, h, h, h, h, h, L
        scales = 1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1,1
        units = W,W,W,V,C,C,C,C,C,C,p

Required values from post linked above:

[[5]]
    nodename = emonpi
    [[[rx]]]
       names = Msg, power1,power2,power1pluspower2,vrms,t1,t2,t3,t4,t5,t6,pulse1count,pulse2count,E1,E2
       datacodes = L, h, h, h, h, h, h, h, h, h, h, L, L, l, l
       scales = 1, 1,1,1, 0.01, 0.01,0.01,0.01,0.01,0.01,0.01, 1, 1, 1,1
       units = n,W,W,W,V,C,C,C,C,C,C,p,p,Wh,Wh

I could not seem to find the current “default” emonhub template on GitHub? Might be worth updating that manual page.

Anyway going to power cycle the EmonTX4 and mutter some magic incantations and hope for the best!

I don’t know if this will help - there’s a working r.f. example sketch for 12 power inputs in the zip download for emonLibDB. The file name for the .h file got tangled up in editing in the .cpp file, just change it to

#include "emonLibDB.h"

the same as the header file itself.

Thanks Robert, which zip are you referring to on the EmonPi, GitHub or?

The example in the manual:
File > Examples > emonLibDB > Examples > EmonTx4DB_rf

Does have that defined:

/*

"Minimal" sketch to demonstrate EmonLibDB, using LowPowerLabs RFM69 library.

Refer to the Application Interface section of the accompanying User Documentation (PDF file) for full details.

Released to accompany emonLibDB, version 1.0.0 6/5/2023 

Due to the limits imposed by the data format required by the radio module, it is necessary to split the data into
two packets sent consecutively. Each packet is sent from a different NodeID, but both relate to the same datalog period
and share the same message number.

The first packet contains values pertaining to CTs 1-6, the second packet to CTs 7 - 12. 
*/

#define Serial Serial3
#include <Arduino.h>

#include "emonLibDB.h"
#define EMONTX4          // Must be above "#include <RFM69_LPL.h>

#include <RFM69_LPL.h>

The one here V1.0.2:

https://community.openenergymonitor.org/t/emonlibdb-version-1-0-2/23535/7?u=robert.wall

Github is out of date.

Thanks Robert.

Post power cycle I managed to recover the EmonTX4 with avrdude to the default FW shipped in the base EmonPi image.

I will try you zip and check carefully before having another run at building and loading the 12 CR version.

Using Roberts example (changing the nodes from 10/11 to 28/29 to match the docs and what I had pre-set in EmonHub) I now have things working on 12 CT channels :grinning:

Failed flash can be recovered with power cycle it seems, @Robert.Wall your version was:
Released to accompany emonLibDB, version 1.0.1 22/11/2023

but the version in GitHub is:
Released to accompany emonLibDB, version 1.0.0 6/5/2023

Now to tackle the EmonTX3 to latest radio format…

The library is actually V1.0.2, as in the title to the Forum thread.

If you make changes to your existing emonTx3 code similar to the parts of the emonTx4 sketch that specifically relate to LPL, you should get there. In essence, you must include the library, initialise it (and invoke encryption), then call it to pass the data. The 12-channel sketch is complicated because there’s too much data to pass in one packet, so the V4 appears as two nodes in emonHub and emonCMS - but the data originates from the same report of the same sampling interval.

There are no concerns with power-cycling the AVR processor like there are with the SD card in the RPi.