Last active
February 4, 2016 06:53
-
-
Save tlrobinson/be33a33123d6403ae3d6 to your computer and use it in GitHub Desktop.
One Fast Cat wheel + switch + C.H.I.P.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh | |
set -e | |
# Must be a valid filename | |
NAME=fastcat | |
PIDFILE=/var/run/$NAME.pid | |
#This is the command to be run, give the full pathname | |
DAEMON=/home/root/fastcat.sh | |
DAEMON_OPTS="" | |
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" | |
case "$1" in | |
start) | |
echo -n "Starting daemon: "$NAME | |
start-stop-daemon --start -b --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS | |
echo "." | |
;; | |
stop) | |
echo -n "Stopping daemon: "$NAME | |
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE | |
echo "." | |
;; | |
restart) | |
echo -n "Restarting daemon: "$NAME | |
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE | |
start-stop-daemon --start -b --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS | |
echo "." | |
;; | |
*) | |
echo "Usage: "$1" {start|stop|restart}" | |
exit 1 | |
esac | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sh -c 'echo 415 > /sys/class/gpio/export' | |
t1="$(awk 'NR==3 {print $3}' /proc/timer_list)" | |
while true; do | |
v1=$(cat /sys/class/gpio/gpio415/value) | |
if [ "$v1" = 0 ] && [ "$v2" = 1 ]; then | |
t2="$(awk 'NR==3 {print $3}' /proc/timer_list)" | |
timestamp="$(date +%s)" | |
elapsed="$(expr "(" "$t2" - "$t1" ")" / 1000000)" | |
echo "$timestamp\t$elapsed" >> fastcat.log | |
wget -qO- --no-check-certificate "https://tonicdev.io/user/notebook/branches/master?timestamp=$timestamp&elapsed=$elapsed" & | |
t1="$t2" | |
fi | |
v2=$v1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pg = require("pg"); | |
var config = { | |
user: "USER", | |
password: "PASSWORD", | |
database: "DATABASE", | |
host: "HOST", | |
port: 5432, | |
ssl: true | |
}; | |
exports.tonicEndpoint = function(request, response) { | |
var url = require('url').parse(request.url, true); | |
var timestamp = parseInt(url.query.timestamp, 0); | |
var elapsed = parseInt(url.query.elapsed, 0); | |
pg.connect(config, function(err, client, done) { | |
if(err) { | |
return response.end(JSON.stringify({ error: 'error fetching client from pool' })); | |
} | |
client.query('INSERT INTO cat_wheel VALUES ($1, $2)', [timestamp, elapsed], function(err, result) { | |
//call `done()` to release the client back to the pool | |
done(); | |
if(err) { | |
return response.end(JSON.stringify({ error: 'error running query: ' + err })); | |
} | |
response.end(JSON.stringify({ elapsed, timestamp })); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment