EmonTx4 not showing in Emoncms

–update, I’m RTFM now on the page you linked Brian, to learn about the serial connection :slight_smile:

Thanks Brian for the suggestion. Makes perfect sense and convenient that the web UI can do this. Unfortunately it did not work. I stopped emonhub and clicked to start serialconfig / serialmonitor and it did not start.

So I tried running the command in my terminal session and got the message that this only works on a Raspberry Pi.

/var/www/emoncms/scripts/serialmonitor$ ./start.sh
Traceback (most recent call last):
  File "/var/www/emoncms/scripts/serialmonitor/serialmonitor.py", line 18, in <module>
    import RPi.GPIO as GPIO
  File "/home/pi/.local/lib/python3.10/site-packages/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!

So a quick google search led me to try:

screen /dev/ttyUSB0 115200,-ixon

which DID connect me.

EmonTx4 + EmonLibDB Continuous Monitoring Minimal Demo with rf
Starting reports every 9.80 seconds approx.

RF No Ack (1)
RF No Ack (2)
Report 0  AC present V1 = 244.45 V2 = 0.00 V3 = 0.00 f=50.25

Ch 1 I=0.047 W=0 VA=12 Wh=0 pf=0.0111
Ch 2 I=0.045 W=0 VA=11 Wh=0 pf=-0.0635
Ch 3 I=0.022 W=0 VA=5 Wh=0 pf=-0.0425
Ch 4 I=0.021 W=0 VA=5 Wh=0 pf=-0.0561
Ch 5 I=0.021 W=0 VA=5 Wh=0 pf=0.0010
Ch 6 I=0.009 W=0 VA=2 Wh=0 pf=-0.0225
Ch 7 I=0.008 W=0 VA=2 Wh=0 pf=-0.0663
Ch 8 I=0.009 W=0 VA=2 Wh=0 pf=-0.0407
Ch 9 I=0.009 W=0 VA=2 Wh=0 pf=-0.0153
Ch 10 I=0.008 W=0 VA=2 Wh=0 pf=-0.0103
Ch 11 I=0.008 W=0 VA=2 Wh=0 pf=-0.0659
Ch 12 I=0.009 W=0 VA=2 Wh=0 pf=-0.0988

I could see the periodic output of the sensor data (as shown above), but I couldn’t type anything. Tried with sudo also. Had to login on another terminal to killall screen to get out of it! haha. Maybe I have to press some arcane key command sequence to get into a mode where I can configure it?

I shall persist.

Good stuff on that page, thanks for reminding me about it: using-the-web-tool

I’ll try to round up the right cables to try the web tool if for some reason connecting to /dev/ttyUSB0 doesn’t let me hit the config page.

@TrystanLea - any reason for needing GPIO?

You might need to power off / power on to get to the config mode @Robert.Wall?

You can simply connect the TX4 directly to a PC and use something like PuTTY.

Ok so the issue is you have installed the Python GPIO module on your system, so it is returning the wrong Error for the catch!

Try changing it to ImportError and see if that works.

I only wrote the library and example sketches, I’ve not yet had time to study in detail how G&T have implemented it in their sketches.

In the ‘old’ emonTx V3 sketch, it required +++[cr][lf] as a “password” to permit changes. Does ?[cr][lf] give some help?
Also - bear in mind the USB C connector on the emonTx4 is orientation-sensitive.

I use the Arduino IDE.

Thanks Brian and Robert. I’m not up on python so it wasn’t clear what to change to ‘ImportError’ – I tried a few things with no change. BUT, if I just comment out that whole little section about the GPIO check there in /var/www/emoncms/scripts/serialmonitor/serialmonitor.py then it does not throw an error, I can see something in the webU (admin/serconfig).

I have 12 CT sensors on mine; it has the add-in extra board. The EmonTx4 Serial Config Tool page shows just 6 CTs, 1-6 all set for 20A. I do see the output of my sensors scroll by every 10 seconds.

I’m a bit afraid to try to send any commands since I have the 12 CTs and the box was pre-configured for them all.

I did try sending the L or l command to list settings but this had no effect. The output just keeps scrolling by every 10 seconds.

It sort of seems like my serial connection is read only from the sensor outputs. I’m just not sure what I’m supposed to see, but I’m not seeing a prompt at all.

I have a support thread open with Glyn, and he said changing it to JSON output would not help my situation. I’ll post the solution if one is found!

