# Creation of Function Node

**URL:** <https://discourse.nodered.org/t/creation-of-function-node/34170>\
**Category:** General\
**Created:** [13 October 2020 10:24 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170 "2020-10-13T10:24:33Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 10:24 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/1 "2020-10-13T10:24:34Z")

</div>

Writing code for decoder function node for decoding hexadecimal payload of lorawan gps tracker.[LW001-BG.pdf](https://discourse.nodered.org/uploads/short-url/9Ub7RMWrOmQHZFwCyCJm2aDXsRb.pdf) (231.6 KB)

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/4231961fafdf0c203106111331ebf18c29dabf17.png) ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d2f93d56fdfe67d7b34b967cad41db18371d89b.png)

---

<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:** [13 October 2020 10:35 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/2 "2020-10-13T10:35:54Z")

</div>

I don't see a question?

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 10:37 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/3 "2020-10-13T10:37:58Z")

</div>

![14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea15f866ab45f502b368affece8bbbfe7838dbcc.png) This wil explain u better  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/722004a60fbbf1250460a6887129f2f235fc7da6.png)  
Could you decode the buffer array and extract out latitude and longitude coordinates as json objects?

---

<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:** [13 October 2020 10:40 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/4 "2020-10-13T10:40:42Z")

</div>

Not really, I still don't see a question.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 10:45 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/5 "2020-10-13T10:45:20Z")

</div>

[flows (1).json](https://discourse.nodered.org/uploads/short-url/pc7jaN5frC35iEF6tOr9xnCD5gZ.json) (3.7 KB)  
Here is the flows file for ur refrence.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 October 2020 10:48 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/6 "2020-10-13T10:48:01Z")

</div>

What you need to do is to tell us what the input you are receiving looks like, how the data is encoded and what you want to get out.  
Also note that a JSON object is always a string, perhaps you mean you want to get javascript objects out, or perhaps just values.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 11:01 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/7 "2020-10-13T11:01:45Z")

</div>

Yes Colin I have parsed the data in 1st function node using simple JSON.parse and extracted out the data attribute from JSON object{} method then passed it into base64 function inorder to change into buffer array of hexadecimal values.Now I require decoding of the same array (as done in ttn) with help of another function node to get result as json objects having values of latitude and longitude.

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/4231961fafdf0c203106111331ebf18c29dabf17.png)  
 ![14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/ea15f866ab45f502b368affece8bbbfe7838dbcc.png)  
I want something just like shown in image of thingsnetwork

[flows (1).json](https://discourse.nodered.org/uploads/short-url/pc7jaN5frC35iEF6tOr9xnCD5gZ.json) (3.7 KB)

But i need some code also for decoding only parser node will not give result in debug window.please check my flow1 and gps pdf file for better understanding of flow.[LW001-BG.pdf](https://discourse.nodered.org/uploads/short-url/9Ub7RMWrOmQHZFwCyCJm2aDXsRb.pdf) (231.6 KB)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 October 2020 11:22 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/8 "2020-10-13T11:22:27Z")

</div>

Ok, so you have a Buffer containing the data 0x61, 0x67 etc and you want to extract the data from that and put it into a javascript object (not a JSON object, JSON is always a string).  
I believe that to do that you would be best using [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) rather than a function node. Your problem is exactly what the node is designed for.

For the future, if you want to post a flow (which I don't think is necessary in this case) then use the `</>` at the top of the forum text field and paste the flow in.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 11:36 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/9 "2020-10-13T11:36:07Z")

</div>

> **[LoRaWAN ShowDoc](http://doc.mokotechnology.com/index.php?s=%2F2&page_id=182)**

  
This contains more information about the sensor lw001-bg gps sensor

---

<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:** [13 October 2020 12:04 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/10 "2020-10-13T12:04:52Z")

</div>

Acording to the PDF with sample data you could so this...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e0600e9c01230cd1f8dcb10c0170c0c7fb9172b8.png)

which matches this...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c23f2ced2d84b472abdad2c52d109d3f1f02cb3.png)

using buffer parser set as per the info you provided...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cabec6da37f892cd37c392ef533c73922025f5e3.png)

Demo flow...

```auto
[{"id":"99b86a91.cc8f18","type":"inject","z":"b489a0e4.4dd7e","name":"test data AgH5e5xFaIdRRA==","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"data\":\"AgH5e5xFaIdRRA==\"}","payloadType":"json","x":820,"y":100,"wires":[["88fc873f.c086c8"]]},{"id":"2bb51028.cbdab","type":"buffer-parser","z":"b489a0e4.4dd7e","name":"","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatle","name":"lat","offset":2,"length":1,"offsetbit":0,"scale":1,"mask":""},{"type":"floatle","name":"lon","offset":6,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":1110,"y":160,"wires":[["2057e639.f3a49a"]]},{"id":"b4228108.10405","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":100,"wires":[]},{"id":"2057e639.f3a49a","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":160,"wires":[]},{"id":"363f26cc.7e8fda","type":"inject","z":"b489a0e4.4dd7e","name":"click me","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":760,"y":160,"wires":[["2b6a66d1.86484a"]]},{"id":"2b6a66d1.86484a","type":"function","z":"b489a0e4.4dd7e","name":"test data 02 01 F9 7B 9C 45 68 87 51 44","func":"msg.payload = { data: Buffer.from(\"0201F97B9C4568875144\", \"hex\") }\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":200,"wires":[["2bb51028.cbdab","29572a95.8942b6"]]},{"id":"88fc873f.c086c8","type":"base64","z":"b489a0e4.4dd7e","name":"","action":"","property":"payload.data","x":1100,"y":100,"wires":[["b4228108.10405","2bb51028.cbdab"]]},{"id":"29572a95.8942b6","type":"debug","z":"b489a0e4.4dd7e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1290,"y":200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 14:29 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/11 "2020-10-13T14:29:15Z")

</div>

Thanks Steve this works perfect. 😊 😍

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 14:47 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/12 "2020-10-13T14:47:01Z")

</div>

Thanks collin i learnt json is a string not an object. 😊

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 16:22 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/13 "2020-10-13T16:22:33Z")

</div>

hello do u know steve which node can help me plot or track latitude and longitude on a map?  
I tried node red world map but in that u have to manually give coordinates.

---

<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:** [13 October 2020 17:32 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/14 "2020-10-13T17:32:29Z")

</div>

> [@bachloo.rahul](#):
>
> I tried node red world map but in that u have to manually give coordinates

Pretty sure you can pass a message with coordinates into the world map node. Start a new thread for a new problem (with an appropriate title so it attracts the right people)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 October 2020 17:33 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/15 "2020-10-13T17:33:11Z")

</div>

Just look at the info side bar for the world map for the simplest example.

---

<div class="post-metadata">

**Author:** ![bachloo.rahul](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@bachloo.rahul](https://discourse.nodered.org/u/bachloo.rahul)\
**Post date:** [13 October 2020 17:50 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/16 "2020-10-13T17:50:50Z")

</div>

In information tab its wriiten that it requires 3 fields name,lat and long for world map node.

 ![19](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47e32b72b5f8347bb5890c75d7e356d0629a0632.png)  
how can i add this data field also?and also would like to show a red color marker on location.  
 ![17](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/6/a62b2941cee1ffb74d128211c00480a0b43c08b1.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 October 2020 18:19 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/17 "2020-10-13T18:19:21Z")

</div>

Hmmm I wonder which node could be used to “change” properties on a message ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 October 2020 18:19 UTC](https://discourse.nodered.org/t/creation-of-function-node/34170/18 "2020-10-27T18:19:22Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
