emonTx Arduino Shield v2.4 usable to send data to a pi or homeassisant?

The Shield does not come with a sketch, because there is no processor, so you must have had one at some point.

Post No.7 has a link where you might have downloaded the sketch from. If you did, it’s on your machine somewhere - unless you deleted it. (Don’t do that, you can’t ever get it back from the Arduino.)

Thanks Robert.

Perhaps I leaving out some history where. I bought and set this up years and years ago. I has been sitting in a cupboard, only got it out when I started this thread. So can’t remember what is on the UNO. Will have to config a new sketch and start from scratch.

Ok got the sketch and added you recommendation, but cant get it to compile:

Sketch:

/*
  EmonTx CT123 Voltage Serial Only example
  
  Part of the openenergymonitor.org project
  Licence: GNU GPL V3
  
  Author: Trystan Lea
*/

#include "EmonLib.h"

// Create  instances for each CT channel
EnergyMonitor ct1,ct2,ct3, ct4;

// On-board emonTx LED
const int LEDpin = 9;                                                    

void setup() 
{
  Serial.begin(9600);
  // while (!Serial) {}
  // wait for serial port to connect. Needed for Leonardo only
  
  Serial.println("emonTX Shield CT123 Voltage Serial Only example"); 
  Serial.println("OpenEnergyMonitor.org");
  
  // Calibration factor = CT ratio / burden resistance = (100A / 0.05A) / 33 Ohms = 60.606
  ct1.current(1, 60.606);
  ct2.current(2, 60.606);                                     
  ct3.current(3, 60.606);
  ct4.current(4, 60.606); 
  
  // (ADC input, calibration, phase_shift)
  ct1.voltage(0, 300.6, 1.7);                                
  ct2.voltage(0, 300.6, 1.7);                                
  ct3.voltage(0, 300.6, 1.7);
  ct4.voltage(0, 300.6, 1.7);
  
  // Setup indicator LED
  pinMode(LEDpin, OUTPUT);                                              
  digitalWrite(LEDpin, HIGH);                                                                                  
}

void loop() 
{ 
  // Calculate all. No.of crossings, time-out 
  ct1.calcVI(20,2000);                                                  
  ct2.calcVI(20,2000);
  ct3.calcVI(20,2000);
  ct4.calcVI(20,2000);
    
  // Print power 
  Serial.print(ct1.realPower);     
  Serial.print(" "); 
  Serial.print(ct2.realPower);
  Serial.print(" "); 
  Serial.print(ct3.realPower);
  Serial.print(" "); 
  Serial.print(ct4.realPower);
  Serial.print(" "); 
  Serial.print(ct1.Vrms);
  Serial.println();

   //Serial.print(F("MSG:")); Serial.print(EnergyMonitor.Msg);
        
      if (ct1) { Serial.print(F(",P1:")); Serial.print(emontx.P1); }
      if (ct2) { Serial.print(F(",P2:")); Serial.print(emontx.P2); }
      if (ct3) { Serial.print(F(",P3:")); Serial.print(emontx.P2); }
      if (ct4) { Serial.print(F(",P4:")); Serial.print(emontx.P2); }
    
  // Available properties: ct1.realPower, ct1.apparentPower, ct1.powerFactor, ct1.Irms and ct1.Vrms

  delay(5000);
}

Error:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

C:\Users\Darryl\Documents\Arduino\emonTx\emonTx.ino: In function 'void loop()':

emonTx:64:42: error: 'emontx' was not declared in this scope

    Serial.print(F("MSG:")); Serial.print(emontx.Msg);

                                          ^~~~~~

emonTx:66:14: error: could not convert 'ct1' from 'EnergyMonitor' to 'bool'

       if (ct1) { Serial.print(F(",P1:")); Serial.print(emontx.P1); }

              ^

emonTx:67:14: error: could not convert 'ct2' from 'EnergyMonitor' to 'bool'

       if (ct2) { Serial.print(F(",P2:")); Serial.print(emontx.P2); }

              ^

emonTx:68:14: error: could not convert 'ct3' from 'EnergyMonitor' to 'bool'

       if (ct3) { Serial.print(F(",P3:")); Serial.print(emontx.P2); }

              ^

