3-Phase Serial Connection - emonhub query

Hi,
I am brand new to emoncms so bear with me. I am running into some issues with the configuration of emonhub. My general setup is as follows:

  • emonTx 3.4 with 3xCT’s connected to 3 phases (240v, AU)
  • 9V AC power pack for the emonTx
  • direct serial connection to RPi3 running emonPi SD image
  • emonTx using 3-phase approximation sketch example with config changed to Serial (I think)

I have been able to get the emonTx to transmit over serial to the Pi and can confirm with Minicom that data is being transmitted successfully to the Pi (see below).

I have modified the emonhub conf to the following:

[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]

[[Serial]]
    type = EmonHubSerialInterfacer
    [[[init_settings]]]
        com_port = /dev/ttyAMA0
        com_baud = 115200
    [[[runtimesettings]]]
        pubchannels = ToEmonCMS,
        subchannels = ToRFM12,

[[MQTT]]

    Type = EmonHubMqttInterfacer
    [[[init_settings]]]
        mqtt_host = 127.0.0.1
        mqtt_port = 1883
        mqtt_user = emonpi
        mqtt_passwd = (removed)

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

        # emonhub/rx/10/values format
        # Use with emoncms Nodes module
        node_format_enable = 0
        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/

#My local emonCMS
#[[emonCMS]]
#    Type = EmonHubEmoncmsHTTPInterfacer
#    [[[init_settings]]]
#    [[[runtimesettings]]]
#        pubchannels = ToRFM12,
#        subchannels = ToEmonCMS,
#        url = http://127.0.0.1/emoncms
#        apikey = (removed)
#        senddata = 1
#        sendstatus = 1

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

[nodes]

## See config user guide: http://github.com/openenergymonitor/emonhub/blob/master/configuration.md

