# Sending Values from NodeRed to Grafana with SimpleJSON

**URL:** <https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675>\
**Category:** General\
**Created:** [14 May 2020 22:48 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675 "2020-05-14T22:48:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [14 May 2020 22:48 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/1 "2020-05-14T22:48:11Z")

</div>

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

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/ee5f14e69240438486b7a6c7a441ceafcdc77efd.png)  
This is my NodeRed Flow

And my functions are  
1st:

```auto
tmp = [];
tmp.push(parseFloat(msg.payload));
tmp.push(parseInt(new Date().getTime()));

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

```

2nd:

```auto
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')];
    
    out.push(tmp_target);
}
msg.payload = JSON.stringify(out);
return msg;

```

I followed this guy's video  
[Video](https://www.youtube.com/watch?v=9nZtiwD8wGc)

On Grafana I get this error

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e3dececbf7bba45f9a0dcdb9c0e97e0bad2c229.jpeg)

Has anyone ever tried this ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2020 23:09 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/2 "2020-05-14T23:09:54Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [14 May 2020 23:12 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/3 "2020-05-14T23:12:03Z")

</div>

debugs dont seem to work. Nothing displaying

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2020 23:13 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/4 "2020-05-14T23:13:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [14 May 2020 23:19 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/5 "2020-05-14T23:19:50Z")

</div>

![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/a/3aec97ed632e09434a22c08853e00024f227e157.png)  
From the "GET" endpoint

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2020 23:22 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/6 "2020-05-14T23:22:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [14 May 2020 23:33 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/7 "2020-05-14T23:33:55Z")

</div>

![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/73dfa73b49e3c9a5f0a2517c3bed72f786e38b9a.png)  
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

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 10:06 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/8 "2020-05-15T10:06:34Z")

</div>

anyone ??

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 May 2020 10:17 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/9 "2020-05-15T10:17:08Z")

</div>

> [@mtp211](#):
>
> The payload of the "posted" message payload is empty

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.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [15 May 2020 12:40 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/10 "2020-05-15T12:40:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 13:32 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/11 "2020-05-15T13:32:40Z")

</div>

I fixed this, I used out= as array

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 May 2020 15:04 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/12 "2020-05-15T15:04:08Z")

</div>

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

> **[JSON plugin for Grafana](https://grafana.com/grafana/plugins/simpod-json-datasource)**
>
> JSON over HTTP datasource

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 15:07 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/13 "2020-05-15T15:07:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 May 2020 15:32 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/14 "2020-05-15T15:32:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 16:04 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/15 "2020-05-15T16:04:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 May 2020 16:49 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/16 "2020-05-15T16:49:28Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 17:55 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/17 "2020-05-15T17:55:02Z")

</div>

How do I set headers on nodes

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 May 2020 18:16 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/18 "2020-05-15T18:16:12Z")

</div>

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

 ![Screenshot 2020-05-15 at 20.17.06](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/03bf2406e196fc964cc48ca9d5476013eb73868c.jpeg)

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

---

<div class="post-metadata">

**Author:** ![mtp211](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mtp211](https://discourse.nodered.org/u/mtp211)\
**Post date:** [15 May 2020 18:33 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/19 "2020-05-15T18:33:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 May 2020 18:43 UTC](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675/20 "2020-05-15T18:43:35Z")

</div>

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

[Next page](https://discourse.nodered.org/t/sending-values-from-nodered-to-grafana-with-simplejson/26675.md?page=2)
