XScript

From Geekworm Wiki
Jump to navigation Jump to search

This is script installation tutorial for NASPi, NASPi Gemini 2.5, NASPi CM4-M2 and NASPi CM4-2.5

This script also works on bookworm OS, and test it on Jan. 9th 2024.

The original key pwm fan control script is from pimlie/geekworm-x-c1, pimlie implements the pwm fan shell script, which does not depend on third-party python libraries at all. Thanks to pimlie.


Now we think you have successfully flashed the OS Image into Micro SD and and power on the device, and you have also completed the operations such as creating new user required in some Raspberry Pi OS.

After your system boots, then you need to open Terminal prpgram, then type the following command to complete the installation of the script


[Update]

1. NASPi series does not support Raspberry Pi 5 hardwared due to different hardware interface.

2. Use gpiod instead of obsolete interface, and supports ubuntu 23.04 also

3. The script now supports the Raspberry Pi OS BOOKWORM version. You just need to uninstall the original script and reinstall it. Please refer to the following:

OPen ternimal window, then run the following command:

mv xscript xcript-old
git clone https://github.com/geekworm-com/xscript
cd xscript
chmod +x *.sh
./uninstall.sh

Then just follow the installation process below.

OS that has been tested

  • Raspbian
  • DietPi
  • Manjaro
  • Ubuntu (Testing based on Ubuntu 23.04)
  • myNode
  • Umbrel
  • Volumio
  • RetroPie
  • Twister

Note: Not tested with Home Assistant, for some reason, we are not able to upgrade and use the Home Assistant to test, please pay attention to check if there is any update in the future.(If you have successfully tested Home Assistant, welcome to share your experience via email at: support@geekworm.com)

Preconfigured config.txt

To install pwm fan, first add dtoverlay=pwm-2chan to /boot/firmware/config.txt or /boot/config.txt under [all] or the end of file and reboot:

sudo nano /boot/firmware/config.txt

Some OS's config.txt may be in the /boot/ directory, so that you need to run the following command:

sudo nano /boot/config.txt

Using ls /boot/firmware/config.txt you can check if the file is in the /boot/firmware/ directory

Save & exit.

sudo reboot

PS: Only appending to the last line not replace.

Install gpiod package

sudo apt install -y gpiod

Download the script

git clone https://github.com/geekworm-com/xscript

cd xscript
chmod +x *.sh

PS: For some OS such as Raspberry Pi OS Lite, the git tool is not installed by default, if you get an error like error: -bash: git: command not found, please run the following command to install the git tool.

sudo apt install -y git

Create the x-c1-fan service

Note: If your device does not support pwm fans or you are not using pwm, you can skip this step

Run the following command to install fan service script;

sudo ./install-fan-service.sh

Then the pwm fan starts running.

Create the x-c1-pwr service

sudo ./install-pwr-service.sh

Prepair software shutdown script

sudo ./install-sss.sh

Then run the following command to create a alias 'xoff' command

echo "alias xoff='sudo /usr/local/bin/xSoft.sh 0 27'" >>   ~/.bashrc
source ~/.bashrc

After the installation is complete, an xoff command will be created to shut down the software.Then you can run xoff to execute software shutdown.

Uninstall

Run the following command to uninstall all.

sudo ./uninstall.sh

Test safe shutdown

Software safe shutdown command:

xoff

DON'T run the 'shutdown' linux command to shut down, otherwise the power of shield will not be shut down.

Hardware safe shutdown operation:

You can verify the safety switch through the onboard switch, press and hold the switch for 3 seconds, then the blue LED will flash slowly and the shutdown is going then all LEDs will be off until the device is completely powered off.

  • press on-board button switch 1-2 seconds to reboot
  • press button switch 3 seconds to safe shutdown,
  • press 7-8 seconds to force shutdown.

Sample

  1. The code for fan speed control is now in the x-c1-fan.sh file.
  2. fan-rpi.py and fan-pigpio.py are no longer used, and are reserved here for research and use by python lovers only.

Support

Email: support@geekworm.com

If you have any problems during use, please contact us by email and tell us the product model you are using and the OS version you are using.

FAQ

Q: How to login volumio via SSH?

1. Enable SSH:

Visit http://volumio.local/dev/, then click ENABLE SSH button

2. URL connection is IP address, and the default user name is volumio, default password is volumio

Q: How to login to Umbrel via SSH? A: ssh umbrel@umbrel.local (or ssh umbrel@). the default user name is umbrel, default password is moneyprintergobrrr
Q: How to login to myNode via SSH? A: URL connection is IP address, and the default user name is admin, default password is bolt
Q: How to login to DietPi via SSH? A: URL connection is IP address, and the default user name is root, default password is dietpi
Q: Is LibreELEC supported? A: TODO


