Node-red changing title bar icon

Node-red dashboard plugin provides a quick setup for a user interface. But sometimes, you may want to change the template to suit your own application. The following post will provide a simple method for editing the title bar icon and tags when loading into the dashboard.

The Node-red icon (white background) in the dashboard is stored in

Windows
C:\Users\Developer\.node-red\node_modules\node-red-dashboard\dist

Raspberry Pi
/home/pi/.node-red/node_modules/node-red-dashboard/dist

If the above directory does not exist, you may try the below directory.

Raspberry Pi
/home/pi/.node-red/node_modules/dashboard-evi/dist

the logo shown in title bar is icon64x64, while the dashboard loading page logo is icon120x120. Chrome will cache the title bar icon, so you may want to delete the history and refresh the page to see the update.

All the configuration is stored in:

/home/pi/.node-red/node_modules/node-red-dashboard/dist/index.html

It is better to change the configuration before opening the dashboard website to prevent using the old logo stored in cache. Otherwise, search for the cache or backup flow to check whether it is updated or not.

grep -ril '/home/pi/.node-red' -e "your old content in string"

Reminder

You may also change the index.html file to point to another file other than icon120x120.png.

<link rel="apple-touch-icon" href="icon120x120.png">

Changing tags works as well.

<h2>Welcome to the Node-RED Dashboard</h2>

Updating Node-red may reset the icon to factory settings, so you could also write a script to copy the icon for every start-up. To learn more about running scripts on startups, you may visit this link.

Nodered saving context data in local filesystem

The official tutorial is https://nodered.org/docs/user-guide/context#using-multiple-context-stores.

cd ~/.node-red/
sudo nano settings.js

Add the following code

...
...
...
    editorTheme: {
        menu: { "menu-item-help": {
            label: "Node-RED Pi Website",
            url: "http://nodered.org/docs/hardware/raspberrypi.html"
        } },
        projects: {
            // To enable the Projects feature, set this value to true
            enabled: false,
            workflow: {
                // Set the default projects workflow mode.
                //  - manual - you must manually commit changes
                //  - auto - changes are automatically committed
                // This can be overridden per-user from the 'Git config'
                // section of 'User Settings' within the editor
                mode: "manual"
            }
        }
    }, //Remember to add ',' 
    contextStorage: {
        default: "memoryOnly",
        memoryOnly: { module: 'memory' },
        file: { module: 'localfilesystem' }
    }
}

Variables saved in memory and localfilesystem are in fact different variables, they can have the same name. So when you save or get the variables, remember to specify which one you are pointing at.

This will store the variable storedInMemory in RAM.

flow.set("storedInMemory", true)
or
flow.set("storedInMemory", true, "default")
or
flow.set("storedInMemory", true, "memoryOnly")

And this will store the variable in localfilesystem. The context data will be stored under ~/.node-red/context/ by default.

flow.set("storedInMemory", false, "file")

Similar method to get the variables stored in localfilesystem

flow.get("storedInMemory", "file")

Raspberry Pi setting fixed ip on Raspbian (Raspberry Pi OS)

Setting wifi and ethernet fixed IP address. Wifi as main internet connection and ethernet cable for stand-alone device.

sudo nano /etc/dhcpcd.conf

Add the following code.


interface wlan0
static ip_address=192.168.1.11/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8

interface eth0
static ip_address=192.168.2.10

Creating startup program on Raspberry Pi by rc.local

rc.local execute once after normal system service (including networking) single-user mode and before multi-user runlevel (GUI and login).

As rc.local runs before X starts, so please do not includes settings with graphical interface. For more information about runlevel, and rc.local, you may visit https://learn.sparkfun.com/tutorials/how-to-run-a-raspberry-pi-program-on-startup/method-1-rclocal

sudo nano /etc/rc.local

Put your script before exit 0. Here is an example of replacing in file text and copying files. The ampersand & at the end of the lines indicates the rc.local script does not wait for that script ends before executing the next line, which is important when you have an infinite loop such as blinky.

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi


sudo sed -i 's/Old string to be replaced/new string to be replaced/g' /home/pi/textfile.txt &

