Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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