Raspberry Pi Automation
Since we have no network access on the road:
timedatectl set-ntp false
control the gpio pins from the shell just by echoing numbers to the file system
Here's a handy bash script for turning on pin(s). Name gpon, in /usr/local/bin, and chmod u+x gpon
#!/bin/bash
if [ ! -e /sys/class/gpio/gpio$1 ]; then
echo "$1" > /sys/class/gpio/export
sleep .25
fi
if [ `cat /sys/class/gpio/gpio$1/direction` != "out" ]; then
echo "out" > /sys/class/gpio/gpio$1/direction
fi
echo "1" > /sys/class/gpio/gpio$1/value
if ! [ -z "$2" ]; then
shift
gpon $@
fi
Setting up a webserver and PHP
Adding a clock for keeping time while the pi is off. Note the website is junk, no schematics anywhere for the plug-in version we bought. But fyi it plugs in flush with the 5v and 3.3v pins. The plug is passthru so you could connect more to the 5v and 3.3v pins. The guide is also wrong on how to enable i2c - it's under boot. Them the first time I query the clock I get the error "hwclock: ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument". Running sudo hwclock --show twice seems to solve the problem, or running hwclock --systohc (caution: resets the hw clock to the current system clock) .
Here's a handy bash script for turning on pin(s). Name gpon, in /usr/local/bin, and chmod u+x gpon
#!/bin/bash
if [ ! -e /sys/class/gpio/gpio$1 ]; then
echo "$1" > /sys/class/gpio/export
sleep .25
fi
if [ `cat /sys/class/gpio/gpio$1/direction` != "out" ]; then
echo "out" > /sys/class/gpio/gpio$1/direction
fi
echo "1" > /sys/class/gpio/gpio$1/value
if ! [ -z "$2" ]; then
shift
gpon $@
fi
likewise, gpoff:
#!/bin/bash
if [ ! -e /sys/class/gpio/gpio$1 ]; then
echo "$1" > /sys/class/gpio/export
sleep .25
fi
if [ `cat /sys/class/gpio/gpio$1/direction` != "out" ]; then
echo "out" > /sys/class/gpio/gpio$1/direction
fi
echo "0" > /sys/class/gpio/gpio$1/value
if ! [ -z "$2" ]; then
shift
gpoff $@
fi
if [ ! -e /sys/class/gpio/gpio$1 ]; then
echo "$1" > /sys/class/gpio/export
sleep .25
fi
if [ `cat /sys/class/gpio/gpio$1/direction` != "out" ]; then
echo "out" > /sys/class/gpio/gpio$1/direction
fi
echo "0" > /sys/class/gpio/gpio$1/value
if ! [ -z "$2" ]; then
shift
gpoff $@
fi
If timing is important, you can do the exporting at boot.
#!/bin/bash
echo "14" > /sys/class/gpio/export
echo "15" > /sys/class/gpio/export
echo "18" > /sys/class/gpio/export
(etc.)
place in /user/local/bin/autoexec and then crontab -e, adding @reboot autoexec on a line by itself.
Setting up a webserver and PHP
Adding a clock for keeping time while the pi is off. Note the website is junk, no schematics anywhere for the plug-in version we bought. But fyi it plugs in flush with the 5v and 3.3v pins. The plug is passthru so you could connect more to the 5v and 3.3v pins. The guide is also wrong on how to enable i2c - it's under boot. Them the first time I query the clock I get the error "hwclock: ioctl(RTC_RD_TIME) to /dev/rtc to read the time failed: Invalid argument". Running sudo hwclock --show twice seems to solve the problem, or running hwclock --systohc (caution: resets the hw clock to the current system clock) .
Comments