Well maybe "debug" is slightly over selling it!
This example will dump any msg you send to the uibuilder node out to the front-end web page and will nicely format it.
You will get an entry on the page for every topic that you send.
/** Standardised data schema's for IoT Home Automation | |
*/ | |
const schemas = { | |
/** network table | |
* A table of network devices (logical and physical) | |
* This schema uses a structure suitable for use with VueJS/bootstrap-vue `b-table` options. | |
* The table is an object of objects with the ID as the primary key | |
* It is periodically updated by an NMAP scan. |
Well maybe "debug" is slightly over selling it!
This example will dump any msg you send to the uibuilder node out to the front-end web page and will nicely format it.
You will get an entry on the page for every topic that you send.
OK, so I've been a bit slow in getting my head around JSONata. I knew it was going to be valuable but I've just had my first actual use case.
I needed to rebuild an output payload from several parts of the input so I could monitor inputs from an RFXtrx433E. I wired up all the input nodes from Max's RFX node, added a timestamp using my moment node then added a change node with 2 changes.
The first change alters the msg.topic - I wanted to add RFX/ to the beginning to push the MQTT output messages to a new, dedicated path. Here is the JSONata for that:
"RFX/" & topic
Your network IP address is the default address that other systems on your network will see as the "server" running Node-RED.
In many environments though, this address is remarkably hard to get hold of reliably. Particularly when you have multiple NIC's. Worse, many of the methods are totally different on different operating systems.
There is one fairly reliable method however, though it does require a connection to the Internet.
To make use of this, you first need to add a global function in settings.js
functionGlobalContext: {
Windows from certainly at least version 7+ and the equivalent server versions have an excellent built-in Speech engine that does both text-to-speech and speech recognition.
The speech engine is written as a system library and so is easily called from PowerShell.
This flow makes use of that feature and uses the exec node to shell out to PowerShell, calling the speech engine using a one-line PowerShell script.
You send the text into the exec node and it passes it through.
See the comment node for some details. This is exactly the way that the popular say.js library works.
This example flow will let you monitor the Operating System process details for your Node-RED instance.
To make this work, you need to know the PID (Process Identifier) of your Node-RED instance. The easiest way to do that is to grab it on startup and add it to the global variables from settings.js. Add the following to your settings.js file & restart NR:
...
functionGlobalContext: {
'pid': process.pid
},
...
This example flow uses the native Node.JS fs and path modules to read a list of file names having a specified file extension from a given folder.
You can pass the folder and extension strings in via the msg.payload. Output is a single message for each file found. The payload will be the full file path. Everything other than the payload will be passed through to each output msg.
You would actually probably be better off using a 3rd party module as indicated in the main code but this may be a useful example of using modules in a Node-Red function node.
Note that function nodes run in a "sandbox" and have restricted syntax. As such, you cannot do:
var fs = require('fs');
As Dashboard includes JQuery as well as Angular, you can use the extensive collection of JQuery examples and tutorials with it.
Here is a simple CSS driven analogue clock that you could easily adapt. It is based on a example on the web Old School Clock with CSS3 and jQuery. You will need to download the image files that are part of the archive that page links to.
Make sure you have httpStatic
set in your settings.js
file and put the CSS3Clock
folder from the downloaded archive into your static folder. Then import the flow below, deploy and enjoy.
Quite often, web REST API's return JSON data but are limited to the number of records they return.
Good API's also return the total number of records that could be returned along with the current offset (from start), the record limit and perhaps even a URL that lets you make the next call in the series.
Mailroute is a cloud service that pre-checks email for you, filtering out spam and viruses and letting you white-/black-list sending domains and email addresses.
It has a pretty good API that returns 20 records at a time. So, if you want to return a large number (all) of the white-/black-list entries, you need a flow that will loop through each recordset.
The attached flow does just that. It also makes use of links to keep the looping flow neat. Also uses JSONata in Change nodes instead of function nodes so reducing the level of JavaScript coding knowledge required.
Those who know me from the Google group and Slack will know that I have a bit of a "thing" about security. It isn't easy to secure a web service at the best of times and trying to do so via your home network with minimal resources is even harder.
So why not avoid the issue altogether! By instead using a bot with a secure messaging service, you don't need to expose Node-RED or a web server, mess with certificates, authentication and authorisation. Nor worry about how to secure websockets.
The flow listed here demonstrates a simple Telegram bot that shows the current status of a set of wireless switches (in my case that control lights) and that let you turn them on and off via a simple text interaction.
If you want the full details, including pictures and some info on wiring up MQTT and the other dependencies, you can find them on the Totally Information development blog.