According to your post no. 7, you’re using the demo sketch which comes as part of the emonLibDB download. The definitely does not have any on-line calibration built in - its only purpose is to demonstrate how to use the library.
If you want to change the calibration, you need to get the source file, change whatever you need to change, recompile and reload it into the emonTx4. The Arduino IDE (with the appropriate libraries and extension for the Atmel -DB series) will do this.
The serial output was intended only for the human eye, if you need it in an “interfacer” format, then I’m afraid you’ll need to change it to suit the interfacer you will be using (like for calibration - get the source, edit - compile - upload). This is probably the reason for emonHub ignoring it.

I don’t know my way around Github, but the only other sketch I can find there for 12 channels

does not have any code for on-line configuration & calibration either, so IF this is what you have, you need to do the same - get the source file, change whatever you need to change, recompile and reload it into the emonTx4.
But it should print to the serial output (i.e. USB-C) the rms voltage and the 12 powers. For them to show up in emonHub, you need to do whatever emonHub needs to handle the serial input - I’m not up-to-date on the latest Interfacers.
The format of the output from this is
VRMS:234.56,P1:123,P2:234,P3:345,…etc…,P12:1201[cr][lf]

Caveat: This is completely untested.

If you want/need a ‘compatible’ serial output, you need to change (or comment out) the serial output you have in the sketch and substitute something like this:

//  for the EmonHubOEMInterfacer

Serial.print("V1: ");Serial.print(EmonLibDB_getVrms(1));
Serial.print(",V2:");Serial.print(EmonLibDB_getVrms(2));
Serial.print(",V3:");Serial.print(EmonLibDB_getVrms(3));
Serial.print(",f:");Serial.println(EmonLibDB_getLineFrequency());

// then the inside of the 'for' loop

Serial.print(",I");Serial.print(ch);Serial.print(":");Serial.print(EmonLibDB_getIrms(ch),3);,
Serial.print(",P");Serial.print(ch);Serial.print(":");Serial.print(EmonLibDB_getRealPower(ch));
Serial.print(",VA");Serial.print(ch);Serial.print(":");Serial.print(EmonLibDB_getApparentPower(ch));
Serial.print(",E");Serial.print(ch);Serial.print(":");Serial.print(EmonLibDB_getWattHour(ch));
Serial.print(",pf");Serial.print(ch);Serial.print(":");Serial.print(EmonLibDB_getPF(ch),4);
Serial.println();  // <--  this might need moving outside the loop
delay(20);

– always assuming you want/need everything for every channel. I’ve no idea whether emonHub can handle 64 key:value pairs in one go and I’d hazard a guess that nobody has tried before, so there’s every chance it will choke on it.

Ref:

Wow, thanks Robert! You just blew my mind but I think you nailed it. I guess I have more of a project on my hands than I bargained for. Thanks for taking the time to give me those specifics and examples.

Hello @lamixer replying here in reference to your support ticket, as I think the resolution of this might be useful for anyone else troubleshooting as well.

Here’s my understanding of your setup so far:

  1. You have an emonTx4 with the 6CT extender running the EmonTx4 + EmonLibDB Continuous Monitoring Minimal Demo with rf firmware.

  2. You are trying to connect this directly via USB to a local VM running emoncms.

  3. The standard data format of this firmware is not compatible with data over serial/USB.

The solution is to upload a different version of the EmonTx4 firmware that supports single phase 12 CT sensors and prints the output in the right format. This firmware example can be found here: https://github.com/openenergymonitor/emontx4/blob/main/firmware/EmonTx4_DB_12CT_WiFi/EmonTx4_DB_12CT_WiFi.ino

I would recommend following this guide in order to compile and upload the firmware using the Arduino IDE: Firmware — OpenEnergyMonitor 0.0.1 documentation

The EmonTx4_DB_12CT_WiFi firmware mentions WiFi in it’s name, the intention behind this firmware was to provide support for the EmonTx4 with 12 CT sensors when connected to an EmonESP WiFi board. This firmware is also suitable for your direct USB connection as the serial output format is the same.

I would also check the CT sensor calibration values while you are at it, see lines 127-141 https://github.com/openenergymonitor/emontx4/blob/main/firmware/EmonTx4_DB_12CT_WiFi/EmonTx4_DB_12CT_WiFi.ino#L127 the example is configured for 20A CT sensors on all channels.

1 Like