emonTx:69:14: error: could not convert 'ct4' from 'EnergyMonitor' to 'bool'

       if (ct4) { Serial.print(F(",P4:")); Serial.print(emontx.P2); }

              ^

exit status 1

'emontx' was not declared in this scope

Nope, I have tried multiple ino sketches. Can get serial output to the serial monitor with correct values. But nothing happening in emonCMS. Does pick anything up in the emonub log, or populate any inputs.

In the emonhub.conf it shows the TXshield, but it doesn’t show it on the inputs page.

Not sure what to try, any suggestions?

I’m afraid you haven’t changed the bit you added to keep it consistent with the rest of the sketch. You need to replace the whole of loop( ) with this:

void loop() 
{ 
  // Calculate all. No.of crossings, time-out 
  ct1.calcVI(20,2000);                                                  
  ct2.calcVI(20,2000);
  ct3.calcVI(20,2000);
  ct4.calcVI(20,2000);
    
/*
  // Print power 
  Serial.print(ct1.realPower);     
  Serial.print(" "); 
  Serial.print(ct2.realPower);
  Serial.print(" "); 
  Serial.print(ct3.realPower);
  Serial.print(" "); 
  Serial.print(ct4.realPower);
  Serial.print(" "); 
  Serial.print(ct1.Vrms);
  Serial.println();

*/
   //Serial.print(F("MSG:")); Serial.print(EnergyMonitor.Msg);
        
      Serial.print(F("P1:")); Serial.print(ct1.realPower); 
      Serial.print(F(",P2:")); Serial.print(ct2.realPower); 
      Serial.print(F(",P3:")); Serial.print(ct3.realPower);
      Serial.print(F(",P4:")); Serial.print(ct4.realPower); 
      //Serial.print(F(",Vrms:")); Serial.print(emontx.ct1.Vrms*100.0); 
      Serial.println();
  // Available properties: ct1.realPower, ct1.apparentPower, ct1.powerFactor, ct1.Irms and ct1.Vrms

  delay(5000);
}

If you want the voltage, uncomment that line.

You won’t of course get anything through emonHub until the data format is correct, and as it hadn’t compiled, you weren’t sending it the correct format.

Then, in emonhub.conf, you will need to change whichever node it’s appearing as to this (assuming it’s Node 6):

[[6]]
    nodename = emontxshield
    [[[rx]]]
       names = power1, power2, power3, power4
       datacodes = h,h,h,h
       scales = 1,1,1,1
       units = W,W,W,W

If you do send the voltage, you’ll need this instead:

[[6]]
    nodename = emontxshield
    [[[rx]]]
       names = power1, power2, power3, power4,Vrms
       datacodes = h,h,h,h,h
       scales = 1,1,1,1,0.01
       units = W,W,W,W,V

And with a bit of luck (because I don’t have a Shield + Uno to test it on), that should work.

hi --if you get total frustrated you can always try this method – it not wired directly it connect the oemtx via wireles connection to what ever controller you want — Howto --emonTx - Shield ESPEASY and WEMOS R3 UNO
you need a wemos R3 uno/esp and and a oemtxshield

espeasy has a controller for oem to send to it via wireless connection or you can follow say this to a certain degree and send it directly to home assistant

The photo in post no.18 clearly shows there is NO radio fitted. Hence any method that required the radio will not apply.

the radio on the wemos R3 – one would assume since they have home automation software running it connected to router and has access to wireless network

Thanks Robert

Did what you said, can see the data in the serial monitor:
image

But still nothing coming through to emonCMS:

Doestn even show the emonTx Input at all.

Here is my emonhub.conf:

[interfacers]

### This interfacer manages the EmonTx3 ESP format serial
#[[SerialTx3e]]
 #    Type = EmonHubTx3eInterfacer
  #    [[[init_settings]]]
   #        # Un-comment line below if using RS485 adapter
    #       com_port = /dev/serial0
         #com_port = /dev/ttyRS485-0
         # default com port if using USB to UART adapter
         #com_port= /dev/ttyUSB0
      #     com_baud = 9600
     # [[[runtimesettings]]]
      #     pubchannels = ToEmonCMS,

