-

CommentStreams:3168bfb7e3def494ef9e4b306d348275

From Geekworm Wiki
Jump to navigation Jump to search

rc.local


 GNU nano 6.2                                                                                      /etc/rc.local
  1. !/bin/bash
  2. !/bin/sh -e
  3. rc.local
  4. This script is executed at the end of each multiuser runlevel.
  5. Make sure that the script will exit 0 on success or any other
  6. value on error.
  7. In order to enable or disable this script just change the execution
  8. bits.
  9. By default this script does nothing.


/etc/x-c1-pwr.sh & python3 /home/shanks/x-c1/fan.py & exit 0


Fan.py


  1. !/usr/bin/python

import pigpio import time

servo = 18

pwm = pigpio.pi() pwm.set_mode(servo, pigpio.OUTPUT) pwm.set_PWM_frequency( servo, 25000 ) pwm.set_PWM_range(servo, 100) while(1):

    #get CPU temp
    file = open("/sys/class/thermal/thermal_zone0/temp")
    temp = float(file.read()) / 1000.00
    temp = float('%.2f' % temp)
    file.close()
    if(temp > 30):
         pwm.set_PWM_dutycycle(servo, 40)
    if(temp > 50):
         pwm.set_PWM_dutycycle(servo, 50)
    if(temp > 60):
         pwm.set_PWM_dutycycle(servo, 70)
    if(temp > 70):
         pwm.set_PWM_dutycycle(servo, 80)
    if(temp > 75):
         pwm.set_PWM_dutycycle(servo, 100)
    if(temp < 30):
         pwm.set_PWM_dutycycle(servo, 0)
    time.sleep(1)

rc.local is running


shanks@ubuntu:~/x-c1$ sudo systemctl status rc-local ● rc-local.service - /etc/rc.local Compatibility

    Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
   Drop-In: /usr/lib/systemd/system/rc-local.service.d
            └─debian.conf
    Active: active (running) since Mon 2023-01-09 15:38:09 CET; 17min ago
      Docs: man:systemd-rc-local-generator(8)
   Process: 809 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
     Tasks: 4 (limit: 2082)
    Memory: 5.7M
       CPU: 1min 8.055s
    CGroup: /system.slice/rc-local.service
            ├─  812 /bin/bash /etc/x-c1-pwr.sh
            ├─  813 python3 /home/shanks/x-c1/fan.py
            └─12725 /bin/sleep 0.2

Jan 09 15:38:09 ubuntu systemd[1]: Starting /etc/rc.local Compatibility... Jan 09 15:38:09 ubuntu rc.local[812]: Your device are shutting down... Jan 09 15:38:09 ubuntu systemd[1]: Started /etc/rc.local Compatibility.


Ubuntu version: Ubuntu 22.04.1 LTS


Python version : Python 3.10.6


xoff is now working fine but the fan script is not working. i tried to execute is manually but nothins happens (i did set the values to 0 to see if the commands will stop the fan but it didn't)