Hello. I’m getting close. I’m on a MacOS machine, have set up Visual Studio Code with the PlatformIO add-on installed. Cloned the github repo for emontx4 and attempt to compile emontx4 > firmware > EmonTx4_DB_12CT_Wifi by opening that folder.

Of course, it asks for a platformio.ini file.

Instructions elsewhere said the contents of this platformio.ini file should be the following:

[platformio]
default_envs = default
src_dir = .

[env]
platform = atmelmegaavr
framework = arduino
board = AVR128DB48
platform_packages =             ; Compiles without this set?
  ; DxCore AVD-DB
  platformio/framework-arduino-megaavr-dxcore@^1.5.6
  
board_build.f_cpu = 24000000L   ; 24 MHz
# board_hardware.oscillator = external

board_hardware.uart = uart3     ; May not be required? 
monitor_speed = 115200

lib_deps =
  https://github.com/SpenceKonde/OneWire.git#36e2604
  https://github.com/openenergymonitor/RFM69_LPL.git#909b91d
  https://github.com/openenergymonitor/emonEProm#avrdb
  https://github.com/openenergymonitor/EmonLibCM#avrdb

[env:default]
build_flags = -DUSING_OPTIBOOT  ; Upload via uart
upload_protocol = arduino
upload_speed = 115200
upload_flags = -v               ; Verbose


However, I wonder if that is not entirely correct when trying to use the DB type of firmware required by my board (12CT). I actually was able to build the standard 6CT version, as a test. lib_deps needs more items listed?

If I just forge ahead and try to compile the firmware I need, it will show error that emonLibDB.h is not available. I actually solved that by downloading it from Roberts page and copying it in to the root of this folder I’m working from.

Trying again, now I’m missing EEPROM.h and SPI.h and there’s a reference to emonLibCM also. I locate those files on github, copy to my directory, and give another go.

Generally, still not working. Obviously I have no idea what I’m doing.

I’ll keep trying, but any help would be appreciated (besides, ‘take a programming class’ though that would of course help).

lightly sanitized last run output:

Executing task: platformio run 

Processing default (platform: atmelmegaavr; framework: arduino; board: AVR128DB48)
-------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/AVR128DB48.html
PLATFORM: Atmel megaAVR (1.9.0) > AVR128DB48
HARDWARE: AVR128DB48 24MHz, 16KB RAM, 128KB Flash
PACKAGES: 
 - framework-arduino-megaavr-dxcore @ 1.5.6 
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
Converting EmonTx4_DB_12CT_WiFi_TSMod1.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 22 compatible libraries
Scanning dependencies...
Dependency Graph
|-- OneWire @ 2.3.5+sha.36e2604
|-- RFM69_LPL @ 0.0.0+20231004115937.sha.909b91d
|-- emonEProm @ 1.0.0+sha.b0859d6
|-- EmonLibCM @ 3.0.6+sha.90a4135
Building in release mode
Compiling .pio/build/default/src/EmonTx4_DB_12CT_WiFi_TSMod1.ino.cpp.o
Compiling .pio/build/default/lib710/OneWire/OneWire.cpp.o
Compiling .pio/build/default/libc15/RFM69_LPL/RFM69_LPL.cpp.o
Compiling .pio/build/default/lib4d4/emonEProm/emonEProm.cpp.o
Compiling .pio/build/default/libce6/EmonLibCM/emonLibCM.cpp.o
Compiling .pio/build/default/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART0.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART1.cpp.o
.pio/libdeps/default/emonEProm/emonEProm.cpp:12:10: fatal error: EEPROM.h: No such file or directory

****************************************************************
* Looking for EEPROM.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EEPROM.h"
* Web  > https://registry.platformio.org/search?q=header:EEPROM.h
*
****************************************************************

 #include <EEPROM.h>
          ^~~~~~~~~~
compilation terminated.
Compiling .pio/build/default/FrameworkArduino/UART2.cpp.o
In file included from .pio/libdeps/default/EmonLibCM/emonLibCM.cpp:76:0:
.pio/libdeps/default/EmonLibCM/emonLibCM.h:63:10: fatal error: SPI.h: No such file or directory

*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SPI.h"
* Web  > https://registry.platformio.org/search?q=header:SPI.h
*
*************************************************************

 #include <SPI.h>
          ^~~~~~~
compilation terminated.
Compiling .pio/build/default/FrameworkArduino/UART3.cpp.o
*** [.pio/build/default/lib4d4/emonEProm/emonEProm.cpp.o] Error 1
*** [.pio/build/default/libce6/EmonLibCM/emonLibCM.cpp.o] Error 1
Compiling .pio/build/default/FrameworkArduino/UART4.cpp.o
================================================= [FAILED] Took 0.47 seconds =================================================