sudo cp -r /home/pi/somephoto/* /home/pi/destinationdir/ &


exit 0

sed is a streamlined editor and could edit the file without opening a text editor. the option -i edit the textfile.txt itself, or else, changes will print to the console only. The s/ stand for substitute and /g for global replacement. Man sed for more information.

Reminders

Someone suggested setting up the script in bash.rc, which runs every time an interactive shell is prompted such as logging in to the shell. Usually Raspberry pi will enable auto login so most of the case bash.rc runs after boot up.

USB Wifi dongle for raspberry pi zero w

USB wifi adapters are not very user-friendly for Linux devices. Most of the adapters’ drivers are neither preinstalled nor will be automatically installed for your Linux OS. Fortunately, modern Raspberry Pi (such as Pi 3, 4, and zero w) models come with onboard wifi. Yet you may also find it handy to have additional wifi systems for some projects.

Environment

Hardware: Raspberry Pi Zero W, USB wifi dongle Realtek 8812CU and RTL8188FTV

Kernel: 5.10.17+

OS: Raspbian GNU/Linux 10 (buster)

Finding drivers/ firmwares for your USB dongle

I previously bought a wifi dongle running on the chip Realtek 8821CU and wanted to build a wifi repeater for my raspberry pi zero w. However, there is no easy install package for raspberry pi zero. I have tried several installers following the steps on Github.

(https://github.com/brektrou/rtl8821CU),

(https://github.com/uzh-rpg/rpg_dwa171_wifidongle),

(https://github.com/whitebatman2/rtl8821CU) and

(https://github.com/morrownr/8821cu). None of them works and I suspect that the drivers do not support armv6 CPU which the Pi zero is using. If you are planning to install it on an armv7 device, please give them a try.

Then I decided to give up and bought another dongle running on an RTL 8188 FTV chip and it works after installing the firmware.

Configure your wifi adaptor

Most of the following content is extracted from (https://www.raspberrypi.org/forums/viewtopic.php?t=44044). To sum up,


Connect your wifi USB adaptor and check your current network status by ifconfig -a

pi@raspberrypi:~ $ ifconfig -a
 lo: flags=73  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 wlan0: flags=4163  mtu 1500
         inet 192.168.0.187  netmask 255.255.255.0  broadcast 192.168.0.255
         inet6 1234::1234:1234:1234:1234  prefixlen 64  scopeid 0x20

         ether 12:34:56:12:34:56  txqueuelen 1000  (Ethernet)
         RX packets 566  bytes 76882 (75.0 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 363  bytes 56329 (55.0 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

If there are multiple wlan such as wlan0 as well as wlan1. Congratulations!! your Pi could recognize your USB adaptor. Usually, wlan0 is your onboard wifi (if your device has one) and the other wlan are your additional wifi systems. If your device does not include onboard wifi, then wlan0 is your external wifi USB dongle.


If wlan1 does not show on ifconfig -a, like me, then run a lsusb.

pi@raspberrypi:~ $ lsusb                                                        Bus 001 Device 002: ID 0bda:f179 Realtek Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Device 002 f179 Realtek Semiconductor Corp is the wifi dongle. So at least the wifi dongle is working. Otherwise, there will be nothing about it.


Then run a lsmod to check whether your kernel modules are currently loaded.

pi@raspberrypi:~ $ lsmod
 Module                  Size  Used by
 aes_arm                16384  1
 aes_generic            40960  1 aes_arm
 cmac                   16384  1
 bnep                   20480  2
 hci_uart               40960  1
.
.
.

For me, there is nothing about my USB adaptor. So it could be concluded that the driver is not installed on my Raspberry Pi Zero W.

The firmware-packages for the more common devices are as follows:
firmware-ralink for Ralink devices (RT5370/RT3070/etc.)
firmware-realtek for Realtek devices (RTL8188CUS/etc.)
firmware-atheros for Atheros devices.

Run apt-get install <firmware-package> to install the firmware on Raspbian (renamed to Raspberry Pi OS).

Unfortunately, my Realtek 8812CU and RTL8818FTV drivers are not included in the firmware package. So I have to go for other options. Luckily, MrEngman (https://www.raspberrypi.org/forums/viewtopic.php?t=241185) wrote a script to determine your USB dongle and kernel version and install your suitable driver. Run the following commands:

$ sudo wget http://downloads.fars-robotics.net/wifi-drivers/install-wifi -O /usr/bin/install-wifi
$ sudo chmod +x /usr/bin/install-wifi
$ sudo install-wifi

I have tried my RTL8188FTV and Realteck 8821CU. The 8188 works, but not the 8821. MrEngman’s script cannot recognize my 8821.

Your wifi module is unrecognised.
**** Unable to identify your wifi module ****

If anyone knows how to install the Realtek 8821CU driver on a raspberry pi zero, please leave a comment.

If MrEngMan’s script could recognize your wifi dongle, it should return something like my 8188:

Your wifi module is Bus 001 Device 003: ID 0bda:f179 Realtek Semiconductor Corp.
And it uses the 8188fu driver.

If your driver has been installed correctly, you should now see your firmware’s kernel module listed on lsmod

pi@raspberrypi:~ $ lsmod
 Module                  Size  Used by
 rtl8188fu            1306624  0
 aes_arm                16384  1
 aes_generic            40960  1 aes_arm
 cmac                   16384  1
 bnep                   20480  2
 hci_uart               40960  1
.
.
.

As well as anadditionl wlan1 on ifconfig -a

pi@raspberrypi:~ $ ifconfig -a
 lo: flags=73  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 wlan0: flags=4163  mtu 1500
         inet 192.168.0.187  netmask 255.255.255.0  broadcast 192.168.0.255
         inet6 1234::1234:1234:1234:1234  prefixlen 64  scopeid 0x20

         ether 12:34:56:12:34:56  txqueuelen 1000  (Ethernet)
         RX packets 2026  bytes 875332 (854.8 KiB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 886  bytes 117991 (115.2 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 wlan1: flags=4163  mtu 1500
         inet 192.168.0.179  netmask 255.255.255.0  broadcast 192.168.0.255
         inet6 1234::1234:1234:1234:1234  prefixlen 64  scopeid 0x20

         ether 12:34:56:12:34:56  txqueuelen 1000  (Ethernet)
         RX packets 158  bytes 44279 (43.2 KiB)
         RX errors 0  dropped 5  overruns 0  frame 0
         TX packets 36  bytes 5029 (4.9 KiB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

As well as iw dev:

pi@raspberrypi:~ $ iw dev
 phy#1
         Interface wlan1
                 ifindex 3
                 wdev 0x100000001
                 addr 12:34:56:12:34:56
                 ssid yourwifissid
                 type managed
                 txpower 12.00 dBm
 phy#0
         Unnamed/non-netdev interface
                 wdev 0x2
                 addr 12:34:56:12:34:56
                 type P2P-device
                 txpower 31.00 dBm
         Interface wlan0
                 ifindex 2
                 wdev 0x1
                 addr 12:34:56:12:34:56
                 ssid yourwifissid
                 type managed
                 channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
                 txpower 31.00 dBm

Reminder

I do not recommend editing /etc/network/interfaces. There is no need to edit the file for a Raspberry Pi Zero running Raspberry Pi OS lite. Rather, do your modification on /etc/wpa_supplicant/wpa_supplicant.conf. If you have installed the driver correctly, the network will automatically pop up in ifconfig -a.