Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dermaze opened this issue Nov 2, 2024 · 1 comment

Comments

@dermaze
Copy link

dermaze commented Nov 2, 2024

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
@geekworm-com
Copy link
Owner

geekworm-com commented Nov 4, 2024

Thanks.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants