Experimenting with Node-RED Emoncms Node

I am looking for help configuring the Emoncms post node for Node-Red.  Has someone used the Post side of node-red-node-emoncms?

 

Details:
After reading Glyn’s post on Node-RED Emoncms Node I decided to give Node-Red a try.  My short-term (install, learn, test) goal is to grab the room temperature from the Nest and post it to my emonPi emoncms.  No real hard core reason why this is needed - I am trying Node-Red.

I’ve installed the following items on my Mac:
    •    node.js (v0.12.8)
    •    Node-RED (v0.12.2)
    •    node-red-node-emoncms (v0.0.6)
    •    node-red-contrib-nest (v0.1.6)

I can get these nodes (with flows) to work:
    •    Emoncms (In) Node:  Fetches last emoncms feed value, returns numerical value.
    •    Nest Request Node: Returns all Nest device data

But I am struggling with is the Post data to Emoncms.  There is no data written to Node 14 and no errors (that I can locate).  Here is how the nodes are configured:

Edit function node:   

msg.payload = {"name":"power1","value":"100","unit":"W"};
return msg;

Any thoughts on what I am doing wrong?

 

joyrider3774's picture

Re: Experimenting with Node-RED Emoncms Node

i have node-red flow's that work for input as well as output without a problem. i'm using it with a modified button widget to update a feed with the status of my wemo insight as well as turn onn / off my wemo insight from within emoncms. It works without a problem with me however i'm not using a function node at least i think so. I'm using a template node where i have written kitchencontrol:0 or kitchencontrol:1 and that's what i send to emoncms.

so i don't know if it has double quotes or needs single quotes or no quotes at all. What i did find out was that i to use the write api key and once i had to reenter it to make it work again but don't think that's the problem.

You could try using a template once to write to the emoncms node as a test and see if that works.

i don't use emonpi though my node red and emoncms are installed on a windows pc although that shouldn't make a diffrence either

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Willems - I changed the Function Node to a Template Node and no joy.  I tried your name & value of kitchencontrol:0 (without quotes), 'kitchencontrol:0',  "kitchencontrol:0", and {kitchencontrol:0} and none of those worked.  

I also tried updating the api RW key.

Not sure if this matters but I am using the low-write v8.5 of emoncms.  I wonder if I need to be on v9?!?

joyrider3774's picture

Re: Experimenting with Node-RED Emoncms Node

ah i don't know if you need emoncms v9.0 but i do have emoncms v 9.2 installed locally.

didn't the url /input/post.json can't remember exactly from the input api change over time ? if that's the case you need to adapt the source code of node-red-node-emoncms to to reflect to your old url if your input api is still also using /input/post.json that's not the problem then

that's the last thing i can think of

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

I don't know enough about the changes between version 8.5 and version 9.x since I am still on the old version.  Has anyone else used Node-Red and the Post side of node-red-node-emoncms?

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

I've just tested emoncms posting with latest version of nodeRED (V12.2). It worked fine for me, see below for screen grab and node export. 

 

 

[{"id":"4889044b.b776fc","type":"emoncms-server","z":"5a0f1398.a5f0ec","server":"http://192.168.0.35/emoncms","name":"emoncms local post"},{"id":"84272ebc.7bd8d","type":"inject","z":"5a0f1398.a5f0ec","name":"","topic":"","payload":"1,2,3,4","payloadType":"string","repeat":"","crontab":"","once":true,"x":474,"y":161,"wires":[["b8215cbe.47dea","d3862714.2c79d8"]]},{"id":"b8215cbe.47dea","type":"emoncms","z":"5a0f1398.a5f0ec","name":"Emoncms","emonServer":"4889044b.b776fc","nodegroup":"1","x":794,"y":130,"wires":[]},{"id":"d3862714.2c79d8","type":"debug","z":"5a0f1398.a5f0ec","name":"","active":true,"console":"false","complete":"false","x":787,"y":223,"wires":[]}]

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

In the above example I sent a CSV string "1,2,3,4", I also tested sending "power1:265,power2:123" and this worked ok. See screen grab below 

 

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

If your still having trouble try viewing the error log: 

$ tail /var/log/node-red.log 

borpin123's picture

Re: Experimenting with Node-RED Emoncms Node

I'm slightly lost here.  Does Node-Red replace an MQTT broker such as mosquitto or do you need both?  If ther is a good explanation somewhere I'd love to read it :)

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Glyn - Thank you for the images and the info!  I imported your JSON flow, updated the IP address, added my RW apikey and have the same issue.  

After looking at the above images, I think the issue may be you are posting to a local network version of emoncms and I am trying to post to the emoncms installed on the emonPi.