[[SerialDirect]]
     Type = EmonHubSerialInterfacer
      [[[init_settings]]]
           com_port = /dev/ttyAMA0      # or /dev/ttyAMA0 or/dev/ttyACM0 etc
           com_baud = 9600              # to match the baud of the connected device
      [[[runtimesettings]]]
           pubchannels = ToEmonCMS,

        nodeoffset = 0
        nodename = Serial_Pi

        group = 210
        frequency = 433
        baseid = 5                              # emonPi / emonBase nodeID
        calibration = 230V                      # (UK/EU: 230V, US: 110V)
        quiet = true                            # Disable quite mode (default enabled) to enable RF packet debugging, show packets which fail crc
        # interval =  300                         # Interval to transmit time to emonGLCD (seconds)
        

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        mqtt_host = 127.0.0.1
        mqtt_port = 1883
        mqtt_user = emonpi
        mqtt_passwd = emonpimqtt2016

    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,

        # emonhub/rx/10/values format
        # Use with emoncms Nodes module
        node_format_enable = 1
        node_format_basetopic = emonhub/

        # emon/emontx/power1 format - use with Emoncms MQTT input
        # http://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/MQTT.md
        nodevar_format_enable = 1
        nodevar_format_basetopic = emon/

[[emoncmsorg]]
    Type = EmonHubEmoncmsHTTPInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,
        url = https://emoncms.org
        apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        senddata = 1                    # Enable sending data to Emoncms.org
        sendstatus = 1                  # Enable sending WAN IP to Emoncms.org MyIP > https://emoncms.org/myip/list
        sendinterval= 30                # Bulk send interval to Emoncms.org in seconds

#######################################################################
#######################          Nodes          #######################
#######################################################################

[nodes]

## See config user guide: https://github.com/openenergymonitor/emonhub/blob/emon-pi/conf/emonhub.conf

[[5]]
    nodename = emonpi
    [[[rx]]]
        names = power1,power2,power1pluspower2,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

[[6]]
    nodename = emontxshield
    [[[rx]]]
       names = power1, power2, power3, power4,Vrms
       datacodes = h,h,h,h,h
       scales = 1,1,1,1,0.01
       units = W,W,W,W,V

[[7]]
   nodename = emontx4
   [[[rx]]]
      names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
      datacodes = h,h,h,h,h,h,h,h,h,h,h,L
      scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
      units = W,W,W,W,V,C,C,C,C,C,C,p

grrr, about to give up. Data is going out, why can I not see it in emonCMS. So frustrating.

First, for future reference, when posting code or bash output, please put in 3 ‘backticks’ (found at the top left of the keyboard normally) on a line on their own, then the code, then 3 more backticks on a line following the code.

    ```
    code
    ```

