Hello all. Node-red gets the temperature values of the boiler via the serial port.
While I was working with the telegram node, I deployed the last changes and everything got froze. The cpu of the raspberry run to 100% locking the device. I stopped the service and restarted and the editor was totally empty!!
Following the start command, it seems the flow is working properly collecting the data.
25 Nov 00:44:49 - [error] [change:3f904e0a.086b82] Invalid 'to' JSON property
25 Nov 00:44:49 - [info] Started flows
25 Nov 00:44:50 - [info] serial port /dev/ttyAMA0 opened at 9600 baud 8N1
25 Nov 00:44:56 - [info] [debug:15b40e4d.900a12]
25 Nov 00:45:00 - [info] [debug:502a025a.73c9dc] 6
25 Nov 00:45:00 - [info] [debug:4689fdbf.93dd94] 36
25 Nov 00:45:00 - [info] [debug:a7cfb47c.bacf88] 0;0;0;0;6;33;36;14;0,0;;0
25 Nov 00:45:00 - [info] [debug:a7cfb47c.bacf88]
25 Nov 00:45:00 - [info] [debug:320b0acf.2e36e6]
{ 'TK - Temp. Pannelli': '6', 'TS - Temp. bollitore': '36' }
25 Nov 00:45:01 - [info] [debug:eaaf8087.447f]
{
col5: 6,
col6: 33,
col7: 36,
}
{ col7: 36 } 25 Nov 00:45:01 - [warn] [telegram sender:31fd57fd.c122c8] msg.payload.chatId is empty
<--- Last few GCs --->
[1333:0x2bd49c0] 228117 ms: Mark-sweep 127.2 (128.9) -> 127.2 (128.9) MB, 21731.8 / 0.6 ms (average mu = 0.146, current mu = 0.002) allocation failure scavenge might not succeed
<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
/usr/bin/node-red-start: riga 75: 1333 Annullato node-red-pi
In the folder, I found a JSON highlighted in black. Can it be adjusted by removing the wrong node?
pi@chris:~/.node-red $ ls -l
-rw-r--r-- 1 pi pi 352 nov 20 18:31 flows_chris_cred.json -rw-r--r-- 1 pi pi 85928 nov 23 23:00 flows_chris.json
drwxr-xr-x 3 pi pi 4096 gen 8 2018 lib
drwxr-xr-x 270 pi pi 12288 nov 13 23:08 node_modules
-rw-r--r-- 1 pi pi 759 nov 13 23:09 package.json
-rw-r--r-- 1 pi pi 109372 nov 13 23:09 package-lock.json
-rw-r--r-- 1 pi pi 10720 feb 3 2021 settings.js
I'm sorry to disturbing, I tried many times the node-red --safe command and the last one restored everything without errors.
Now, can I back to work normally? What the difference if I continue in safe mode?
Thanks in advance
If you know what is incorrect and can edit it out, that should unbreak whatever broke it initially. If you are fearing of losing your flows for whatever reason, just make a copy of what you currently have as a backup and then go from there. If you break something else, just restore your copy and work until you figure out how to unbreak everything. So long as you have a backup, you can freely experiment until you unbreak everything. Without knowing the flow and the changes made to it that may have broken it, there's no way of telling how to unbreak it. But if you're not scared to experiment for fear of losing everything, then it makes it a lot easier.
The flows are stopped when starting it in safe mode. You had errors, you corrected them (i hope), once you deploy node-red will restart the flows and it will be running in its normal state.
msg.payload.chatId is empty
To avoid this, use something like a switch node in front of the telegram node to block or pass the message if chatId is/is not empty.
About backup, do you mean to export the flow? If yes, I do it regularly. I haven't scared to experiment but It was the first crash for me and looking the editor empty, I felt unhappy. So everything seems working fine now. Thanks
Usually, I export each flow from the browser editor saving it to my computer. Node red runs on raspberry and I don't know any other way how to do the backup. Is there another better and safer way?
The Node-Red folder on Linux is not exactly straightforward to find. You have to go to your home directory and navigate to the hidden node-red directory:
cd ~/.node-red
You should be able to find everything Colin is talking about after that.
Here are my daily, weekly, monthly backup scripts. You run them via CRON. You would need to adjust the bits that tell you to change for your system. They assume you are using MQTT but you can change the immediate outputs to use a node-red http-in/-out flow if you prefer, that is commented out in these. Main log output goes to syslog under the name nrmain-backup which again you can change to suit. These are designed to work on any Debian based Linux (should work on Debian, Raspbian, Ubuntu, etc).
Daily
#! /usr/bin/env bash
# Redirect stdout to syslog -
# show with: `sudo journalctl -t nrmain-backup`
# or `sudo cat /var/log/syslog | grep nrmain-backup`
exec 1> >(logger -t nrmain-backup -p local0.info)
# redirect stderr to syslog
exec 2> >(logger -t nrmain-backup -p local0.err)
# --- SET THESE TO THE CORRECT LOCATIONS --- #
NR_SERVICE_NAME=nrmain
NR_SOURCE_PATH=/home/home/nrmain
NR_DEST_PATH=/home/home/nrmain-backup
# ------------------------------------------ #
STARTDATE=$(date +'%Y-%m-%d %T')
echo " "
echo "Starting daily backup of $NR_SOURCE_PATH/ to $NR_DEST_PATH/ ..."
echo "Rotating snapshots ..."
# Delete oldest daily backup
if [ -d $NR_DEST_PATH/daily.7 ] ; then
echo " Deleting oldest daily backup $NR_DEST_PATH/daily.7"
# The slow but understandable way:
#rm -rf $NR_DEST_PATH/daily.7
# The faster way (needs an empty folder)
rsync -rd --delete $NR_DEST_PATH/empty/ $NR_DEST_PATH/daily.7/
fi
# Shift all other daily backups ahead one day
for OLD in 6 5 4 3 2 1 ; do
if [ -d $NR_DEST_PATH/daily.$OLD ] ; then
NEW=$(($OLD+1))
echo " Moving $NR_DEST_PATH/daily.$OLD to $NR_DEST_PATH/daily.$NEW"
# Backup last date
# ISSUE: touch does not support options on synology (busybox) system
touch $NR_DEST_PATH/.dtimestamp -r $NR_DEST_PATH/daily.$OLD
mv $NR_DEST_PATH/daily.$OLD $NR_DEST_PATH/daily.$NEW
# Restore timestamp
touch $NR_DEST_PATH/daily.$NEW -r $NR_DEST_PATH/.dtimestamp
fi
done
# Copy hardlinked snapshot of level 0 to level 1 (before updating 0 via rsync)
if [ -d $NR_DEST_PATH/daily.0 ] ; then
echo " Copying hardlinks from $NR_DEST_PATH/daily.0 to $NR_DEST_PATH/daily.1"
cp -al $NR_DEST_PATH/daily.0 $NR_DEST_PATH/daily.1
fi
echo "Finished rotating snapshots ..."
if ! [ -d $NR_DEST_PATH/daily.0 ] ; then
mkdir -p $NR_DEST_PATH/daily.0
fi
# Set today's date on the current backup folder
touch $NR_DEST_PATH/daily.0
ENDDATE=$(date --iso-8601=s)
# Back up
echo "Performing rsync backup ..."
rsync --archive --hard-links --delete --delete-excluded \
--exclude 'node_modules' --exclude 'data/node_modules' --exclude 'data/externalModules/node_modules' \
$NR_SOURCE_PATH/ $NR_DEST_PATH/daily.0
# Validate return code
# 0 = no error,
# 24 is fine, happens when files are being touched during sync (logs etc)
# all other codes are fatal -- see man (1) rsync
# You can output the result to MQTT or to a Node-RED http-in endpoint
if ! [ $? = 24 -o $? = 0 ] ; then
echo "Fatal: Node-RED daily backup finished with errors!"
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=daily&result=fail'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/daily/fail -m $ENDDATE
else
echo "Finished Node-RED daily backup, no errors."
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=daily&result=success'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/daily/success -m $ENDDATE
fi
# Sync disks to make sure data is written to disk
sync
#EOF
Weekly
#! /usr/bin/env bash
# Weekly backup for node-red
# Redirect stdout to syslog -
# show with: `sudo journalctl -t nrmain-backup`
# or `sudo cat /var/log/syslog | grep nrmain-backup`
exec 1> >(logger -t nrmain-backup -p local0.info)
# redirect stderr to syslog
exec 2> >(logger -t nrmain-backup -p local0.err)
# --- SET THESE TO THE CORRECT LOCATIONS --- #
NR_SERVICE_NAME=nrmain
NR_SOURCE_PATH=/home/home/nrmain
NR_DEST_PATH=/home/home/nrmain-backup
# ------------------------------------------ #
STARTDATE=$(date +'%Y-%m-%d %T')
echo " "
echo "Starting weekly backup of $NR_SOURCE_PATH/ to $NR_DEST_PATH/ ..."
echo "Rotating snapshots ..."
# Delete oldest weekly backup
if [ -d $NR_DEST_PATH/weekly.5 ] ; then
echo " Deleting oldest weekly backup $NR_DEST_PATH/weekly.5"
# The slow but understandable way:
#rm -rf $NR_DEST_PATH/weekly.5
# The faster way (needs an empty folder)
rsync -rd --delete $NR_DEST_PATH/empty/ $NR_DEST_PATH/weekly.5/
fi
# Shift all other weekly backups ahead one day
for OLD in 5 4 3 2 1 ; do
if [ -d $NR_DEST_PATH/weekly.$OLD ] ; then
NEW=$(($OLD+1))
echo " Moving $NR_DEST_PATH/weekly.$OLD to $NR_DEST_PATH/weekly.$NEW"
# Backup last date
# ISSUE: touch does not support options on synology (busybox) system
touch $NR_DEST_PATH/.wtimestamp -r $NR_DEST_PATH/weekly.$OLD
mv $NR_DEST_PATH/weekly.$OLD $NR_DEST_PATH/weekly.$NEW
# Restore timestamp
touch $NR_DEST_PATH/weekly.$NEW -r $NR_DEST_PATH/.wtimestamp
fi
done
# Copy hardlinked snapshot of level 0 to level 1 (before updating 0 via rsync)
if [ -d $NR_DEST_PATH/weekly.0 ] ; then
echo " Copying hardlinks from $NR_DEST_PATH/weekly.0 to $NR_DEST_PATH/weekly.1"
cp -al $NR_DEST_PATH/weekly.0 $NR_DEST_PATH/weekly.1
fi
echo "Finished rotating snapshots ..."
if ! [ -d $NR_DEST_PATH/weekly.0 ] ; then
mkdir -p $NR_DEST_PATH/weekly.0
fi
# Set today's date on the current backup folder
touch $NR_DEST_PATH/weekly.0
ENDDATE=$(date --iso-8601=s)
# Back up
echo "Performing rsync backup ..."
rsync --archive --hard-links --delete --delete-excluded \
--exclude 'node_modules' --exclude 'data/node_modules' --exclude 'data/externalModules/node_modules' \
$NR_SOURCE_PATH/ $NR_DEST_PATH/weekly.0
# Validate return code
# 0 = no error,
# 24 is fine, happens when files are being touched during sync (logs etc)
# all other codes are fatal -- see man (1) rsync
# You can output the result to MQTT or to a Node-RED http-in endpoint
if ! [ $? = 24 -o $? = 0 ] ; then
echo "Fatal: Node-RED weekly backup finished with errors!"
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=weekly&result=fail'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/weekly/fail -m $ENDDATE
else
echo "Finished Node-RED weekly backup, no errors."
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=weekly&result=success'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/weekly/success -m $ENDDATE
fi
# Sync disks to make sure data is written to disk
sync
#EOF
Monthly
#! /usr/bin/env bash
# Monthly backup for node-red
# Redirect stdout to syslog -
# show with: `sudo journalctl -t nrmain-backup`
# or `sudo cat /var/log/syslog | grep nrmain-backup`
exec 1> >(logger -t nrmain-backup -p local0.info)
# redirect stderr to syslog
exec 2> >(logger -t nrmain-backup -p local0.err)
# --- SET THESE TO THE CORRECT LOCATIONS --- #
NR_SERVICE_NAME=nrmain
NR_SOURCE_PATH=/home/home/nrmain
NR_DEST_PATH=/home/home/nrmain-backup
# ------------------------------------------ #
STARTDATE=$(date +'%Y-%m-%d %T')
echo " "
echo "Starting monthly backup of $NR_SOURCE_PATH/ to $NR_DEST_PATH/ ..."
echo "Rotating snapshots ..."
# Delete oldest monthly backup
if [ -d $NR_DEST_PATH/monthly.12 ] ; then
echo " Deleting oldest monthly backup $NR_DEST_PATH/monthly.12"
# The slow but understandable way:
#rm -rf $NR_DEST_PATH/monthly.12
# The faster way (needs an empty folder)
rsync -rd --delete $NR_DEST_PATH/empty/ $NR_DEST_PATH/monthly.12/
fi
# Shift all other monthly backups ahead one day
for OLD in 11 10 9 8 7 6 5 4 3 2 1 ; do
if [ -d $NR_DEST_PATH/monthly.$OLD ] ; then
NEW=$(($OLD+1))
echo " Moving $NR_DEST_PATH/monthly.$OLD to $NR_DEST_PATH/monthly.$NEW"
# Backup last date
# ISSUE: touch does not support options on synology (busybox) system
touch $NR_DEST_PATH/.mtimestamp -r $NR_DEST_PATH/monthly.$OLD
mv $NR_DEST_PATH/monthly.$OLD $NR_DEST_PATH/monthly.$NEW
# Restore timestamp
touch $NR_DEST_PATH/monthly.$NEW -r $NR_DEST_PATH/.mtimestamp
fi
done
# Copy hardlinked snapshot of level 0 to level 1 (before updating 0 via rsync)
if [ -d $NR_DEST_PATH/monthly.0 ] ; then
echo " Copying hardlinks from $NR_DEST_PATH/monthly.0 to $NR_DEST_PATH/monthly.1"
cp -al $NR_DEST_PATH/monthly.0 $NR_DEST_PATH/monthly.1
fi
echo "Finished rotating snapshots ..."
if ! [ -d $NR_DEST_PATH/monthly.0 ] ; then
mkdir -p $NR_DEST_PATH/monthly.0
fi
# Set today's date on the current backup folder
touch $NR_DEST_PATH/monthly.0
ENDDATE=$(date --iso-8601=s)
# Back up
echo "Performing rsync backup ..."
rsync --archive --hard-links --delete --delete-excluded \
--exclude 'node_modules' --exclude 'data/node_modules' --exclude 'data/externalModules/node_modules' \
$NR_SOURCE_PATH/ $NR_DEST_PATH/monthly.0
# Validate return code
# 0 = no error,
# 24 is fine, happens when files are being touched during sync (logs etc)
# all other codes are fatal -- see man (1) rsync
# You can output the result to MQTT or to a Node-RED http-in endpoint
if ! [ $? = 24 -o $? = 0 ] ; then
echo "Fatal: Node-RED monthly backup finished with errors!"
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=monthly&result=fail'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/monthly/fail -m $ENDDATE
else
echo "Finished Node-RED monthly backup, no errors."
#curl --insecure -I 'https://localhost:1880/nrnotify?type=backup&schedule=monthly&result=success'
mosquitto_pub -r -t services/$NR_SERVICE_NAME/backup/monthly/success -m $ENDDATE
fi
# Sync disks to make sure data is written to disk
sync
#EOF
Oh, should have also said that the current structure of the backups assumes you are using my alternate installer which installs node-red locally to a master folder with the userDir in a sub-folder called data. Shouldn't be hard to adjust the code though.