Add your comment
Geekworm Wiki welcomes all comments. If you do not want to be anonymous, register or log in. It is free.


Anonymous user #24

one month ago
Score 0++
Hi, I followed this guide and now xoff works, but the fan not move at all. It show active and enabled when I enter "sudo systemctl status x-c1-fan.service". Is it the fan broken or have any suggestion to debug?

Anonymous user #24

one month ago
Score 0++
I also using raspberryOS 64bit(bookworm)

Lisa

one month ago
Score 0++
Hi,Please check if the [FAN FS] is shorted by Jumper Cap.

Anonymous user #24

one month ago
Score 0++
Hi, is there a version of Debian 12(Bookworm)? I'm using NASPi and the fan not working and "xoff: command not found" after install script.

Lisa

one month ago
Score 0++
Hi,Sorry,we have not tested the Debian yet, you can refer to other users' feedback.XScript#comment-4426 or XScript#comment-4046

Anonymous user #25

one month ago
Score 0++
I have the same problem...

Anonymous user #23

one month ago
Score 0++

Hi, I followed this guide and now xoff works like a charm, many thanks.

On the other hand, even if I am able to run and control my fan, even at low speeds it's very loud. I tried changing some values in the x-c1-fan.sh script and the fan responded but it never got "silent" like it used to be. I remember it being very silent, especially at low speeds.

What can i do? is there something i missed to try? I'm kinda a newbie when it comes to hardware, and the Naspi was not touched since i built it, therefore i can't explain to me why the fan got noisy.

Any help?

Thanks in advance

Anonymous user #22

one month ago
Score 0++
If I do not install the script, I can still switch on and switch off my Pi4 with the X-C1 board. Is that save or is it like a hard shut off which might corrupt my SD card?

Lisa

one month ago
Score 0++
Hi,Yes, if you do not install the script, press 7-8 seconds to force shutdown.

Anonymous user #20

2 months ago
Score 0++
I have installed retropi to my pi4. Run sudo update and sudo upgrade first and then installed xscript. Fan controll works but xoff command doesnt work. Says command not found. Rebooted multiple times. I have to force close with power button. What can i do?

Anonymous user #21

2 months ago
Score 0++

Create an alias yourself by running these two commands:

echo "alias xoff='sudo /usr/local/bin/xSoft.sh 0 27'" >> ~/.bashrc

source ~/.bashrc

Anonymous user #19

3 months ago
Score 0++
It works. Thank you.

Anonymous user #18

3 months ago
Score 0++

Your "fix" for kernel 6.6 does not work.

~ $ cd xscript rm x-c1-softsd.sh x-c1-pwr.sh -f git pull origin chmod +x *.sh sudo cp -f . /x-c1-softsd.sh /usr/local/bin/ sudo cp -f . /x-c1-pwr.sh /usr/local/bin/ sudo reboot Already up to date. cp: -r not specified; omitting directory '.' cp: cannot stat '/x-c1-softsd.sh': No such file or directory cp: -r not specified; omitting directory '.' cp: cannot stat '/x-c1-pwr.sh': No such file or directory

Broadcast message from root@mediabed on pts/1 (Tue 2024-03-19 19:15:49 CDT):

The system will reboot now!


paul@mediabed:~ $ ~ $ xoff /usr/local/bin/x-c1-softsd.sh: line 5: echo: write error: Invalid argument /usr/local/bin/x-c1-softsd.sh: line 6: /sys/class/gpio/gpio27/direction: No such file or directory /usr/local/bin/x-c1-softsd.sh: line 7: /sys/class/gpio/gpio27/value: No such fil e or directory Your device will shutting down in 4 seconds...

/usr/local/bin/x-c1-softsd.sh: line 19: /sys/class/gpio/gpio27/value: No such fi le or directory

Harry

3 months ago
Score 0++
reinstall script.

Anonymous user #17

3 months ago
Score 0++

Hello, I install XScript on a "Linux raspberid64 6.6.17-v8+ #1734 SMP PREEMPT Mon Feb 19 11:59:52 GMT 2024 aarch64" but the "x-c1-pwr.sh" doesn't work properly:

$ sudo /usr/local/bin/x-c1-pwr.sh /usr/local/bin/x-c1-pwr.sh: line 6: echo: write error: Invalid argument /usr/local/bin/x-c1-pwr.sh: line 7: /sys/class/gpio/gpio4/direction: No such file or directory /usr/local/bin/x-c1-pwr.sh: line 9: echo: write error: Invalid argument /usr/local/bin/x-c1-pwr.sh: line 10: /sys/class/gpio/gpio17/direction: No such file or directory /usr/local/bin/x-c1-pwr.sh: line 11: /sys/class/gpio/gpio17/value: No such file or directory

