Skip to content

Instantly share code, notes, and snippets.

@fvdbosch
Last active December 3, 2016 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvdbosch/8762ad8b3402baa9e825e1e9c264e8b7 to your computer and use it in GitHub Desktop.
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.
// 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