If it is something like php you can add a language identifier that after the first 3 backticks so ```php

If you have thge serial data, you are getting close.

What we need now is the emonhub.log output from the start. Do a sudo systemctl restart emonhub.service and post the first 30 seconds of logs.

[edit]
How is this wired? I posted earlier…

On the Pi, open a miniterm session and see if you get serial data (edit for the right port and speed)

miniterm --rtscts /dev/ttyAMA0 115200

Thanks borpin.

Yeah I have the Tx to Tx.

I will do the back tick thing.

I cant run those commands as I can’t log into the pi via ssh. I took the card out and created /boot/ssh but still connection refused.

Any other way I can get you the log?

@borpin
Brian - you don’t need to swap wires if the output is getting into emonHub.

@dazzle_rsa
The output format you now have - you can see on the serial monitor - is in “key:value,” pairs. That’s the correct format for the EmonHubTx3eInterfacer, which is the one you have commented out.

Put that back in, and I think you should start seeing something.

Did you wait for it to fully boot?

Do it again and make sure (if creating the file in windows) it did not add an extension to the filename.

Add a monitor and keyboard.

That is still to be confirmed. The serial above is, I think, connected via the IDE. - COM18 is the clue I think.

Looking at the photos, the wires looked reversed.

I looked, but couldn’t tell from those.

When Darryl enables the correct interfacer, that’s one problem out of the way. At least we now know what’s actually coming out of his Shield.

I’ve spent quite a while ploughing through diagrams. Using the emonPi Shield drawing, and confirmed by the photo in the Wiki, I think the full serial connections are this:

Shield Signal Raspberry Pi
Name Pin Pin Name
GND 1 GND 6 GND
5 V 3 Power 2 5 V
“Tx” 4 ←data 8 Tx
“Rx” 5 data→ 10 Rx
RST 6 Reset 7 GPIO 4

Note: The Shield V2.4 and emonTx V3.4 send on the “Rx” pin and receive on the “Tx” pin. The emonTx V3.2 is labelled correctly.
The pin numbers (counting GND = 1) will always be correct.

For one-way data, with no programming from the Pi, only GND, 5 V & Data → are required.

Wiring diagram

And my wiring…

:+1: I’d completely forgotten that. It’s now in my “fount of all knowledge” file. The picture is much better than the Wiki one. And as for the wiring diagram or schedule in the Wiki…

1 Like

Hi Guys

Ok so this is where I am currently at after the suggestions:

This is the wiring I am using:

The data in the serial monitor of Arduino IDE is Key Value pairs:
image

My emonhub.conf:

#######################################################################
#######################      emonhub.conf     #########################
#######################################################################
### emonHub configuration file, for info see documentation:
### https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md
#######################################################################
#######################    emonHub  settings    #######################
#######################################################################

[hub]
### loglevel must be one of DEBUG, INFO, WARNING, ERROR, and CRITICAL
loglevel = DEBUG
### Uncomment this to also send to syslog
# use_syslog = yes
#######################################################################
#######################       Interfacers       #######################
#######################################################################

[interfacers]

### This interfacer manages the EmonTx3 ESP format serial
[[SerialTx3e]]
     Type = EmonHubTx3eInterfacer
      [[[init_settings]]]
           # Un-comment line below if using RS485 adapter
           com_port = /dev/serial0
         #com_port = /dev/ttyRS485-0
         # default com port if using USB to UART adapter
         #com_port= /dev/ttyUSB0
           com_baud = 9600
      [[[runtimesettings]]]
           pubchannels = ToEmonCMS,

[[SerialDirect]]
     Type = EmonHubSerialInterfacer
      [[[init_settings]]]
           com_port = /dev/ttyAMA0      # or /dev/ttyAMA0 or/dev/ttyACM0 etc
           com_baud = 9600              # to match the baud of the connected device
      [[[runtimesettings]]]
           pubchannels = ToEmonCMS,
           read_interval = 10
            nodename = 6

        group = 210
        frequency = 433
        baseid = 6                             # emonPi / emonBase nodeID
        calibration = 230V                      # (UK/EU: 230V, US: 110V)
        quiet = true                            # Disable quite mode (default enabled) to enable RF packet debugging, show packets which fail crc
        # interval =  300                         # Interval to transmit time to emonGLCD (seconds)
        

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        mqtt_host = 127.0.0.1
        mqtt_port = 1883
        mqtt_user = emonpi
        mqtt_passwd = emonpimqtt2016

    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

        # emonhub/rx/10/values format
        # Use with emoncms Nodes module
        node_format_enable = 1
        node_format_basetopic = emonhub/

        # emon/emontx/power1 format - use with Emoncms MQTT input
        # http://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/MQTT.md
        nodevar_format_enable = 1
        nodevar_format_basetopic = emon/

[[emoncmsorg]]
    Type = EmonHubEmoncmsHTTPInterfacer
    [[[init_settings]]]
    [[[runtimesettings]]]
        pubchannels = ToRFM12,
        subchannels = ToEmonCMS,
        url = https://emoncms.org
        apikey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        senddata = 1                    # Enable sending data to Emoncms.org
        sendstatus = 1                  # Enable sending WAN IP to Emoncms.org MyIP > https://emoncms.org/myip/list
        sendinterval= 30                # Bulk send interval to Emoncms.org in seconds

#######################################################################
#######################          Nodes          #######################
#######################################################################

[nodes]

## See config user guide: https://github.com/openenergymonitor/emonhub/blob/emon-pi/conf/emonhub.conf

[[5]]
    nodename = emonpi
    [[[rx]]]
        names = power1,power2,power1pluspower2,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

[[6]]
    nodename = emonTxShield
    firmware = emonTxShield
    hardware = emonTxShield
    [[[rx]]]
       names = power1, power2, power3, power4, Vrms
       datacode = h
       scales = 1,1,1,1,0.01
       units =W,W,W,W,V

[[7]]
   nodename = emontx4
   [[[rx]]]
      names = power1, power2, power3, power4, vrms, temp1, temp2, temp3, temp4, temp5, temp6, pulse
      datacodes = h,h,h,h,h,h,h,h,h,h,h,L
      scales = 1,1,1,1,0.01,0.1,0.1, 0.1,0.1,0.1,0.1,1
      units = W,W,W,W,V,C,C,C,C,C,C,p

Enabling the EmonHubTx3eInterfacer has made no difference.
Here is the EmonHub Log:

2021-03-14 21:46:07,797 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2021-03-14 21:46:07,800 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2021-03-14 21:46:07,802 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2021-03-14 21:46:07,803 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2021-03-14 21:46:07,805 WARNING  MainThread Setting emoncmsorg apikey: obscured
2021-03-14 21:46:07,806 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2021-03-14 21:46:07,807 INFO     MainThread Setting emoncmsorg senddata: 1
2021-03-14 21:46:07,808 INFO     MainThread Setting emoncmsorg sendstatus: 1
2021-03-15 08:09:56,860 INFO     MainThread Creating EmonHubTx3eInterfacer 'SerialTx3e'
2021-03-15 08:09:56,862 DEBUG    MainThread Opening serial port: /dev/serial0 @ 9600 bits/s
2021-03-15 08:09:59,709 DEBUG    MainThread Signal 15 received.
2021-03-15 08:09:59,753 INFO     MainThread Exiting hub...
2021-03-15 08:09:59,993 INFO     MainThread Exit completed
2021-03-15 08:10:03,010 INFO     MainThread EmonHub emonHub (emon-pi variant) v2.1.5
2021-03-15 08:10:03,012 INFO     MainThread Opening hub...
2021-03-15 08:10:03,013 INFO     MainThread Logging level set to DEBUG
2021-03-15 08:10:03,014 INFO     MainThread Creating EmonHubTx3eInterfacer 'SerialTx3e'
2021-03-15 08:10:03,018 DEBUG    MainThread Opening serial port: /dev/serial0 @ 9600 bits/s
2021-03-15 08:10:03,020 INFO     MainThread Creating EmonHubSerialInterfacer 'SerialDirect'
2021-03-15 08:10:03,023 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 9600 bits/s
2021-03-15 08:10:03,024 DEBUG    MainThread Setting SerialDirect pubchannels: ['ToEmonCMS']
2021-03-15 08:10:03,026 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2021-03-15 08:10:03,030 DEBUG    MainThread Setting MQTT pubchannels: ['ToEmonCMS']
2021-03-15 08:10:03,031 DEBUG    MainThread Setting MQTT subchannels: ['ToRFM12']
2021-03-15 08:10:03,032 INFO     MainThread Setting MQTT node_format_enable: 1
2021-03-15 08:10:03,032 INFO     MainThread Setting MQTT nodevar_format_enable: 1
2021-03-15 08:10:03,033 INFO     MainThread Setting MQTT nodevar_format_basetopic: emon/
2021-03-15 08:10:03,034 INFO     MainThread Creating EmonHubEmoncmsHTTPInterfacer 'emoncmsorg'
2021-03-15 08:10:03,036 DEBUG    MainThread Setting emoncmsorg pubchannels: ['ToRFM12']
2021-03-15 08:10:03,037 DEBUG    MainThread Setting emoncmsorg subchannels: ['ToEmonCMS']
2021-03-15 08:10:03,038 WARNING  MainThread Setting emoncmsorg apikey: obscured
2021-03-15 08:10:03,038 INFO     MainThread Setting emoncmsorg url: https://emoncms.org
2021-03-15 08:10:03,039 INFO     MainThread Setting emoncmsorg senddata: 1
2021-03-15 08:10:03,040 INFO     MainThread Setting emoncmsorg sendstatus: 1

And my feeds:

No data in any of them.

What on earth am I missing, I have a feeling it is something small.