The problem is I haven't this 'directories' : /sys/class/gpio/gpio4 /sys/class/gpio/gpio17

I only have this in gpio:

$ sudo ls /sys/class/gpio -la total 0 drwxrwxr-x 2 root gpio 0 Feb 23 06:20 . drwxr-xr-x 66 root root 0 Jun 18 2023 .. --w--w---- 1 root gpio 4096 Mar 11 09:23 export lrwxrwxrwx 1 root gpio 0 Feb 23 06:20 gpiochip512 lrwxrwxrwx 1 root gpio 0 Feb 23 06:20 gpiochip570 --w--w---- 1 root gpio 4096 Feb 23 06:20 unexport

Can anyone tellme what's wrong??

Harry

2 months ago
Score 0++

You upgraded the OS and the kernel was updated in the new OS.

Please re-download & reinstall the script

Anonymous user #16

3 months ago
Score 0++

I installed XScript on Raspberry Pi OS, but excute source ~/.bashrc display -sh: 1: source: not found

xoff command don't work but sudo /usr/local/bin/x-c1-softsd.sh works fine.

Perhaps "source ~/.bashrc" error caouse the phenomenon.

Can I solve this error?

Harry

2 months ago
Score 0++

Your system is missing the source command.

You can reboot your device to make bashrc take effect

Anonymous user #9

4 months ago
Score 0++

Fan control and work with power button for NASPi Gemini 3.5 and Raspberry Pi Debian

github.com/aardzhanov/naspi35_xscript

Anonymous user #9

4 months ago
Score 0++
Work with debian?

Anonymous user #14

5 months ago
Score 0++
I wrote to support because after setting up the power service the Raspberry is stuck in a boot loop. According to support this is normal while the X-c1 hardware is not connected to the Raspberry. I think that this is a HUGE PROBLEM since the Raspberry becomes unusable if it's separated from the hardware or if the hardware should fail. I advise everyone to STAY AWAY from this script and possibly from the product: since the raspberry is stuck it's no longer possible to access it.

Anonymous user #13

6 months ago
Score 0++
Hey, using NASPi Gemini 2.5 dual ssd expansion, I recently decided to start back from scratch and test a different OS instead of omv. The fan script was working fine before and so was xoff. I reformatted everything, put Ubuntu server on it and created script according to instructions. Can doesn’t appear to work now anymore and running xoff it starts counting down to shutdown but it doesn’t shut it down. Also, power button on the unit doesn’t reboot or shutdown the unit either, only force shutdown seems to work now.

Walker

6 months ago
Score 0++
Hello. Normally. NASPi Gemini 2.5 is Compatible with all Raspberry Pi operating systems, you can contact us via our email: support@geekworm.com we will do our best to solve your problem

Anonymous user #11

6 months ago
Score 0++
after complete this step, "Create the x-c1-pwr service". my screen just goes black. this happened about 5 times. driving me nuts.

Anonymous user #11

6 months ago
Score 0++
i also want to add that i have to reflash my sdcard. using ubuntu 22.04.3lts

Walker

6 months ago
Score 0++
Hello, you can contact us via our email: support@geekworm.com ,Describe your problem more clearly, By the way, provide your order number, In this way, we can better solve your problem

Anonymous user #14

5 months ago
Score 0++

I have the same problem: RaspberryOS 64bit on Raspi4B 4Gb, wrote a mail to support.

The last step is somehow wrong: it shuts down the Raspberry immedately and is then stuck in a boot loop.

Anonymous user #10

6 months ago
Score 0++
How do I configure it with home assistant?

Walker

6 months ago
Score 0++
Hi, we haven't tested it on home assistant, there's no way to help you with that.

Anonymous user #9

8 months ago
Score 0++

Hi all! I was started fan on Debian! Use fan-rpi.py python script instead shell.

Also I add iomem=relaxed in /boot/firmware/cmdline.txt.

Anonymous user #9

8 months ago
Score 0++

small refactoring of fan-rpi.py

  1. !/usr/bin/python3
  1. DON'T use pigpiod library on Nov. 24 2022 by Harry Huang
  2. import pigpio

import RPi.GPIO as IO import time import subprocess import logging

servo = 18 logging.basicConfig(format='%(message)s', level=logging.DEBUG) IO.setwarnings(False) IO.setmode (IO.BCM) IO.setup(servo,IO.OUT) fan = IO.PWM(servo,2000) fan.start(0)