[[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

##Other nodes removed from this section that appear in the actual file

[[11]]
    nodename = 3phase
    [[[rx]]]
       #names = powerL1, powerL2, powerL3, power4, Vrms, temp1, temp2, temp3, temp4, temp5, temp6
       names = powerL1, powerL2, powerL3, power4, Vrms
       datacode = h
       #scales = 1,1,1,1,0.01,0.1,0.1,0.1,0.1,0.1,0.1
       scales = 1,1,1,1,0.01
       #units =W,W,W,W,V,C,C,C,C,C,C
       units =W,W,W,W,V

The output to emonhub.log is:

2017-02-12 14:47:13,842 DEBUG    MQTT       CONACK => Return code: 0
2017-02-12 14:47:13,943 INFO     MQTT       on_subscribe
2017-02-12 15:06:21,965 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2017-02-12 15:06:27,254 DEBUG    MainThread SIGINT received.
2017-02-12 15:06:27,254 INFO     MainThread Exiting hub...
2017-02-12 15:06:27,309 INFO     MainThread Exit completed
2017-02-12 15:06:27,784 INFO     MainThread EmonHub emonHub 'emon-pi' variant v1.2
2017-02-12 15:06:27,785 INFO     MainThread Opening hub...
2017-02-12 15:06:27,785 INFO     MainThread Logging level set to DEBUG
2017-02-12 15:06:27,786 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2017-02-12 15:06:27,787 INFO     MainThread MQTT Init mqtt_host=127.0.0.1 mqtt_port=1883 mqtt_user=emonpi
2017-02-12 15:06:27,788 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2017-02-12 15:06:27,889 INFO     MQTT       Connecting to MQTT Server
2017-02-12 15:06:27,892 INFO     MQTT       connection status: Connection successful
2017-02-12 15:06:27,892 DEBUG    MQTT       CONACK => Return code: 0
2017-02-12 15:06:27,993 INFO     MQTT       on_subscribe
2017-02-12 15:06:58,604 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2017-02-12 15:07:03,164 DEBUG    MainThread SIGINT received.
2017-02-12 15:07:03,164 INFO     MainThread Exiting hub...
2017-02-12 15:07:03,224 INFO     MainThread Exit completed
2017-02-12 15:07:03,637 INFO     MainThread EmonHub emonHub 'emon-pi' variant v1.2
2017-02-12 15:07:03,638 INFO     MainThread Opening hub...
2017-02-12 15:07:03,638 INFO     MainThread Logging level set to DEBUG
2017-02-12 15:07:03,638 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2017-02-12 15:07:03,639 INFO     MainThread MQTT Init mqtt_host=127.0.0.1 mqtt_port=1883 mqtt_user=emonpi
2017-02-12 15:07:03,641 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2017-02-12 15:07:03,742 INFO     MQTT       Connecting to MQTT Server
2017-02-12 15:07:03,744 INFO     MQTT       connection status: Connection successful
2017-02-12 15:07:03,745 DEBUG    MQTT       CONACK => Return code: 0
2017-02-12 15:07:03,846 INFO     MQTT       on_subscribe

As you can see from the log it emonhub doesn’t appear to be receiving any data. Can someone give me a steer in the right direction?

A couple of related queries:

  • should I delete all the unwanted nodes from the conf file?
  • how do I set up a local connection to emoncms (not .org) do I need an API key etc or is it done over the local MQTT connection?

Thanks.

Hi Mitch, Welcome to OEM.

Looking at your emonhub.log there is no attempt made to create a serial interfacer, you can see for instance, the MQTT interfacer created in the lines

2017-02-12 15:06:27,786 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT'
2017-02-12 15:06:27,787 INFO     MainThread MQTT Init mqtt_host=127.0.0.1 mqtt_port=1883 mqtt_user=emonpi

a closer look at your emonhub.conf reveals the interfacer “Type=” setting is wrongly spelled as “type=”. If you alter that you should see a line appear in emonhub.log to confirm the “Serial” interfacer is created and the connection tested at the baud defined. You do not need to restart emonhub for this setting edit to be picked up, just editing the conf file is enough.

Your serial output screenshot is a little confusing, it looks like there is some confusion over line endings and there is only a newline rather than a carriage return and newline combined, but that maybe just the way it is displayed using what ever serial terminal software you are using.

So I cannot be sure if you will see data pass through emonhub once you have edited the conf, it mostly depends if the serial prints are terminated correctly.

Great work, that was an excellent pickup. I have now made some progress. As you can see in the log I now get a serial connection.

2017-02-13 09:58:23,663 INFO     MainThread EmonHub emonHub 'emon-pi' variant v1.2
2017-02-13 09:58:23,663 INFO     MainThread Opening hub...
2017-02-13 09:58:23,664 INFO     MainThread Logging level set to DEBUG
2017-02-13 09:58:23,664 INFO     MainThread Creating EmonHubSerialInterfacer 'Serial' 
2017-02-13 09:58:23,665 DEBUG    MainThread Opening serial port: /dev/ttyAMA0 @ 115200 bits/s
2017-02-13 09:58:23,666 DEBUG    MainThread Setting Serial subchannels: ['ToRFM12']
2017-02-13 09:58:23,666 DEBUG    MainThread Interfacer: Subscribed to channel' : ToRFM12
2017-02-13 09:58:23,667 DEBUG    MainThread Setting Serial pubchannels: ['ToEmonCMS']
2017-02-13 09:58:23,667 DEBUG    MainThread Interfacer: Subscribed to channel' : ToRFM12
2017-02-13 09:58:23,668 INFO     MainThread Creating EmonHubMqttInterfacer 'MQTT' 
2017-02-13 09:58:23,669 INFO     MainThread MQTT Init mqtt_host=127.0.0.1 mqtt_port=1883 mqtt_user=emonpi
2017-02-13 09:58:23,670 DEBUG    MainThread MQTT Subscribed to channel' : ToEmonCMS
2017-02-13 09:58:23,771 INFO     MQTT       Connecting to MQTT Server
2017-02-13 09:58:23,773 INFO     MQTT       connection status: Connection successful
2017-02-13 09:58:23,774 DEBUG    MQTT       CONACK => Return code: 0
2017-02-13 09:58:23,875 INFO     MQTT       on_subscribe

I still don’t seem to be getting messages through. I am guessing that the print formatting should be OK in the sketch as I have not changed the 3-phase example (beyond config). I am assuming that I should see messages come through in the emonhub.log file? Is there any other setup I need to do in emonhub.conf ??

Alternatively I can poke through the emontx sketch for the exact print statements.

Thanks again.

Looking at the sketch, there are a couple of “newline” line endings that should be “newline + carriage return”, that would explain both the wonky serial prints in your screenshot and the lack of data passing through emonhub since emonhub is specifically looking for the “newline + carriage return” termination before processing the proceeding line (payload).

Lines 494 and 550 need to be changed from “Serial.print("\n");” to “Serial.println();

I’ve submitted a PR for the changes

Pull request from @pb66 has been merged, version has been bumped to V0.11.0 and a release with a compiled .hex has been relseased: Release Newline + carriage return line endings, fix for direct serial · openenergymonitor/emontx-3phase · GitHub

Thanks.

Thanks guys for all your help. Unfortunately I am travelling for the rest of the week so won’t be able to drop the updated sketch in the emonTx. Interesting I was reading through the same code on the plane and thought it was a little odd.

Thanks again and will update on my progress.

Sounds like you’re referring to Carriage return + linefeed.
(newline = CR+LF)

So I am back at home and have been able to modify the sketch as described and upload it to the emonTx. I am now getting values through that can be read by the Pi. There are still a few tidy up issues as you may have noticed that I am getting negative power value through. I assume I just need to turn the CT’s round.

There was one other point. In the emonhub.conf I had to change the datacode value from ‘h’ to ‘0’ to fix up some format issues.

I am definitely a few steps ahead now. Thanks for your help.

Possibly!! however check your order of phases is correct for the sketch, (from memory) I believe the 1st and 4th CT’s are configured to read the same phase as the AC adapter is on and the 2nd CT is for “the next phase” in rotation and the 3rd CT is for the last phase. Any deviation might result in a positive power reading negative due to the incorrect “correction” being applied to the Vrms signal during the realpower calculations

That sounds correct, the values being passed from the sketch via serial are full human readable value that therefore require “zero” decoding, hence the “0” datacode.