LATEST RELEASE: FPP 8.4 - Download from here - https://github.com/FalconChristmas/fpp/releases/tag/8.4
Host Name: Lighting1
CPU Temperature: 49C
CPU Usage: 3%
Disk Usage: 23%
Memory Usage: 47%
Power OK.
Fuse Failure!
Case Temperature 44.9C
Battery Voltage 11.43 Volts
Fan On
Cooling Off
Host Name: Lighting1
CPU Temperature: 49C
CPU Usage: 3%
Disk Usage: 23%
Memory Usage: 47%
Power OK.
Fuse Status: Unknown
Case Temperature 44.9C
Battery Voltage 11.43 Volts
Fan On
Cooling Off
#! /usr/bin/python3
# pi_monitor.py
# Scan / print the health of a Raspberry Pi and
# report any issues to the phone or email list
import psutil, subprocess, email, smtplib, ssl, SendMessage
from time import sleep
from sys import argv, exit
from os import uname
from gpiozero import CPUTemperature
import RPi.GPIO as GPIO
Degrees = "\u00B0C" # Degree symbol UTF-16
Degrees = "C"
HighCPUUsage = 90 # High CPU usage in %
HighCPUTemp = 65 # High CPU temperature in Celsius
CritCPUTemp = 80 # Critical CPU temperature in Celsius
HighMemUsage = 70 # High Memory utilization
HighDiskUsage = 60 # High Disk utilization
Uname = uname().nodename
phones = [["##########", "Consumer Cellular", True],["##########", "Sprint", True], ["#######", "##########", False]]
# runDef = [ Script Name, Delay in seconds, Send to stdout, Send email / sms ]
runDef = [["start", 30, False, True], ["check", 0, False, False], ["print", 0, True, False], ["flash", 0, True, True], ["mail", 0, False, True]]
GPIO.setmode(GPIO.BCM)
GPIO.setup(4,GPIO.IN)
GPIO.setup(17,GPIO.IN)
Fuse = GPIO.input(4)
Power = GPIO.input(17)
if len(argv) > 0: # Should always be non-zero if called from CLI
envString = argv[0] # Contains the name by which the script was called
for runVal in runDef:
scriptName, scriptDelay, scriptPrint, scriptMail, *rest = runVal
if envString.find(scriptName) > 0: # Check if script called with this runVal value
sleep(scriptDelay)
break
else:
print("WTF?") # Not called from CLI
exit(1)
def pi_status(): # Main routine: always called by script
# Gather information about system
result1 = getTemperature()
result2 = getCPU()
result3 = getDiskUsage()
result4 = getMemUsage()
if scriptMail: # Called with Mail Send request: send email
if scriptName == "start":
sendText = "Raspberry Pi Startup notification\r\n"
else:
sendText = "Raspberry Pi Monitor Mail\r\n"
sendText = sendText + "Host Name: " + Uname + "\r\n"
sendText = sendText + result1+ "\r\n"
sendText = sendText + result2+ "\r\n"
sendText = sendText + result3+ "\r\n"
sendText = sendText + result4+ "\r"
sendMessage(sendText)
if scriptPrint: # Called with display request: send to stdout
print("Host Name: " + Uname)
print(result1)
print(result2)
print(result3)
print(result4)
def getTemperature():
cpuTemp = int(CPUTemperature().temperature)
Ctemp = "CPU Temperature: " + str(cpuTemp) + Degrees
if cpuTemp > CritCPUTemp:
sendText = "CRITICAL ALARM FROM HOST " + Uname + "!\r\nALERT: Critical temperature " + str(Ctemp) + ".\r\nShutting system down...\r"
sendMessage(sendText)
sleep(10)
subprocess.run(["shutdown", "-h", "0"])
elif cpuTemp > HighCPUTemp:
sendText = "Alarm From Host " + Uname + "!\r\nWarning: High temperature " + str(Ctemp) + ".\r"
sendMessage(sendText)
return Ctemp
def getCPU():
cpuPercent = int(psutil.cpu_percent(1))
Cusage = "CPU Usage: " + str(cpuPercent) + "%"
if cpuPercent > HighCPUUsage:
# Sending alert on high cpu usage."
sendText = "Alert From HOST " + Uname + "!\r\nWarning: High CPU Utilization " + str(cpuPercent) + "%\r"
sendMessage(sendText)
return Cusage
def getDiskUsage():
for dp in psutil.disk_partitions():
diskUsagePercent = int(psutil.disk_usage(dp.mountpoint).percent)
diskPercent = "Disk Usage: " + str(diskUsagePercent) + "%"
if (diskUsagePercent > HighDiskUsage):
sendText = "Warning From Host " + Uname + "!\r\nWarning: High Disk Usage " + str(diskUsagePercent) + "%.\r"
sendMessage(sendText)
return diskPercent
def getMemUsage():
memUsagePercent = int(psutil.virtual_memory().percent)
if (memUsagePercent > HighMemUsage):
sendText = "Alert From Host " + Uname + "!\r\nWarning: High Memory Usage " + str(memUsagePercent) + "%.\r"
sendMessage(alertMsg)
memUse = "Memory Usage: " +str(memUsagePercent) + "%"
return memUse
def getPower():
if not Fuse:
if not Power:
Text = "Main power failure. Shutdown will occur shortly."
else:
Text = "Fuse failure."
SendMessage(Text)
pi_status()
Quote from: lrhorer on January 15, 2025, 03:16:51 PMFPP is indeed using the pin, as expected. The problem is, I still need to be able to scan the state of the pin in the external script. The script needs to run on the falling edge of the pin, but it also needs to examine the pin whether nor not it has been called by FPP. It runs under various situations, including when FPP calls it, as well, and it needs to know the status of the pin whether it has been called by FPP or not.Personally, I would use node-red instead of a script and have FPP issue a MQTT status when the pin is pressed and let node-red do all the logic including calling back to FPP's API to cause FPP to do things. This comes with the added bonus of a visual workflow rather than having to re-read/learn the script each time to troubleshoot or modify it.
FPP 8.4 released!
by lrhorer
Today at 11:30:42 AM |
Swapped PiCap V1 with V2 - Pixels will not light in test
by twseeman
Today at 10:24:13 AM |
Does the Falcon PiCap v2 support Renard Output?
by dakingus
January 18, 2025, 05:45:25 PM |
K2-Pi-Servo
by breese
January 17, 2025, 01:47:06 PM |
Big button url question
by darylc
January 14, 2025, 05:54:32 PM |
Display TEXT to LED Panels form REST API
by CaptainMurdoch
January 14, 2025, 11:55:25 AM |
Differential Board: PSU & Enclosure
by jnealand
January 14, 2025, 07:42:55 AM |
wine from matrix with octoscroller control
by Poporacer
January 12, 2025, 10:40:05 AM |
xLights.org forum registration waiting for approval for several months.
by darylc
January 11, 2025, 12:42:54 AM |
FPP sequence fade
by CaptainMurdoch
January 10, 2025, 08:19:33 AM |
Page created in 0.025 seconds with 33 queries.