def get_temp(): output = subprocess.run(['cat', '/sys/class/thermal/thermal_zone0/temp'], capture_output=True) temp_str = output.stdout.decode() try: return float(temp_str)/1000 except (IndexError, ValueError): raise RuntimeError('Could not get temperature')

while 1: temp = get_temp() # Get the current CPU temperature if temp > 60: # Check temperature threshhold, in degrees celcius fan.ChangeDutyCycle(100) # Set fan duty based on temperature, 100 is max speed and 0 is min speed or off. logging.debug("Temp: %d, speed: 100", temp) elif temp > 50: fan.ChangeDutyCycle(90) logging.debug("Temp: %d, speed: 90", temp) elif temp > 40: fan.ChangeDutyCycle(85) logging.debug("Temp: %d, speed: 85", temp) elif temp > 32: fan.ChangeDutyCycle(70) logging.debug("Temp: %d, speed: 70", temp) elif temp > 25: fan.ChangeDutyCycle(60) logging.debug("Temp: %d, speed: 60", temp) else: fan.ChangeDutyCycle(0) logging.debug("Temp: %d, speed: 0", temp)

time.sleep(5) # Sleep for 5 seconds

Walker

8 months ago
Score 0++
Thank you for your attention to our products

Anonymous user #8

8 months ago
Score 0++

What is about gemini 3.5?

Power script does not work with RPi 4B and debian.

Walker

8 months ago
Score 0++
Hello, NASPi Gemini 3.5 is an Ideal storage solution specially designed for Raspberry Pi 4B. OS that has been tested: Raspbian, DietPi, Manjaro, Ubuntu, myNode, Umbrel, Volumio, RetroPie, Twister. Currently we have not tested it on debian.

Anonymous user #15

5 months ago
Score 0++
Same here. I installed the scripts on a Raspberry Pi 4B with DietPi (which is Debian under the hood). Fan script is working well, but the shutdown script only prints the downtime info and does nothing afterwards. Need some assistance here.

Anonymous user #7

9 months ago
Score 0++
Hi NASPi Gemini 3.5 with Raspberry Pi 64bit Lite, fan not working : (

Anonymous user #7

9 months ago
Score 0++

pi@raspberrypi:~/xscript $ 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 Thu 2023-09-14 07:29:03 BST; 58min ago Main PID: 461 (bash) Tasks: 2 (limit: 1599) CPU: 18.604s CGroup: /system.slice/x-c1-fan.service ├─ 461 bash /usr/local/bin/x-c1-fan.sh └─41092 sleep 5

Sep 14 08:21:51 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 80, temp is 74.01 Sep 14 08:22:01 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 100, temp is 74.98 Sep 14 08:24:07 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 80, temp is 74.50 Sep 14 08:24:12 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 100, temp is 75.47 Sep 14 08:24:27 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 80, temp is 74.50 Sep 14 08:24:32 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 100, temp is 75.96 Sep 14 08:24:37 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 80, temp is 74.50

Sep 14 08:24:42 raspberrypi x-c1-fan.sh[461]: Fan speed changed to 100, temp is 75.47

Walker

9 months ago
Score 0++
Hello, you can contact us via our email: support@geekworm.com ((Please provide your order number)) we will do our best to solve your problem

Anonymous user #6

9 months ago
Score 0++
For three days, autopower on worked normally. Now i shutdown the unit with script, i remove energy, put it back again, but the unit is not poweron automatically. I have to press the button. Do you have any advice?

Harry

9 months ago
Score 0++

Hi,

When you turn on the power again, please increase the interval time, for example, wait for about one minute and then try again.

Anonymous user #5

10 months ago
Score 0++

Hi, Is there anyway to report on the fan speed through he script? I can see that the fan is running and I'd like to see the Pi Temp and Fan speed?

Thanks

Richard

Harry

10 months ago
Score 0++

Hi,

Try to run the command:

sudo systemctl status x-c1-fan.service

Anonymous user #4

10 months ago
Score 0++

Line 184 is: " printf -v CUR_TEMP %0.0f "$TEMP" # Convert float to int" Return invalid Number in daemon service.

S.O raspberrypi 6.1.29-v8+ #1652 SMP PREEMPT Wed May 24 14:46:55 BST 2023 aarch64 locale: LANG=it_IT.UTF-8 LANGUAGE=it_IT.UTF-8 LC_CTYPE="it_IT.UTF-8" LC_NUMERIC="it_IT.UTF-8" LC_TIME="it_IT.UTF-8" LC_COLLATE="it_IT.UTF-8" LC_MONETARY="it_IT.UTF-8" LC_MESSAGES="it_IT.UTF-8" LC_PAPER="it_IT.UTF-8" LC_NAME="it_IT.UTF-8" LC_ADDRESS="it_IT.UTF-8" LC_TELEPHONE="it_IT.UTF-8" LC_MEASUREMENT="it_IT.UTF-8" LC_IDENTIFICATION="it_IT.UTF-8"

LC_ALL=it_IT.UTF-8

Walker

10 months ago
Score 0++
Hello, what product did you purchase? If you encounter a problem that is difficult to solve, you can contact us by email: support@geekworm.com and describe your problem clearly, we will try our best to solve your problem, thank you

Anonymous user #12

6 months ago
Score 0++

I had the same error. I'm italian too and we use the comma as separator for decimals. The solution is to modify x-c1-fan.sh file.

I have done as follow:

1) Type in terminal cd ~/xscript sudo nano x-c1-fan-sh 2) Modify function get_temp { RAW_TEMP="$(cat /sys/class/thermal/thermal_zone0/temp)" TEMP="$(awk -v temp="$RAW_TEMP" 'BEGIN { printf "%0.2f", temp / 1000; exit(0) }')" echo "$TEMP" }

