x-c1 icon indicating copy to clipboard operation
x-c1 copied to clipboard

x-c1-fan.sh service throws error because of problem with float -> int conversion

Open dermaze opened this issue 1 year ago • 1 comments

The fan script did not work properly after installation, so I had a look at the service:

pi@raspberrypi:~ $ sudo systemctl status x-c1-fan.service 
● x-c1-fan.service - Daemon to monitor and control fan speed
   Loaded: loaded (/lib/systemd/system/x-c1-fan.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2024-11-02 19:43:20 CET; 1h 38min ago
 Main PID: 455 (bash)
    Tasks: 2 (limit: 4164)
   CGroup: /system.slice/x-c1-fan.service
           ├─ 455 bash /usr/local/bin/x-c1-fan.sh
           └─2641 sleep 5

Nov 02 21:21:17 raspberrypi x-c1-fan.sh[455]: /usr/local/bin/x-c1-fan.sh: Zeile 184: printf: 46.74: Ungültige Zahl.
Nov 02 21:21:22 raspberrypi x-c1-fan.sh[455]: /usr/local/bin/x-c1-fan.sh: Zeile 184: printf: 44.79: Ungültige Zahl.
Nov 02 21:21:27 raspberrypi x-c1-fan.sh[455]: /usr/local/bin/x-c1-fan.sh: Zeile 184: printf: 46.74: Ungültige Zahl.

The printf function is used for conversion from float to int, but fails. So I used the builtin number manipulation capabilities of bash instead:

    CUR_TEMP=${TEMP/.*}    #This does now work as intended
    #printf -v CUR_TEMP %0.0f "$TEMP" # Convert float to int, but does not work, original method, now commented out

Now the script works:

pi@raspberrypi:~ $ sudo systemctl status x-c1-fan.service 
● x-c1-fan.service - Daemon to monitor and control fan speed
   Loaded: loaded (/lib/systemd/system/x-c1-fan.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2024-11-02 21:40:50 CET; 12min ago
 Main PID: 26993 (bash)
    Tasks: 2 (limit: 4164)
   CGroup: /system.slice/x-c1-fan.service
           ├─ 4042 sleep 5
           └─26993 bash /usr/local/bin/x-c1-fan.sh

Nov 02 21:40:50 raspberrypi systemd[1]: Started Daemon to monitor and control fan speed.
Nov 02 21:40:50 raspberrypi x-c1-fan.sh[26993]: Fan speed changed to 45, temp is 46.74
Nov 02 21:42:40 raspberrypi x-c1-fan.sh[26993]: Fan speed changed to 50, temp is 50.63
Nov 02 21:42:55 raspberrypi x-c1-fan.sh[26993]: Fan speed changed to 45, temp is 48.20

dermaze avatar Nov 02 '24 20:11 dermaze

Thanks.

Refer to https://github.com/geekworm-com/xscript

geekworm-com avatar Nov 04 '24 07:11 geekworm-com