04 ‐ The scripts - ronbuist/remeha-can-interface GitHub Wiki
Overview
There are two scripts that I've made to get the information from the Calenta Ace's CAN bus:
remeha_start.sh
. This script is started from the crontab. The user starting it should have sudo privileges, so it can bring up the CAN0 interface and create a directory under /run. This script will start the other script.remeha.sh
. This is the main script that parses the output of thecandump
utility. It creates a file/run/remeha/remeha.json
with the current data from the boiler.
remeha_start.sh
Put this script in the crontab of a user with sudo privileges. I am using the following crontab entry:
* * * * * /home/pi/scripts/start_remeha.sh >/dev/null 2>&1
This will run the command every minute. The first thing the script does, is check if the candump
utility is already running. If this
is the case, the script will exit. By running the script every minute, we are making sure it will start quickly after a reboot of the
system.
If candump
is not running, the script will proceed to check if the directory to write to (which is /run/remeha
) exists and is writable. It's important to realize that the script will continuously recreate the remeha.json file. The /run
folder is a RAM drive,
which means the script is not writing to the micro SD card. This ensures a longer lifetime for the micro SD card. It also means that the json file will not survive a reboot, but that's OK since it will be recreated shortly after reboot anyway.
Next, the script checks if the CAN0 interface is up. If this is not the case, it will be brought up. This needs to be done once after a reboot.
Finally, the script will start the candump
utility, sending the output to the remeha.sh
script.
The script does a bit of logging, but the crontab entry will redirect this to /dev/null
, so effectively there is no logging. However, when you are setting things up, you may want to run remeha_start.sh manually instead of through cron. This way, you can see what's happening.
remeha.sh
The script remeha.sh
will loop through the loglines produced by candump
, storing information whenever a line with a relevant CAN ID is received. To see how I've come up with the CAN ID's to use and what they mean, see the Analysis Wiki page.
I've created the hex2int function to convert the hexadecimal values to decimal. This also reverses the order of the bytes (converting from little endian).
The JSON file is only rewritten when a relevant CAN ID was received. The other CAN IDs are ignored. The contents of the JSON:
{
"datetime": "2024-12-28 19:58:32",
"statusid": "3",
"statusdescription": "heat active",
"flowtemperature": 46.4,
"setpoint": 51,
"power": 62,
"pressure": 1.6
}