A Banana Pro Weather Logger
scripts I haven't mentioned yet but should.
I use wicd to manage my wireless connection. It will run any script found in the directory /etc/wicd/scripts/postconnect after it has first established an internet connection. Network Manager has a similar functonality. The first thing startup.sh does is set the system time. Next it will set TIP_COUNT to 0 for the initial logging period and finally it will run wl_jobs -u to power up the weather-logger circuit.
#!/bin/bash ################################################ # RM20190425 # /etc/wicd/scripts/postconnect/startup.sh # Required to set time after connecting to # the internet. Only after correct date/time # is set can the weather data logger script # be run. ################################################ # Config file . /etc/weather-logger.conf # # Set system time for session. ntpdate pool.ntp.org # # Set the file /tmp/tip-count to 0 at startup. # the script /usr/local/bin/weather-logger.sh # will re-set it to 0 again after it updates data. /usr/bin/echo 0 >> $TIP_COUNT # # Power up circuit board and green LED /usr/local/bin/wl_jobs -u
I want wl_jobs -s to run at start up in order to monitor GPIO pins 2 and 3. So I'll add that command to /etc/rc.d/rc.local
#!/bin/sh # # /etc/rc.d/rc.local: Local system initialization script. # # Put any local startup commands in here. Also, if you have # anything that needs to be run at shutdown time you can # make an /etc/rc.d/rc.local_shutdown script and put those # commands in there. # # i2c_dev.ko is not automaically loaded at boot so do it here. /sbin/modprobe i2c_dev # # Run an instance of wl_jobs -s in order to monitor shutdown # button and the tip count switch used to monitor rain gauge # bucket tips. /usr/local/bin/wl_jobs -s &
The script is run as a system call by wl_jobs every time a bucket tip is detected on GPIO pin 2.
#!/bin/bash ############################################################ # /usr/local/bin/count-tips.sh RM20190503 # # This script increments the file /tmp/tip-count by one # but requires an initial value of 0 in /tmp/tip-count # to be provided at start up and again after each 15 # minute data query ############################################################ # Config file . /etc/weather-logger.conf temp_count=$(cat $TIP_COUNT) count=$(echo "$temp_count + 1" | bc ) echo "$count" > $TIP_COUNT