Ah… I needed a little break. I re-read this part “Next install the libraries used by the main firmware, download and place these in your Arduino libraries directory” of the instructions and now I know what that means and will try using those links and update. But it’s lunch time now.

You don’t need that if you’re using emonLibDB. The two perform the same job, getting the power/energy data. But they can co-exist, there’s no need to remove one to use the other.

I’m afraid I can’t help if you feel the need to use platfromio. All the development work on emonLibDB was done with the Arduino IDE.

Ok, maybe I’ll switch. Does the Arduino IDE have to run on an Arduino board?

Here’s my attempt with the ‘correct’ xyz.h files:

 *  Executing task: platformio run 

Processing default (platform: atmelmegaavr; framework: arduino; board: AVR128DB48)
-------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/AVR128DB48.html
PLATFORM: Atmel megaAVR (1.9.0) > AVR128DB48
HARDWARE: AVR128DB48 24MHz, 16KB RAM, 128KB Flash
PACKAGES: 
 - framework-arduino-megaavr-dxcore @ 1.5.6 
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
Converting EmonTx4_DB_12CT_WiFi_TSMod1.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 22 compatible libraries
Scanning dependencies...
Dependency Graph
|-- OneWire @ 2.3.5+sha.36e2604
|-- RFM69_LPL @ 0.0.0+20231004115937.sha.909b91d
|-- emonEProm @ 1.0.0+sha.b0859d6
|-- EmonLibCM @ 3.0.6+sha.90a4135
Building in release mode
Compiling .pio/build/default/src/EmonTx4_DB_12CT_WiFi_TSMod1.ino.cpp.o
Compiling .pio/build/default/liba6e/OneWire/OneWire.cpp.o
Compiling .pio/build/default/libcfe/RFM69_LPL/RFM69_LPL.cpp.o
Compiling .pio/build/default/lib985/emonEProm/emonEProm.cpp.o
Compiling .pio/build/default/libb20/EmonLibCM/emonLibCM.cpp.o
Compiling .pio/build/default/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART0.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART1.cpp.o
.pio/libdeps/default/emonEProm/emonEProm.cpp:12:10: fatal error: EEPROM.h: No such file or directory

****************************************************************
* Looking for EEPROM.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EEPROM.h"
* Web  > https://registry.platformio.org/search?q=header:EEPROM.h
*
****************************************************************

 #include <EEPROM.h>
          ^~~~~~~~~~
compilation terminated.
Compiling .pio/build/default/FrameworkArduino/UART2.cpp.o
In file included from .pio/libdeps/default/EmonLibCM/emonLibCM.cpp:76:0:
.pio/libdeps/default/EmonLibCM/emonLibCM.h:63:10: fatal error: SPI.h: No such file or directory

*************************************************************
* Looking for SPI.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:SPI.h"
* Web  > https://registry.platformio.org/search?q=header:SPI.h
*
*************************************************************

 #include <SPI.h>
          ^~~~~~~
compilation terminated.
Compiling .pio/build/default/FrameworkArduino/UART3.cpp.o
*** [.pio/build/default/lib985/emonEProm/emonEProm.cpp.o] Error 1
*** [.pio/build/default/libb20/EmonLibCM/emonLibCM.cpp.o] Error 1
Compiling .pio/build/default/FrameworkArduino/UART4.cpp.o
========================================================== [FAILED] Took 0.47 seconds ==========================================================

 *  The terminal process "platformio 'run'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 


No IDE will run on an Arduino. Look at
https://docs.openenergymonitor.org/electricity-monitoring/arduino-ide/macoside.html

To the libraries list, you’ll need to add emonLibDB and RFM69_LPL

You won’t need RFu_JeeLib or GLCD_ST7565, and I can’t see why it’s asking for EEPROM.h because that’s not asked for in the source file I think you’re using. SPI.h is part of the Arduino IDE, as far as I’m aware.

I updated the platformio.ini to this

[platformio]
default_envs = default
src_dir = .

[env]
platform = atmelmegaavr
framework = arduino
board = AVR128DB48
platform_packages =             ; Compiles without this set?
  ; DxCore AVD-DB
  platformio/framework-arduino-megaavr-dxcore@^1.5.6
  
