-
-
Save fvdbosch/8762ad8b3402baa9e825e1e9c264e8b7 to your computer and use it in GitHub Desktop.
Using Particle for Raspberry Pi to create a local and remote temperature warning.
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
// Define variables | |
Process proc; | |
float cpuTemp; | |
long lastExecution; | |
void setup() { | |
// Initialise variables | |
cpuTemp = 0; | |
lastExecution = 0; | |
} | |
void loop() { | |
// Measure the CPU temperature | |
proc = Process::run("cat /sys/class/thermal/thermal_zone0/temp"); | |
proc.wait(); | |
// Parse command response | |
cpuTemp = proc.out().parseFloat(); | |
// If higher than 60'C | |
if(cpuTemp > 60000) { | |
// Blink LEDs | |
blink(); | |
// Only trigger notification every 10 minutes | |
if(millis() - lastExecution > 10*60*1000) { | |
// Publish temperature, triggering IFTTT applet | |
Particle.publish("cpu_temp", String(int(cpuTemp/1000))); | |
lastExecution = millis(); | |
} | |
} | |
} | |
void blink() { | |
// Set Blinkt to RED for 500ms | |
proc = Process::run("/home/pi/Pimoroni/blinkt/examples/rgb.py 255 0 0"); | |
proc.wait(); | |
delay(500); | |
// Set Blinkt to OFF for 500ms | |
proc = Process::run("/home/pi/Pimoroni/blinkt/examples/rgb.py 0 0 0"); | |
proc.wait(); | |
delay(500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment