Post data to emonpi and getting it thru MQTT ?

Hello,

I am using an emonpi to monitor my power consumption and collect data from emonTH ancestors sensors (stripped down emonTx fitted with DS18B20 only). I am also posting data from an IP device (a WeIO fitted with 2 DS18B20 and one DHT22 : http://interactingobjects.com/from-wifridge-to-weiofridge/ ) device using the Node API.

But, as I do with data coming in from CTs and RFM network, with the data coming from my WeIO, I would like to 

  • post it to another self hosted emoncms site
  • be able to access thru MQTT

Unfortunately, I can't get this to work.

As I understand it, only data coming in thru the EmonHubJeeInterfacer can be published the MQTT and only data published to MQTT can be published to EmonHubEmoncmsHTTPInterfacer.

Am I wrong ?

How could I published data coming from other IP devices (using the Node API) to MQTT and other emoncms site ? Is there a way to push data to EmonHub thru an API ? Or directly to MQTT ? 

Thanks in anticipation for your help.

JS

alexg's picture

Re: Post data to emonpi and getting it thru MQTT ?

i am also very interested in this

jsroques's picture

Re: Post data to emonpi and getting it thru MQTT ?

Hello again,

Can anybody help on this ?

Thanks.

JS

borpin123's picture

Re: Post data to emonpi and getting it thru MQTT ?

I've successfully started posting data from another system into EmonCMS.  I posted here about it.

The issue you may have come across is the phpmqtt_input.php script does not accept a valid JSON payload.  If you are trying to send data from a system that will only send valid JSON, then it will not work.

I don't use the mqtt system from emonhub so I can change the code.

So I have one system publishing an mqtt message via a python script to the mqtt broker (mosquitto) running on the EmonCMS system.  EmonCMS then picks up this message (subscribes to the broker) and the data appears as a node in EmonCMS.  You can also see the data directly by using mosquitto_sub.

HTH

Cheers, Brian

jsroques's picture

Re: Post data to emonpi and getting it thru MQTT ?

Hello Brian,

Thanks for your reply. I'll have a look at your post and PHP modifications and keep you posted !

Jean-Sébastien

jsroques's picture

Re: Post data to emonpi and getting it thru MQTT ?

Hello again,

I did get the posting to MQTT queue to work.

I posted

  • to the following topic : emonhub/rx/<nodeid>/values
  • in a "csv" format : 12,15,12,35 (in my cas, I can choose the format of what is sent)

It posts the values properly.

But... it is still not "propagated" to my other emoncms web site. So I am half way thru... and it seems that posting to MQTT is not sufficient. I need to get data posted to emonhub just like power data is posted. So now I will try Socket Interfacer. Bu I have a problem with it... Just posted a new question here: http://openenergymonitor.org/emon/node/11839

Thanks for your help.

Jean-Sébastien

 

glyn.hudson's picture

Re: Post data to emonpi and getting it thru MQTT ?

You will need to open up the MQTT port on your emonPi, run:

sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

Then you will be able to publish and subscribe to the MQTT feed from any device. See my blog post: http://openenergymonitor.blogspot.co.uk/2015/10/emonpi-nodered-and-mqtt.html

pb66's picture

Re: Post data to emonpi and getting it thru MQTT ?

@Glyn - Why did you stop using ufw ? " sudo ufw allow 1883/tcp " is so much more user friendly than iptables, Is there a distinct benefit ? coz personally I wouldn't know what that command above is doing exactly without doing some lookup.

Paul

alexg's picture

Re: Post data to emonpi and getting it thru MQTT ?

on the latest prebuilt sd card image i used the ufw route, somehow the iptables add route did not work for me when i tried it (after restart).

i can also confirm the above from jsroques, you cna post to that topic but it doesn t get propagated to my online emoncms, just local

 

jsroques's picture

Re: Post data to emonpi and getting it thru MQTT ?

Hello,

I did manage to post to MQTT (thanks to Glyn's blog article and Brian's post.) But in blog article, it is explained how to subscribe to a topic and post thru REST API, not MQTT. As Brian, I first expected the data to be posted to be in JSON format. That is why I struggled in the first place.

Because it is not propagated to my other emoncms, I tried the socket interfacer. I manage to send 1 "frame". And data is propagated to my other emoncms :-) but I then get disconnected. I've opened another post for that here.

About iptables, I don't know (yet) ufw but I can confirm that using iptables command does not set the configuration in a persistent way. If you reboot, you need to re-issue the command.

Thanks again for your help.

JS

 

glyn.hudson's picture

Re: Post data to emonpi and getting it thru MQTT ?

Ah cool, thanks I didn't realise ufw would work on the Pi. I Assumed since it was called 'Ubuntu firewall' it would not be in Debian. That's great. I've been using 

sudo apt-get install iptables-persistent

To make the iptables rules persistant 

pb66's picture

Re: Post data to emonpi and getting it thru MQTT ?

ah I see how the confusion could slip in as it's predominantly used in Ubuntu, but actually it's called Uncomplicated FireWall and not only is available for Raspbian via apt-get but I just discovered a ufw gui called "gufw" also available via apt-get (not that the gui will be of much use for the new image with all the graphical stuff removed)

https://wiki.ubuntu.com/UncomplicatedFirewall

Paul

TrystanLea's picture

Re: Post data to emonpi and getting it thru MQTT ?

Emonhub publishes node data on the topic emonhub/rx/<nodeid>/values with data in csv format as Jean mentioned.

A little info on implementation: The nodes module has a service called emoncms-nodes-service which runs the php script: nodes_mqtt_process.php found in /var/www/emoncms/Modules/nodes/nodes_mqtt_process.php. Line 9 defines the base topic that the nodes service listens to:
https://github.com/emoncms/nodes/blob/9.0/nodes_mqtt_process.php#L9

To check that the emoncms-nodes-service is running, run

sudo service emoncms-nodes-service status

jsroques's picture

Re: Post data to emonpi and getting it thru MQTT ?

Hello Trystan,

Thanks for this details.

I actually managed to send data to MQTT but the data was still not propagated to another self hosted emoncms instance. But I now understand a bit better how it works. I though in the first place that MQTT was in charge of "dispatching" data to both local and remote emoncms. But it is actually emonhub which does that thur the so called "interfacers". I finally manage to send data to emonhub thru socket interfacer after a few modifications in the php code.

So my setup is now working fine with the latest emonpi fw including Paul (pb66) update (Added missing imports).

So I now have an arduino Yùn measuring my fridge temps and outside temp / humidity send data to my emonpi thru the socket interfacer, which, in turn, send the data to a remote emoncms. I also have nodered monitoring the mqtt topics and sending out an email if any of them is not uptaded within 1 to 10 minutes. It's been running for almost a week now with no problems !

Thanks for your help.

Hope you had some nice Christmas and wish you a nice end of year :-)

JS

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.