Sending Values from NodeRed to Grafana with SimpleJSON

Im trying to send the values of a sensor to Grafana via NodeRed with the help of SimpleJSON Plugin.

This is my NodeRed Flow

And my functions are

tmp = [];
tmp.push(parseInt(new Date().getTime()));

flow.set('speed', tmp);
node.status({'text': msg.payload});
return msg;


tmp = [];

for(var id in msg.payload.targets){
    var tmp_target = {};
    tmp_target['target'] = msg.payload.targets[id].target;
    tmp_target['datapoints'] = [flow.get('speed')];
msg.payload = JSON.stringify(out);
return msg;

I followed this guy's video

On Grafana I get this error

Has anyone ever tried this ?

1 Like

What comes out of the 2 debugs? (I.e which http request is being executed? I ask because the top one doesn't appear to return any payload)

debugs dont seem to work. Nothing displaying

Then it's not hitting your endpoint.

In your browser, try accessing the 2 endpoints. You should see something in the debug - that's what anyone calling them would get.

From the "GET" endpoint

when Im trying to accessing POST endpoint it doesnt show anything.
Im really confused.

You'll need something like "postman" to test it.

But as you can see, your endpoint works so the other application isn't hitting that GET endpoint.

Go through the tutorial again incase you missed something perhaps?

Made a GET request with speed. I got the payload

when im tryin to post it says that out is not defined even though it is <- FIXED THAT MY MISTAKE

The payload of the "posted" message payload is empty

Also I cannot understand why Grafana gives me Bad Request

anyone ??

Use debug nodes to see what goes in to & out of the function before the POSTs http out node - that will tell you why payload is empty.

But as you can see - end points do work (since you see debug messages)

As for why grafana isnt hitting your end points - you'll likely have to ask on stackexchange or a grafana forum i suspect.

The error says your second function is failing. You define an array tmo, but push to nonexistent out. Hence the out is not defined error. Either rename tmp or use tmp.

1 Like

I fixed this, I used out= as array

Assuming you are using Grafana v6.4+, you probably want to use this rather than the simpleJson addon:

how this works? I mean what modification should I do to the message.

Don't know, I've not yet had a chance to play.

I saw the manual is kind the same as the SimpleJSON. The thing is that the Grafana cannot connect to the simplejson

Grafana can connect, just tested it, however the documentation states:

Your backend needs to implement 4 urls:

  • / should return 200 ok. Used for "Test connection" on the datasource config page.
  • /search used by the find metric options on the query tab in panels.
  • /query should return metrics based on input.
  • /annotations should return annotations.
  • /tag-keys should return tag keys for ad hoc filters.
  • /tag-values should return tag values for ad hoc filters.

In order to make this work, your http-response node requires a header to be set to json.
Open a new tab in your browser and open the url, what do you see ?

How do I set headers on nodes

doubleclick the http-response node, click the "add" button at the bottom.

and make sure the url actually produces json out by opening a new tab and open the url.

Yeah I did that sorry. It cannot connect to grafana bad gateway.

As stated before: what do you see when you open the url in a new tab