# Publishing a Sine Wave

**URL:** <https://discourse.nodered.org/t/publishing-a-sine-wave/52060>\
**Category:** Dashboard\
**Created:** [10 October 2021 11:53 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060 "2021-10-10T11:53:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![casual](https://avatars.discourse-cdn.com/v4/letter/c/dfb087/32.png) [@casual](https://discourse.nodered.org/u/casual)\
**Post date:** [10 October 2021 11:53 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/1 "2021-10-10T11:53:42Z")

</div>

Hey Guys,  
I've been searching for days, the Curve Node is no longer able to be used with the latest version and I've been trying to find a script for the function node to develop a Cosine Wave to publish with the chart node. Can anybody help me?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [10 October 2021 12:43 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/2 "2021-10-10T12:43:13Z")

</div>

Welcome to the forum.

Perhaps I am misunderstanding your question, but have you tried putting the sine or cosine function in a Function node, like this?

```auto
msg.payload = Math.cos(msg.payload);
return msg;

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53eb3a9a38cffe073f2b817932c5aa71f93532b6.png)

[Here is some more info](https://www.techonthenet.com/js/math_cos.php).

EDIT: Here is the same flow (with some different input values) with the Chart dashboard node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/896032f3d2f2816d5b432db85642a67e9efc7965.png)

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

---

<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:** [10 October 2021 13:54 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/3 "2021-10-10T13:54:19Z")

</div>

Or if you mean a wave moving with time then something like

```auto
[{"id":"166bfec95e80808a","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":180,"y":2320,"wires":[["050131afc8e18f30"]]},{"id":"050131afc8e18f30","type":"function","z":"bdd7be38.d3b55","name":"Cos(t)","func":"let now = new Date().getTime()/1000 // seconds\nmsg.payload = Math.cos(now/5)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":2320,"wires":[["548269bb7bd58242"]]},{"id":"548269bb7bd58242","type":"ui_chart","z":"bdd7be38.d3b55","name":"","group":"903a6ab8.4f4ca8","order":1,"width":0,"height":0,"label":"Cosine","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":500,"y":2320,"wires":[[]]},{"id":"708b63063ecbbad1","type":"inject","z":"bdd7be38.d3b55","name":"Clear chart","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[]","payloadType":"json","x":310,"y":2400,"wires":[["548269bb7bd58242"]]},{"id":"903a6ab8.4f4ca8","type":"ui_group","name":"Home","tab":"e2e6f4f5.56f91","order":1,"disp":false,"width":"6","collapse":false},{"id":"e2e6f4f5.56f91","type":"ui_tab","name":"Homet","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

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

---

<div class="post-metadata">

**Author:** ![Antho1](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Antho1](https://discourse.nodered.org/u/Antho1)\
**Post date:** [11 October 2021 10:59 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/4 "2021-10-11T10:59:39Z")

</div>

thank you for this.

Im new to this and wondering where you type that code for cosine and can you change it to sine?  
do you just paste it under like this

msg.payload = Math.cos(msg.payload);  
return msg;  
[{"id":"166bfec95e80808a","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":180,"y":2320,"wires":[["050131afc8e18f30"]]},{"id":"050131afc8e18f30","type":"function","z":"bdd7be38.d3b55","name":"Cos(t)","func":"let now = new Date().getTime()/1000 // seconds\nmsg.payload = Math.cos(now/5)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":,"x":330,"y":2320,"wires":[["548269bb7bd58242"]]},{"id":"548269bb7bd58242","type":"ui\_chart","z":"bdd7be38.d3b55","name":"","group":"903a6ab8.4f4ca8","order":1,"width":0,"height":0,"label":"Cosine","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"60","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":500,"y":2320,"wires":[]},{"id":"708b63063ecbbad1","type":"inject","z":"bdd7be38.d3b55","name":"Clear chart","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"json","x":310,"y":2400,"wires":[["548269bb7bd58242"]]},{"id":"903a6ab8.4f4ca8","type":"ui\_group","name":"Home","tab":"e2e6f4f5.56f91","order":1,"disp":false,"width":"6","collapse":false},{"id":"e2e6f4f5.56f91","type":"ui\_tab","name":"Homet","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

kind regards

---

<div class="post-metadata">

**Author:** ![Hopperpop](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hopperpop/32/42533_2.png) [@Hopperpop](https://discourse.nodered.org/u/Hopperpop)\
**Post date:** [11 October 2021 11:17 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/5 "2021-10-11T11:17:37Z")

</div>

You can read [here](https://nodered.org/docs/user-guide/editor/workspace/import-export) how to import and export flows. You can import the provided code into your own node-red instance.

Try also reading the [pinned post](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506/8) about formatting code when posting on this forum.

---

<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:** [11 October 2021 11:22 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/6 "2021-10-11T11:22:43Z")

</div>

Welcome to the forum @Antho1

You can import the flow I posted and see it working so that you can then change it how you like. I presume you did not know that so I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Antho1](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Antho1](https://discourse.nodered.org/u/Antho1)\
**Post date:** [12 October 2021 13:51 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/7 "2021-10-12T13:51:31Z")

</div>

Ahh thanks very much mate. appreciate it!!

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [12 October 2021 18:44 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/8 "2021-10-12T18:44:50Z")

</div>

My LFO node does exactly this:

> **[node-red-contrib-lfo](https://flows.nodered.org/node/node-red-contrib-lfo)**
>
> Low frequency oscillators for Node-RED

---

<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:** [11 November 2021 18:45 UTC](https://discourse.nodered.org/t/publishing-a-sine-wave/52060/9 "2021-11-11T18:45:43Z")

</div>

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