This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 50 Test new fan.py script * 50 Test mount disks * 50 Add rc.local to mount disks * 50 Fix playbooks --------- Co-authored-by: veerendra2 <[email protected]>
- Loading branch information
1 parent
6a41d16
commit e604b7f
Showing
11 changed files
with
88 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,47 @@ | ||
#!/usr/bin/python3 | ||
''' | ||
Description: A simple script to control 3pin PWM fan in raspberry pi 4 | ||
Reference: https://github.com/geekworm-com/x-c1/blob/main/fan.py | ||
''' | ||
import pigpio | ||
import time | ||
import logging | ||
|
||
logging.basicConfig(format='%(levelname)s:%(asctime)s %(message)s', level=logging.DEBUG) | ||
# Pin number for the fan | ||
FAN_PIN = 18 | ||
|
||
# PWM frequency and duty cycle range | ||
PWM_FREQ = 25000 | ||
PWM_RANGE = 100 | ||
|
||
servo = 18 | ||
# Temperature thresholds and corresponding duty cycles | ||
TEMP_THRESHOLDS = [(75, 100), (70, 80), (60, 70), (48, 50), (30, 40)] | ||
|
||
logging.basicConfig(format='%(levelname)s:%(asctime)s %(message)s', level=logging.DEBUG) | ||
|
||
pwm = pigpio.pi() | ||
pwm.set_mode(servo, pigpio.OUTPUT) | ||
pwm.set_PWM_frequency(servo, 25000) | ||
pwm.set_PWM_range(servo, 100) | ||
while (True): | ||
pwm.set_mode(FAN_PIN, pigpio.OUTPUT) | ||
pwm.set_PWM_frequency(FAN_PIN, PWM_FREQ) | ||
pwm.set_PWM_range(FAN_PIN, PWM_RANGE) | ||
|
||
prev_dc = None | ||
while True: | ||
# Get CPU temp | ||
with open("/sys/class/thermal/thermal_zone0/temp") as f: | ||
temp = float(f.read()) / 1000.00 | ||
temp = float('%.2f' % temp) | ||
|
||
if (temp > 75): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 100%") | ||
pwm.set_PWM_dutycycle(servo, 100) | ||
elif (temp > 70): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 80%") | ||
pwm.set_PWM_dutycycle(servo, 80) | ||
elif (temp > 60): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 70%") | ||
pwm.set_PWM_dutycycle(servo, 70) | ||
elif (temp > 50): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 50%") | ||
pwm.set_PWM_dutycycle(servo, 50) | ||
elif (temp > 30): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 40%") | ||
pwm.set_PWM_dutycycle(servo, 40) | ||
elif (temp < 30): | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to 0%") | ||
pwm.set_PWM_dutycycle(servo, 0) | ||
|
||
time.sleep(120) | ||
temp = float(f.read()) / 1000.00 | ||
temp = round(temp, 2) | ||
|
||
# Determine duty cycle based on temperature | ||
duty_cycle = 0 | ||
for threshold, dc in TEMP_THRESHOLDS: | ||
if temp >= threshold: | ||
duty_cycle = dc | ||
break | ||
|
||
# Set fan speed if duty cycle has changed | ||
if duty_cycle != prev_dc: | ||
pwm.set_PWM_dutycycle(FAN_PIN, duty_cycle) | ||
logging.debug(f"Current CPU temperature is {temp}°C. Setting fan speed to {duty_cycle}%") | ||
prev_dc = duty_cycle | ||
|
||
# Wait for 2 minutes before checking temperature again | ||
time.sleep(60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
POSTGRES_HOST=postgres | ||
POSTGRES_HOST=databases_postgres | ||
POSTGRES_DB_FILE=/run/secrets/postgres_db | ||
POSTGRES_USER_FILE=/run/secrets/postgres_user | ||
POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
- 53 | ||
- 7359 | ||
- 1900 | ||
- 2377 | ||
allow_udp_ports: | ||
- 53 | ||
- 67 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters