Publishing custom input from emonpi to emoncms.org

Hi all

I’ve had a look for anything that seems similar, but I haven’t found anything that helps, so forgive me if this is already answered but I couldn’t work out the thing to search for!

I’ve set up monitoring of a battery with a voltage divider connected to an arduino which is communicating on a serial interface to a raspberry pi, which in turn is posting that as an input to my local emonpi (makes sense to do this in case the internet is down).

What I would like to happen is for the emonpi to forward this input on to emoncms.org as it does with my usage and pv inputs. Is this something that can happen, or do I have to post it to both the emonpi and to emoncms.org from the first pi?

If you are posting direct to emonCMS on the emonPi then no, emonCMS cannot forward that data as emonCMS has no ability to forward data to other targets. Only emonHub can do that and if you are posting direct to emonCMS using a HTTP API request or by publishing MQTT then you are bypassing emonHub.

Can you confirm how exactly the data is passed for the RPi to the emonPi?

Assuming for the moment you are using HTTP API’s you can indeed change your script to post to both emonCMS targets (on the emonPi and emoncms.org). This is possibly the “easy” option but IMO it is not the best option, as you have already mentioned, you could lose data due to network outages etc.

If you were to post to emonHub on the emonPi instead of to emonCMS, emonHub could then post to as many emonCMS instances as you like, what emonHub adds to the mix is the fact it can buffer the data, so that when posting to emoncms.org and the internet goes down (for example) emonHub can buffer the data from your script and post it to emoncms.org later, after the network comes up again.

To post to emonhub from your RPi you would need to use an emonHub socket interfacer, there are several forum discussions explaining how to use socket interfacers, they are real easy to use, just not well documented and it would mean altering your script to post a different way, but you would need to do that to make it post to 2 locations anyway.

This.

Just adding some weight to the the socket interfacer as an option!

Until I actually created one and used it, it looked way too confusing and quite daunting. When I actually took the plunge though, it was quite straight forward.

1 Like

@pb66 @Greebo Thanks guys. I’ll try and have a look at emonHub this evening and see how I get on

Just had a chance to sort it out, took less than an hour, and most of that was me missing some really simple things. I followed https://github.com/openenergymonitor/emonhub/blob/emon-pi/configuration.md. The mistakes I made were as follows:

  • I put the code for
    [[mysocketlistener]]
        Type = EmonHubSocketInterfacer
        [[[init_settings]]]
                port_nb = 8080
        [[[runtimesettings]]]
                pubchannels = ToEmonCMS,
                timestamped = True
    
    at the bottom of the emonHub config, instead of the interfacers section.
  • It didn’t mention to restart emonHub, but that was required
  • On realising I had to restart emonHub I got an error message. I did an “emonPi update” which seemed to fix it
  • Its important that in the python code
    import socket, time
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(('emonpi ip', 8080))
    s.sendall(str(time.time())+' 98 3.8 1.6 5.2 80.3\r\n')
    
    the last digit of data doesn’t have a space before the \r\n

Once I got past those silly mistakes, it works perfectly with the code I had written previously to post via the http api, the input shows up on both my local emonPi and on emoncms.org.

If you omit timestamped = True in your interfacer definition, emonHub will timestamp the data for you instead of using time.time() in your Python sketch. Makes the Python even simpler :slight_smile:

What the doco is trying to say is that if you need to provide a specific timestamp in your data that isn’t “now”, that’s how you do it.

Ah ok, that makes sense (and was what I was doing before with the http api)