New to Node-Red(NR) and maybe start with a simple application You can benefit direct from ?
This application is measuring Your Internet connection at chosen intervals using Speedtest.net and showing the result in a graph. If the speed is under a set value it will send You an email.
New ! better version !
Check this post for testing your local networks speed ?
If You haven't installed NR yet here is some short notes how to.
Flow setup
The picture shows all the logic that is needed.
Download the flow ISP_speedtest_NR.json from Github, click on "Clone or Download => Download ZIP" or just click on ISP_speedtest_NR.json, then "raw" and copy the code.
In NR, open according to the picture, "Menu => Import => Clipboard" and paste the code.
To make the flow work You have to install nodes node-red-dashboard and node-red-contrib-speedtest.
So open "Menu => Manage palette => Palette => Install" and paste the nodename and in the list click on "Install"
Click on Deploy in the upper right corner. This have to be done after any change in the code You do.
If You don't see any sidebar, check box in "Menu => View => Show sidebar". In the sidebar You can get additional information.
Now the flow is up and running and every 5 minutes the speed test is checking You Internet speed.
If You want to force the speed test just click once on the grey area, to the left of the arrow, on the timestamp node and You will se a text "Requesting" just below the speedtest node.
Click on "Debug" in sidebar area and the debug info is shown.
Probably You will see a "Error Mail command....", so double click on the Mail node and set it up.
Click on "Dashbord" in the sidebar area and then another click on the arrow to the right of "Site" which will take You to the GUI Dashboard corresponding to the picture first in this post.
Flow explanation
Every NR flow must have a trigger/inject that starts the flow. In this case the inject node, named "timestamp" do the job. Double click on the node and You will see that every 5 minutes it sends a timestamp to the speedtest node.
This triggers the measurement and when it's ready it emits a message to next node. If You activate the debug node, connected to the speedtest output, clicking on the right side, the message will appear in the sidebar, debug message.
The next node, a function node which always contains Java Script(JS) code, named "Get speed Down/Up", picks up the down and upload measures from the input message. It is then divided to 2 outputs, since we want to show both values in the same graph.
The next node, "Broadband Speed" which is a chart node, handles the output to a graph.
The function node, named "If speed below X Mbps => send mail" prepares the message for the mail node. If the speed is below x the message will be built, otherwise nothing is sent from the node.
In the "Mail" node properties is set for sending the mail.
I like the function nodes because they can do a lot of job in the same node, but on the other hand You have to learn JS. It is also so that they are a heavier CPU load than a "standard" node.
Shown in the picture I have done the same flow without the function nodes
As seen it will be some more nodes but maybe it is more simple ?
In the "Mail information" node the msg.payload is set with a JSONata expression.
The syntax is
"Warning ! The download speed have been below 10 Mbps. Now "& $string(msg.payload) & " Mbps"
Remark
The node-red-contrib-speedtest measure don't always seems to report correct values so did a variant with the script from this post.
Fetch the script and move it to the right folder
wget https://git.io/speedtest.sh
sudo mv speedtest.sh /usr/local/sbin
and execute the command in a NR exec node, command => bash /usr/local/sbin/speedtest.sh
Download the flow ISP_speedtest_NR_3.json from Github, and import it to NR
Flow setup
The picture shows all the logic that is needed.
Download the flow ISP_speedtest_NR.json from Github, click on "Clone or Download => Download ZIP" or just click on ISP_speedtest_NR.json, then "raw" and copy the code.
In NR, open according to the picture, "Menu => Import => Clipboard" and paste the code.
To make the flow work You have to install nodes node-red-dashboard and node-red-contrib-speedtest.
So open "Menu => Manage palette => Palette => Install" and paste the nodename and in the list click on "Install"
Click on Deploy in the upper right corner. This have to be done after any change in the code You do.
If You don't see any sidebar, check box in "Menu => View => Show sidebar". In the sidebar You can get additional information.
Now the flow is up and running and every 5 minutes the speed test is checking You Internet speed.
If You want to force the speed test just click once on the grey area, to the left of the arrow, on the timestamp node and You will se a text "Requesting" just below the speedtest node.
Click on "Debug" in sidebar area and the debug info is shown.
Probably You will see a "Error Mail command....", so double click on the Mail node and set it up.
Click on "Dashbord" in the sidebar area and then another click on the arrow to the right of "Site" which will take You to the GUI Dashboard corresponding to the picture first in this post.
Flow explanation
Every NR flow must have a trigger/inject that starts the flow. In this case the inject node, named "timestamp" do the job. Double click on the node and You will see that every 5 minutes it sends a timestamp to the speedtest node.
This triggers the measurement and when it's ready it emits a message to next node. If You activate the debug node, connected to the speedtest output, clicking on the right side, the message will appear in the sidebar, debug message.
The next node, a function node which always contains Java Script(JS) code, named "Get speed Down/Up", picks up the down and upload measures from the input message. It is then divided to 2 outputs, since we want to show both values in the same graph.
The next node, "Broadband Speed" which is a chart node, handles the output to a graph.
The function node, named "If speed below X Mbps => send mail" prepares the message for the mail node. If the speed is below x the message will be built, otherwise nothing is sent from the node.
In the "Mail" node properties is set for sending the mail.
I like the function nodes because they can do a lot of job in the same node, but on the other hand You have to learn JS. It is also so that they are a heavier CPU load than a "standard" node.
Shown in the picture I have done the same flow without the function nodes
As seen it will be some more nodes but maybe it is more simple ?
In the "Mail information" node the msg.payload is set with a JSONata expression.
The syntax is
"Warning ! The download speed have been below 10 Mbps. Now "& $string(msg.payload) & " Mbps"
Remark
The node-red-contrib-speedtest measure don't always seems to report correct values so did a variant with the script from this post.
Fetch the script and move it to the right folder
wget https://git.io/speedtest.sh
sudo mv speedtest.sh /usr/local/sbin
and execute the command in a NR exec node, command => bash /usr/local/sbin/speedtest.sh
Download the flow ISP_speedtest_NR_3.json from Github, and import it to NR
Id like to get this running but Speedtest allways throws out "check your proxy". I can guess, that this information only gets to to people like me with hardly any knowledge about where to open wich port for what and where again... or do I have to kind of shake hands somewhere before my node speedtest can get kicked off.. so maybe at point "This triggers the measurement and when it's ready..." you could add some setting-advices from zero...
ReplyDeleteIt should work out of the box, but please instead check out the "New ! better version !" linked in the beginning of this post.
Delete