Does node-red have the ability to post to the emonPi (v2) emoncms (vlow-write-v8.5)?

 

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Brian - I just started looking at Node-Red on Monday (not an expert).  I don’t believe Node-RED replaces MQTT.  Node-Red enables a non-programmer to do “Browser-based flow editing. Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click.”  (from http://nodered.org)

Node-RED does have Nodes to access MQTT.  There are two that I have found.

The items I read thru are Glyn’s blogs about Node-Red:

and this from Node-RED

Hope this helps!

 

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

Correct, NodeRED does not run it's own MQTT server nor does it replace MQTT. In my blog post example I connected to the emonPi's Mosquitto MQTT server on port 1883. 

I was posting from a RaspberryPi running NodeRED to the emonPi running emoncms, both on my local network. I also tested posting to emoncms.org. 

I see no reason why it would not work posting to localhost. Are you running nodeRED on your emonPi and posting to emoncms on the same emonPi? Are you referencing the emoncms install in nodeRED via http://localhost in nodeRED or http://local IP address? 

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Glyn - For learning and testing purposes I am running Node-RED on my iMac and trying to post data to my emonPi emoncms.  Once I get things working I'll install Node-Red on the emonPi.  I am referencing emoncms via http://192.168.40.230/emoncms (see image below).  For what it is worth I can read values from the emoncms using the Node-RED "Emoncms In" (Fetches last emoncms feed value, returns numerical value.)

Does a firewall port need to be open on the emonPi?  I have port 1883 open.  Does anything need to be configured in the emonPi EmonHub Config Editor?

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

That all looks fine. Can you post to emoncms via your browser?

http://IPADDRESS/emoncms/input/post.json?json={power:200}&apikey=xxxxxxxx

You should see 'ok' responce 

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Yes, I receive an "ok" response, but I cannot locate where the value was written.  Does a node need to be defined in above json post?

 

 

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

Woops forgot the Node ID http://IP_ADDRESS/emoncms/input/post.json?node=1&json={power:200}&apikey=XXXXX

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

I posted this: http://192.168.40.230/emoncms/input/post.json?node=1&json={power:200}&apikey=myRWapikey.  And yes, I received an "ok" response, but I cannot locate where the value was written.  Nothing on the emonPi Node page and nothing in the emonhub or emoncms logs.

 

borpin123's picture

Re: Experimenting with Node-RED Emoncms Node

Hi Glyn,

You are using a JSON string of {power:200}.  In trying to debug what I am doing, I discover that running it through jsonlint, the string does not validate.  It needs to be {"power":200} to validate.

Or am I missing something?

Cheers, Brian.

borpin123's picture

Re: Experimenting with Node-RED Emoncms Node

I'll move this to a new thread.

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Glyn - I thought I had read somewhere (though I cannot locate it at the moment) that we could not post to the emonPI emoncms because it is low-write.  Did v9 (or v9.2) of emoncms change posting to the emonPI emoncms?

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

Hi Jon, 

Posting to Emoncms on the emonPi with low write should work in exactly the same way as usual. The data is stored in the /home/pi/data which is always mounted as RW 

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

I think I am making some progress by stumbling across something new (new to me!).  I was going through the input_controller.php code (/var/www/emoncms/Modules/input/input_controller.php) trying to determine why none of the above would work for me.  I came across some code that pointed me to http://192.168.40.230/emoncms/input/api.  This is the Input API Help webpage of Input API examples and this webpage pointed me to http://192.168.40.230/emoncms/input/view.  And this is where I located the POSTS and the data from the examples above.  Eureka!

So I starting digging thru the various menus on the emonPi emoncms and I could not locate the Inputs View menu item.  Is this not available?  (my wife tells me I am blind so I could be missing the obvious!)

 

glyn.hudson's picture

Re: Experimenting with Node-RED Emoncms Node

Ah good find! Very sorry I did not think of this sooner. We hid the Inputs menu on the emonPi as to not confuse users as the Nodes menu performs the same job in a more user friendly way.

As you have found you can access this menu by going to http://192.168.40.230/emoncms/input/view

The inputs menu will be exposed in the new version of the emonPi software we plan to launch in the next few weeks. 

Jon's picture

Re: Experimenting with Node-RED Emoncms Node

Glyn - glad we were able to figure it out!  Thank you!

As part of troubleshooting I was trying to get the http://emonPi_IP/emoncms/input/post.json?node=1&json={power:200}&apikey=myRWapikey to throw an error.  But when I typed an out-of-range Node number (node=41) it did not error.  It looks like there is code in "input_controller.php" to catch this (line 214).  Also the http://IPADDRESS/emoncms/input/post.json?json={power:200}&apikey=xxxxxxxx (without a node) was also accepted.

Only an incorrect apikey caused an error: "<br />
<b>Notice</b>:  Undefined index: write in <b>/var/www/emoncms/Modules/input/input_controller.php</b> on line <b>22</b><br />
". 

Comment viewing options

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