Publishing a Sine Wave

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?

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?

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

Here is some more info.

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

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

[{"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

1 Like

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

You can read here how to import and export flows. You can import the provided code into your own node-red instance.

Try also reading the pinned post about formatting code when posting on this forum.

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 . 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.

Ahh thanks very much mate. appreciate it!!

My LFO node does exactly this:

1 Like