with this

function get_temp { RAW_TEMP="$(cat /sys/class/thermal/thermal_zone0/temp)" TEMP="$(awk -v temp="$RAW_TEMP" 'BEGIN { printf "%0.0f", temp / 1000; exit(0) }')" echo "$TEMP" } 3) Then follow the istruction in this page to uninstall the script 4) Then follow the istruction in this page to reinstall the script

Now it works for me. Sorry to all of you for my bad english

PS: I've only modified 'printf "%0.2f"' with 'printf "%0.0f"' to get the integer right away.

Anonymous user #3

10 months ago
Score 0++

Hi Harry, thanks for your fast reply. I bought Naspi V2.0 2,5 Inch for Raspberry Pi 4. I completed the assembly of the product hardware and my Raspberry Pi 4 ist running. I used the Linux distribution "RaspiBlitz". Currently I am downloading BTC Blockchain and the Raspberry is at 84 degrees Celsius.. so I really would like to get the fan running.. I dont understand anythiung from this tutorial and I dont think this is straight forward for beginners.. Hope that clarifies my situation.

DK101

Harry

10 months ago
Score 0++

Hi.

I reply to you via email.

About FAN FS, refer to picture:

IMG 3713-compare-NEW.jpg

Anonymous user #3

10 months ago
Score 0++

Hey there, Im a total noob regarding such stuff... the tutorial above just leaves me with a lot of questions :D I run RaspiBlitz OS and trying to figure out how to activate the fan.. any advise?

Regards DK101

Harry

10 months ago
Score 0++

Hi,

First of all, I don't know exactly what product you bought. But before the script installation, you can complete the assembly of the product hardware by watching the video or installation guide, and then download the OS, flash the OS and other operations. Then complete the installation of the script with this tutorial.

This tutorial is relatively simple, I'm sorry I don't know how I can help you.

Harry / Geekworm Team

Anonymous user #2

10 months ago
Score 0++

Hi, I successfully installed the X-Script on my Naspi and it works perfectly! But I see countless entries in the daemon.log every 5 seconds: x-c1-fan.sh[483]: /usr/local/bin/x-c1-fan.sh: Zeile 184: printf: 38.46: Ungültige Zahl. "Ungültige Zahl" means "invalid number".

Line 184 is: " printf -v CUR_TEMP %0.0f "$TEMP" # Convert float to int"

Do you know what causes this and how to fix this?

Thanks a lot!

Stony

Harry

10 months ago
Score 0++

Hi, Stony


Thanks for your feedback.

Want to know what OS you are using? Is it the official system of Raspberry Pi?


We recommend that you reply to us via email support@geekworm.com

Anonymous user #2

10 months ago
Score 0++
Hi, I'm using Raspbian GNU/Linux 10 (buster)

Anonymous user #2

10 months ago
Score 0++

I forgot to mention that my Raspbian is set to german locale. We are using a comma as decimal separator (e.g. 40,4 insteda of 40.4 °C. I think this causes the error, right?

Stony

Anonymous user #1

11 months ago
Score 0++

Hi, how to uninstall this X-Script? Because the temperature now is higher than with the older X-C1-script I used before. Thanks!

Achim

Harry

11 months ago
Score 0++

Hi,

New add #Uninstall secton.

But I still recommend you to use the new script. The higher temperature may just be your illusion.