Monday, March 18, 2019

More Node-Red


Node-Red is amazingly powerful, and flexible. Maybe in a future post, I set some recipies, including recurring timers, Google Assistant integration and notifications.



Dedicated System Setup


One advantage of using Node-Red in your home is you don't have to worry about security too much. You aren't publishing your daily habits to anyone in the cloud. One disadvantage, you need to give the system all it's smarts. It doesn't mean you can't integrate with the cloud, but it doesn't happen automatically.

Using a RaspberryPI as the dedicated controller will allow the 'PI to be the WiFi hub, DHCP server, MQTT server agent, and provide all the flows without worrying about tying up another machine (home office computer), or having that system walk out the door (laptop).

In my example ESP8266 nodes, I always hard coded the IP address of the server. That works great, since the RaspberryPI is providing all the DHCP and WiFi for the various nodes in the house. If I want to move the system somewhere else, I don't have to worry about reprogramming the nodes server IP address.



The above diagram shows how the home WiFi is separate from the IoT WiFi. To connect to the rest of the internet, a wired connection can be made to the home Cable Mode. Connecting the RaspberryPI to the internet will allow updates and other features to be easier. It doesn't have to be connected to the internet, it is up to you. Since the RaspberryPi connected to the modem will NAT all internet traffic, unless routes are set up in the modem, the RaspberryPI is not visible from the outside network.

For my network, I run the IoT network on WiFi Channel 11 since my home network is on channel 1. Keeping them on separate channels should prevent IoT traffic from being picked up on the home WiFi devices theoretically making things faster. Radio is radio, so if the devices are close enough, they may interfere anyway. (For some reason the Sony PS4 seems to interfere with WiFi devices near it, so if the kids bring the PS4 into the sun room, the IoT devices perform poorly).

My WiFi config file on the RaspberryPI looks like:

pi@raspberrypi:~ $ cat /etc/hostapd/hostapd.conf
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
beacon_int=100
auth_algs=1
wpa_key_mgmt=WPA-PSK
ssid=raspi-webgui
channel=11
wpa=2
hw_mode=g
wpa_passphrase=XXXXXXXX
interface=wlan0
#wpa_pairwise=TKIP
rsn_pairwise=CCMP
country_code=US


The dns config file is the default, really no changes. 

Node-Red Dashboard

This will be a gentle introduction, just barely covering what it is capable of. This is really the big win for Node-Red. 

First there you need to install the dashboard nodes. From the Node-Red main window, hamburger menu on the far right. Left click on that to bring up the configuration menu. Select the "Manage Palette". A dialog with two tabs will appear, select the "Install" tab. Type in "dashboard" in the "Filter nodes box" There will be a list of dashboard items available. For now, we only want the default "node-red-dashboard". Select "install" and give it a couple minutes. After the update completes, scroll toward the bottom of the nodes on the left. 

There will be a section of nodes labled "dashboard" with nodes like "button", "slider", "dropdown", etc. These items can be added to a flow, and used to set settings or view values available in the flow. The updated garage flow with simple outputs for the garage state and temperature graph looks like:

The light blue nodes are dashboard nodes. The garage door ones are the current state as text (open/closed) and the temperature is a graph showing the current trend, with degrees in Fahrenheit. To set the node display, use the payload to get the value:


Create a group, as you wish. For my house these nodes are in the Garage, so I created a Garage group. I also have a Sunroom Group and a Basement group. They are all part of the House, as a hidden group. The payload is enclosed in "{{" and "}}" I'll expand on why that later. Alignment can be changed as desired, the top row above is left, center and right aligned. The next is fill, and the bottom right is label over value. The look that this allows is:


The temperature trend for the last 20 minutes or so is shown, getting colder. Both doors are closed. Pretty simple, but a quick look and you can see it. Note the URL. I chose the home network, since my RaspberryPI is plugged into the home network. Node Red is running on port 1880, the default. But after that there is a /ui, so I don't see the whole Node Red flow builder, but just the dashboard. 

How about if you want to see this on your phone? No problem, that is built in:

Enter the same url (like 192.168.0.35:1880/ui in chrome, safari or whatever browser you prefer. All the dashboard features are there. No special apps, or knowledge of programming needed. 

There is so much more that can be done in Node-Red. Start playing, and you should find ideas that I never thought of. More next time. 


No comments:

Post a Comment