113: Better Breadboard? See post 62 at http://dicks-photon-arduino.blogspot.com/
Just pie-in-the-sky, of course.
Topics I'm Exploring: Pi/Arduino/Photon Sensors: Temperature, PIR motion, Photocell; Devices: Darlington array, I2C, MCP23008, MCP3008 (analog input), Pi Camera, Opto-isolated relays, A variety of motors, Programming in Shell, C, Python, Using crontab, Security camera app, Farming/Gardening Apps, Unifying Pi software structure, Pi access and control from the Internet, Wireless device control.
while true ;
do
a=`/opt/vc/bin/vcgencmd measure_temp` # returns Celsius
b=`expr "$a" : '.*=\([0-9][0-9]*\)'`
if [ $b -gt "70" ] ; # 160F
then
echo 'CPU HOT!' | mail -s 'DicksRpi4-HOT' myemail@gmail.com
sudo halt # NOTE: have to restrart manually
fi
if [ $b -lt "55" ] ; # 130F
then
sleep 300 # sleep longer if under 130F
else
sleep 60
fi
done
===============
Also, I changed the Particle code, mainly to add a delay inside the loop function. Plus I got rid of most of the C++ crap.
// Danger! This thing is running as super-user (root)
#include <stdio.h>
#include <unistd.h>
#define SAFE_UID 1000 // i.e., the "pi" user built into RPi Linux
#define MY_PATH "/home/pi"
char Rstr[100];
int Ct = 0;
void setup() {
Particle.variable("dhpi1v", Rstr, STRING);
Particle.function("dhpi1f", pifunc);
}
void loop() {
delay(10); // kludge to keep the empty loop from being a cpu hog
}
int pifunc(String cmd) {
int arg = cmd.toInt();
char file[100];
FILE *fp;
++Ct;
sprintf(Rstr, "Call count = %d, Arg = %d\n", Ct, arg);
sprintf(file, "%s/pi_out.txt", MY_PATH);
fp = fopen(file, "w");
fputs(Rstr, fp);
fclose(fp);
chown(file, SAFE_UID, SAFE_UID); // otherwise belongs to root
return Ct;
}
The delay(10) was supposed to reduce CPU load to about "1%" but my tests show 12%.
Before I added the delay statement particle-agent was raising my RPi's temperature about 1C every
3 minutes. Maybe I need heat sinks (I had some but can't find the tiny package). And maybe when an RPi gets too hot it halts by itself.
Anyone know?