board_build.f_cpu = 24000000L   ; 24 MHz
# board_hardware.oscillator = external

board_hardware.uart = uart3     ; May not be required? 
monitor_speed = 115200

lib_deps =
  https://github.com/SpenceKonde/OneWire
  https://github.com/openenergymonitor/RFM69_LPL
  https://github.com/openenergymonitor/emonEProm#avrdb
  https://github.com/openenergymonitor/emonLibDB

[env:default]
build_flags = -DUSING_OPTIBOOT  ; Upload via uart
upload_protocol = arduino
upload_speed = 115200
upload_flags = -v               ; Verbose

only change was [Preformatted text](https://github.com/openenergymonitor/EmonLibCM#avrdb) to [Preformatted text](https://github.com/openenergymonitor/emonLibDB) which is clearly the correct one now for my set up.

Tantalizingly close, the attempt to compile leaves only the one error looking for EEPROM.h which seems to be sourced from emonEProm.cpp.o (that’s probably the wrong terminology):

Executing task: platformio run 

Processing default (platform: atmelmegaavr; framework: arduino; board: AVR128DB48)
-------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/AVR128DB48.html
PLATFORM: Atmel megaAVR (1.9.0) > AVR128DB48
HARDWARE: AVR128DB48 24MHz, 16KB RAM, 128KB Flash
PACKAGES: 
 - framework-arduino-megaavr-dxcore @ 1.5.6 
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)
Converting EmonTx4_DB_12CT_WiFi_TSMod1.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 22 compatible libraries
Scanning dependencies...
Dependency Graph
|-- OneWire @ 2.3.5+sha.36e2604
|-- RFM69_LPL @ 0.0.0+20231004175757.sha.b6dbef8
|-- emonEProm @ 1.0.0+sha.b0859d6
|-- emonLibDB @ 0.0.0+20231004175758.sha.c9bd452
Building in release mode
Compiling .pio/build/default/src/EmonTx4_DB_12CT_WiFi_TSMod1.ino.cpp.o
Compiling .pio/build/default/liba6e/OneWire/OneWire.cpp.o
Compiling .pio/build/default/libcfe/RFM69_LPL/RFM69_LPL.cpp.o
Compiling .pio/build/default/lib985/emonEProm/emonEProm.cpp.o
Compiling .pio/build/default/lib9f5/emonLibDB/emonLibDB.cpp.o
Compiling .pio/build/default/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART0.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART1.cpp.o
.pio/libdeps/default/emonEProm/emonEProm.cpp:12:10: fatal error: EEPROM.h: No such file or directory

****************************************************************
* Looking for EEPROM.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:EEPROM.h"
* Web  > https://registry.platformio.org/search?q=header:EEPROM.h
*
****************************************************************

 #include <EEPROM.h>
          ^~~~~~~~~~
compilation terminated.
Compiling .pio/build/default/FrameworkArduino/UART2.cpp.o
Compiling .pio/build/default/FrameworkArduino/UART3.cpp.o
*** [.pio/build/default/lib985/emonEProm/emonEProm.cpp.o] Error 1
Compiling .pio/build/default/FrameworkArduino/UART4.cpp.o
================================================= [FAILED] Took 0.45 seconds


Yes:

emonEProm.cpp has an include for EEPROM.h which I don’t know how to obtain… well, I have one, but not one that works apparently!

#include <Arduino.h>
#include <avr/pgmspace.h>
#include <EEPROM.h>
#include <emonEProm.h>

This must be another fault in platromio. I don’t use it because it’s malware in my book: when I tried it, it moved my downloaded stuff from Github - proof was scripts to do the download suddenly stopped because the destination directory wasn’t there.

Your work-around will be to copy EEPROM.h into the same place as all your OEM libraries.

Ouch, not a pleasant experience! I see why you stay away from it.

Regarding EEPROM.h, the weird thing is I do already have it sitting in the root directory with the other header files. I can’t remember where I grabbed it from, certainly could not be the file that is expected.

Thanks for your help. Maybe Trystan will be able to pop back here and sort me out.

If not I guess I’ll try to set up Arduino IDE. Maybe I’ll try the ‘portable’ linux download and run it on the machine that the emonTx4 is actually connected to.

Ok… after one newbie hurdle (or two) I got my custom firmware compiled using the legacy version of Arduino IDE and uploaded using avrdude on the machine that runs emonhub. Thanks for your help Robert!

I’m very pleased and can finally close some browsers windows I had open for reference!

1 Like