From c7744cd947c8cc07a1af95b13368a014fb945a5d Mon Sep 17 00:00:00 2001 From: John O'Hare Date: Sun, 30 Jul 2017 10:45:20 +0100 Subject: [PATCH 1/6] Test return code of exec 3 In some instances failure to open has caused the printf output to appear in other processes. --- burl | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/burl b/burl index fc83a41..bcf3d0a 100755 --- a/burl +++ b/burl @@ -14,29 +14,33 @@ burl() { [[ $path == $host ]] && path="" - exec 3<>/dev/tcp/${host}/${HTTP_PORT} + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then - printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 + printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 - IFS= - while read -r -t 1 line 0<&3; do - line=${line//$'\r'} + IFS= + while read -r -t 1 line 0<&3; do + line=${line//$'\r'} - if [[ ! -v headers_read && $INCLUDE_HEADERS -eq 0 ]]; then - [[ -z $line ]] && headers_read=yes - continue - fi + if [[ ! -v headers_read && $INCLUDE_HEADERS -eq 0 ]]; then + [[ -z $line ]] && headers_read=yes + continue + fi - echo "$line" - done + echo "$line" + done - exec 3<&- + exec 3<&- + else + exec 3<&- + echo "`date "+%d/%m/%Y %X"` unable to connect: $host:$HTTP_PORT/${path}" 1>&2 + exit 1 + fi } usage() { cat < Date: Sun, 30 Jul 2017 21:16:35 +0100 Subject: [PATCH 2/6] Tidy up --- burl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/burl b/burl index bcf3d0a..4863c37 100755 --- a/burl +++ b/burl @@ -14,10 +14,8 @@ burl() { [[ $path == $host ]] && path="" - if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then - + if [ exec 3<>/dev/tcp/${host}/${HTTP_PORT} ]; then printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 - IFS= while read -r -t 1 line 0<&3; do line=${line//$'\r'} From 705751a70ba43a2d43670429d6f498a3d7cc3313 Mon Sep 17 00:00:00 2001 From: John O'Hare Date: Sun, 30 Jul 2017 21:26:13 +0100 Subject: [PATCH 3/6] Square bracket issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I am unable to use [[ … ]] as you request. --- burl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/burl b/burl index 4863c37..6e11569 100755 --- a/burl +++ b/burl @@ -14,7 +14,7 @@ burl() { [[ $path == $host ]] && path="" - if [ exec 3<>/dev/tcp/${host}/${HTTP_PORT} ]; then + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 IFS= while read -r -t 1 line 0<&3; do From 69173bfd4b58344027e402abeab7a4ee030230b4 Mon Sep 17 00:00:00 2001 From: John O'Hare Date: Sun, 3 Sep 2017 12:39:06 +0100 Subject: [PATCH 4/6] Report to an error file --- burl | 1 + 1 file changed, 1 insertion(+) diff --git a/burl b/burl index 6e11569..ed3531f 100755 --- a/burl +++ b/burl @@ -32,6 +32,7 @@ burl() { else exec 3<&- echo "`date "+%d/%m/%Y %X"` unable to connect: $host:$HTTP_PORT/${path}" 1>&2 + echo "`date "+%d/%m/%Y %X"` unable to connect: $host:$HTTP_PORT/${path}" 1>>burl.err exit 1 fi } From 50fd2435efb08da51604369b5d13b15bd183c25b Mon Sep 17 00:00:00 2001 From: John O'Hare Date: Sun, 3 Sep 2017 12:48:05 +0100 Subject: [PATCH 5/6] Tweak Also add post bash script. A lighter than burl when no response is required. --- burl | 14 ++++++++++-- post | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) mode change 100755 => 100644 burl create mode 100644 post diff --git a/burl b/burl old mode 100755 new mode 100644 index ed3531f..eabf91d --- a/burl +++ b/burl @@ -14,12 +14,23 @@ burl() { [[ $path == $host ]] && path="" + counter=0; + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 IFS= while read -r -t 1 line 0<&3; do + let counter++ line=${line//$'\r'} - + +# if [ "$counter" == "1" ]; then +# if [ "${line:0:12}" == "HTTP/1.1 200" ]; then +# break +# else +# echo "burl: $host:$HTTP_PORT/${path} ${line:0:12}" 1>&2 +# echo "`date "+%d/%m/%Y %X"` $host:$HTTP_PORT/${path} ${line:0:12}" 1>> burl.err +# fi +# fi if [[ ! -v headers_read && $INCLUDE_HEADERS -eq 0 ]]; then [[ -z $line ]] && headers_read=yes continue @@ -27,7 +38,6 @@ burl() { echo "$line" done - exec 3<&- else exec 3<&- diff --git a/post b/post new file mode 100644 index 0000000..430220b --- /dev/null +++ b/post @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +HTTP_PORT=80 + +post() { + shopt -s extquote + + export LC_ALL=C + unset headers_read + + host=${1%%/*} + path=${1#*/} + + [[ $path == $host ]] && path="" + + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then + printf "POST /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 + IFS= + while read -r -t 1 line 0<&3; do + if [ "${line:0:12}" == "HTTP/1.1 200" ]; then + break + else + echo "post: $host:$HTTP_PORT/${path} ${line:0:12}" 1>&2 + echo "`date "+%d/%m/%Y %X"` $host:$HTTP_PORT/${path} ${line:0:12}" 1>> post.err + exit 1 + fi + done + exec 3<&- + else + exec 3<&- + echo "`date "+%d/%m/%Y %X"` unable to connect: $host:$HTTP_PORT/${path}" 1>&2 + echo "`date "+%d/%m/%Y %X"` unable to connect: $host:$HTTP_PORT/${path}" 1>>post.err + exit 1 + fi +} + +usage() { + cat < use alternative port number (default: 80) +EOF +} + +if [[ $# -eq 0 ]]; then + usage + exit 1 +fi + +while getopts 'hip:' option; do + case "$option" in + h) + usage + exit 0 + ;; + + p) + HTTP_PORT=$OPTARG + ;; + + *) + usage + exit 1 + ;; + esac +done +shift $(( $OPTIND - 1)) + +post ${1/http:\/\/} + From 1260a03fe8bd317ae15161097e59007627cbb134 Mon Sep 17 00:00:00 2001 From: John O'Hare Date: Fri, 25 Jan 2019 11:02:00 +0000 Subject: [PATCH 6/6] Backup scripts --- Bash Scripts/ChkTemp.sh | 22 ++++ Bash Scripts/Jee18.sh | 94 ++++++++++++++++ Bash Scripts/Jee19.sh | 93 ++++++++++++++++ Bash Scripts/Jee20.sh | 93 ++++++++++++++++ Bash Scripts/JeeActivity.sh | 17 +++ Bash Scripts/JeeCentralMonitor-MK1.sh | 78 ++++++++++++++ Bash Scripts/JeeCentralMonitor.sh | 149 ++++++++++++++++++++++++++ Bash Scripts/JeeCentralTest.sh | 89 +++++++++++++++ Bash Scripts/JeeElec.sh | 12 +++ Bash Scripts/JeeGasCounterDecoder.sh | 138 ++++++++++++++++++++++++ Bash Scripts/JeeGraphGas.sh | 20 ++++ Bash Scripts/JeePowerSneakDecoder.sh | 29 +++++ Bash Scripts/JeeRoomNodeDecoder.sh | 74 +++++++++++++ Bash Scripts/JeeTempDecoder.sh | 59 ++++++++++ Bash Scripts/Outside.sh | 51 +++++++++ Bash Scripts/RFxConsole.sh | 21 ++++ Bash Scripts/RasPi-Console.sh | 88 +++++++++++++++ Bash Scripts/Xrestart.sh | 37 +++++++ Bash Scripts/burl | 80 ++++++++++++++ Bash Scripts/fbtunnel.sh | 3 + Bash Scripts/heating.sh | 20 ++++ Bash Scripts/heating_OFF.sh | 20 ++++ Bash Scripts/heating_ON.sh | 20 ++++ Bash Scripts/jee | 13 +++ Bash Scripts/jeebash-old.sh | 144 +++++++++++++++++++++++++ Bash Scripts/jeebash.sh | 136 +++++++++++++++++++++++ Bash Scripts/log | 7 ++ Bash Scripts/post | 71 ++++++++++++ Bash Scripts/reboot.sh | 36 +++++++ Bash Scripts/restart.sh | 40 +++++++ Bash Scripts/rx.sh | 56 ++++++++++ Bash Scripts/rx_threshold.sh | 25 +++++ Bash Scripts/tx-old.sh | 32 ++++++ Bash Scripts/tx.sh | 37 +++++++ 34 files changed, 1904 insertions(+) create mode 100755 Bash Scripts/ChkTemp.sh create mode 100755 Bash Scripts/Jee18.sh create mode 100755 Bash Scripts/Jee19.sh create mode 100755 Bash Scripts/Jee20.sh create mode 100755 Bash Scripts/JeeActivity.sh create mode 100755 Bash Scripts/JeeCentralMonitor-MK1.sh create mode 100755 Bash Scripts/JeeCentralMonitor.sh create mode 100755 Bash Scripts/JeeCentralTest.sh create mode 100755 Bash Scripts/JeeElec.sh create mode 100755 Bash Scripts/JeeGasCounterDecoder.sh create mode 100755 Bash Scripts/JeeGraphGas.sh create mode 100755 Bash Scripts/JeePowerSneakDecoder.sh create mode 100755 Bash Scripts/JeeRoomNodeDecoder.sh create mode 100755 Bash Scripts/JeeTempDecoder.sh create mode 100755 Bash Scripts/Outside.sh create mode 100755 Bash Scripts/RFxConsole.sh create mode 100755 Bash Scripts/RasPi-Console.sh create mode 100755 Bash Scripts/Xrestart.sh create mode 100644 Bash Scripts/burl create mode 100755 Bash Scripts/fbtunnel.sh create mode 100755 Bash Scripts/heating.sh create mode 100755 Bash Scripts/heating_OFF.sh create mode 100755 Bash Scripts/heating_ON.sh create mode 100644 Bash Scripts/jee create mode 100755 Bash Scripts/jeebash-old.sh create mode 100755 Bash Scripts/jeebash.sh create mode 100644 Bash Scripts/log create mode 100644 Bash Scripts/post create mode 100755 Bash Scripts/reboot.sh create mode 100755 Bash Scripts/restart.sh create mode 100755 Bash Scripts/rx.sh create mode 100755 Bash Scripts/rx_threshold.sh create mode 100755 Bash Scripts/tx-old.sh create mode 100755 Bash Scripts/tx.sh diff --git a/Bash Scripts/ChkTemp.sh b/Bash Scripts/ChkTemp.sh new file mode 100755 index 0000000..1d437dc --- /dev/null +++ b/Bash Scripts/ChkTemp.sh @@ -0,0 +1,22 @@ +#!/bin/bash +/usr/bin/tail -n1 /etc/heyu/JeeTempDecoder.dat > /tmp/JeeTempDecoder.dat +read date time node command x y type seq goodFloor badFloor failNoiseCount rxRssi temperature voltage < /tmp/JeeTempDecoder.dat +if [ "$temperature" -le "400" ]; then +let "t = $temperature / 100" +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +#From: RasPi1-2 +Date: `date` +Subject: RasPi1-2: Sandhurst Temperature is < $t°C on `date -R` +Body: +/etc/heyu/JeeGasCounterDecoder.dat +---------------------------------- +`tail /etc/heyu/JeeTempDecoder.dat` +---------------------------------- +/etc/heyu/JeeRoomNodeDecoder.dat +---------------------------------- +`tail /etc/heyu/JeeRoomNodeDecoder.dat` +---------------------------------- + +EOF +fi diff --git a/Bash Scripts/Jee18.sh b/Bash Scripts/Jee18.sh new file mode 100755 index 0000000..76a9a24 --- /dev/null +++ b/Bash Scripts/Jee18.sh @@ -0,0 +1,94 @@ +#!/bin/bash +# Garden Shed +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/Jee18-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +yymmdd=`date "+%Y%m%d"` +/usr/bin/tail -n1 /etc/heyu/Jee18.dat > /tmp/Jee18.dat # /tmp is a ram disk on RPi +read date time node light movement humidity temp < /tmp/Jee18.dat # Read back last data stored +if [ "${yymmdd:6:2}" != "${date:8:2}" ] + then + mv /etc/heyu/Jee18.dat /etc/heyu/archive/Jee18-${date:0:4}${date:5:2}${date:8:2}.dat + touch /etc/heyu/Jee18.dat + mv /etc/heyu/Jee18.skipped /etc/heyu/archive/Jee18-${date:0:4}${date:5:2}${date:8:2}.skipped + touch /etc/heyu/Jee18.skipped +fi +#echo `date "+%Y/%m/%d %X"` $@ >> ./JeeRoomNodeDecoder.txt + args=("$@") # Assign to array +# args0 1 2 3 4 5 6 7 8 9 10 +# OK 19 0 0 0 6 0 54 133 16 170 85 12 (71dB) +#struct { //0 Offset, node # +# byte command; //1 ACK command return field +# byte missedACK :4; //2 +# byte attempts :4; //2 Transmission attempts +# byte count :4; //3 Packet count +# byte moved :1; //3 motion detector: 0..1 +# byte lobat :1; //3 supply voltage dropped under 3.1V: 0..1 +# byte spare2 :2; //3 +#if BME280_PORT +# uint32_t pressure:24; //4&5&6 +#endif +# byte light; //7 light sensor: 0..255 +# unsigned int humi:16; //8&9 humidity: 0..100.00 +# int temp :16; //10&11 temperature: -5000..+5000 (hundredths) +#} payload; +# +# RoomNode +# 19 0 15 0 87 140 1 0 87 2 185 8 115 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 +# + +let "node = ${args[0]}" # Get node number +#let "node = $node & 31" # strip ack/dst/ctl flags + +let "command = ${args[1]}" # Get command byte + +let "attempts = ${args[2]} >> 4" +let "missedACK = ${args[2]} & 15" + +let "movement = ${args[3]} & 128" +let "battery = ${args[3]} & 64" + +let "count = ${args[3]}" +#let "count = $count >> 1" +#echo "Count10=$count" + +let "pressure = ${args[6]} << 8" +let "pressure = $pressure + ${args[5]}" +let "pressure = $pressure << 8" +let "pressure = $pressure + ${args[4]}" + +let "light = ${args[7]}" + +let "humidity = ${args[9]} << 8" +let "humidity = $humidity + ${args[8]}" +# +let "temp = ${args[11]} << 8" +let "temp = temp + ${args[10]}" +let temp=$(($temp<<48)); let temp=$(($temp>>48)) # Preserve signed number +# +# 149 == 4.06v +# 108 is minimum that node stays active ~ 2.7v +let "vcc = ${args[12]}" +# +echo $temp $humidity $pressure $vcc > /tmp/Jee18-BME280.temp +#cp /tmp/BME280.temp /tmp/BME280.roomNode +# +echo `date "+%Y/%m/%d %X"` $node $light $command $attempts $missedACK $count $movement $battery $pressure $humidity $temp $vcc >> /etc/heyu/Jee18.dat +# +#post "http://api.thingspeak.com/update?key=AG0FOXOMBA68DDOR&field1=$light&field2=$movement&field3=$humidity&field4=$temp&field5=$battery" + +if [[ $vcc -le 90 ]]; + then + who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'"Low Battery Node $node $vcc" > /dev/$pty; done +fi + +else + echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/Jee18.skipped +################################################################# +rm -rf "${LOCKDIR}" +fi +################################################################# + diff --git a/Bash Scripts/Jee19.sh b/Bash Scripts/Jee19.sh new file mode 100755 index 0000000..be07880 --- /dev/null +++ b/Bash Scripts/Jee19.sh @@ -0,0 +1,93 @@ +#!/bin/bash +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/Jee19-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +yymmdd=`date "+%Y%m%d"` +/usr/bin/tail -n1 /etc/heyu/Jee19.dat > /tmp/Jee19.dat # /tmp is a ram disk on RPi +read date time node light movement humidity temp < /tmp/Jee19.dat # Read back last data stored +if [ "${yymmdd:6:2}" -ne "${date:8:2}" ] + then + mv /etc/heyu/Jee19.dat /etc/heyu/archive/Jee19-${date:0:4}${date:5:2}${date:8:2}.dat + touch /etc/heyu/Jee19.dat + mv /etc/heyu/Jee19.skipped /etc/heyu/archive/Jee19-${date:0:4}${date:5:2}${date:8:2}.skipped + touch /etc/heyu/Jee19.skipped +fi +#echo `date "+%Y/%m/%d %X"` $@ >> ./JeeRoomNodeDecoder.txt + args=("$@") # Assign to array +# args0 1 2 3 4 5 6 7 8 9 10 +# OK 19 0 0 0 6 0 54 133 16 170 85 12 (71dB) +#struct { //0 Offset, node # +# byte command; //1 ACK command return field +# byte missedACK :4; //2 +# byte attempts :4; //2 Transmission attempts +# byte count :4; //3 Packet count +# byte moved :1; //3 motion detector: 0..1 +# byte lobat :1; //3 supply voltage dropped under 3.1V: 0..1 +# byte spare2 :2; //3 +#if BME280_PORT +# uint32_t pressure:24; //4&5&6 +#endif +# byte light; //7 light sensor: 0..255 +# unsigned int humi:16; //8&9 humidity: 0..100.00 +# int temp :16; //10&11 temperature: -5000..+5000 (hundredths) +#} payload; +# +# RoomNode +# 19 0 15 0 87 140 1 0 87 2 185 8 115 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 +# + +let "node = ${args[0]}" # Get node number +#let "node = $node & 31" # strip ack/dst/ctl flags + +let "command = ${args[1]}" # Get command byte + +let "attempts = ${args[2]} >> 4" +let "missedACK = ${args[2]} & 15" + +let "movement = ${args[3]} & 8" +let "battery = ${args[3]} & 4" + +let "count = ${args[3]}" +#let "count = $count >> 1" +#echo "Count10=$count" + +let "pressure = ${args[6]} << 8" +let "pressure = $pressure + ${args[5]}" +let "pressure = $pressure << 8" +let "pressure = $pressure + ${args[4]}" + +let "light = ${args[7]}" + +let "humidity = ${args[9]} << 8" +let "humidity = $humidity + ${args[8]}" +# +let "temp = ${args[11]} << 8" +let "temp = $temp + ${args[10]}" +let temp=$(($temp<<48)); let temp=$(($temp>>48)) # Preserve signed number +# +# 149 == 4.06v +# 108 is minimum that node stays active ~ 2.7v +let "vcc = ${args[12]}" +# +echo $temp $humidity $pressure $vcc > /tmp/BME280.temp +echo $temp $humidity $pressure $vcc >/tmp/BME280.roomNode +# +echo `date "+%Y/%m/%d %X"` $node $light $command $attempts $missedACK $count $movement $battery $pressure $humidity $temp $vcc >> /etc/heyu/Jee19.dat +# +#post "http://api.thingspeak.com/update?key=AG0FOXOMBA68DDOR&field1=$light&field2=$movement&field3=$humidity&field4=$temp&field5=$battery" + +if [[ $vcc -le 110 ]]; + then + who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'"Low Battery Node $node $vcc" > /dev/$pty; done +fi + +else + echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/Jee19.skipped +################################################################# +rm -rf "${LOCKDIR}" +fi +################################################################# + diff --git a/Bash Scripts/Jee20.sh b/Bash Scripts/Jee20.sh new file mode 100755 index 0000000..d87b14d --- /dev/null +++ b/Bash Scripts/Jee20.sh @@ -0,0 +1,93 @@ +#!/bin/bash +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/Jee18-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +yymmdd=`date "+%Y%m%d"` +#/usr/bin/tail -n1 /etc/heyu/Jee18.dat > /tmp/Jee18.dat # /tmp is a ram disk on RPi +#read date time node light movement humidity temp < /tmp/Jee18.dat # Read back last data stored +if [ "${yymmdd:6:2}" -ne "${date:8:2}" ] + then + mv /etc/heyu/Jee18.dat /etc/heyu/archive/Jee18-${date:0:4}${date:5:2}${date:8:2}.dat + touch /etc/heyu/Jee18.dat + mv /etc/heyu/Jee18.skipped /etc/heyu/archive/Jee18-${date:0:4}${date:5:2}${date:8:2}.skipped + touch /etc/heyu/Jee18.skipped +fi +#echo `date "+%Y/%m/%d %X"` $@ >> ./JeeRoomNodeDecoder.txt + args=("$@") # Assign to array +# args0 1 2 3 4 5 6 7 8 9 10 +# OK 19 0 0 0 6 0 54 133 16 170 85 12 (71dB) +#struct { //0 Offset, node # +# byte command; //1 ACK command return field +# byte missedACK :4; //2 +# byte attempts :4; //2 Transmission attempts +# byte count :4; //3 Packet count +# byte moved :1; //3 motion detector: 0..1 +# byte lobat :1; //3 supply voltage dropped under 3.1V: 0..1 +# byte spare2 :2; //3 +#if BME280_PORT +# uint32_t pressure:24; //4&5&6 +#endif +# byte light; //7 light sensor: 0..255 +# unsigned int humi:16; //8&9 humidity: 0..100.00 +# int temp :16; //10&11 temperature: -5000..+5000 (hundredths) +#} payload; +# +# RoomNode +# 19 0 15 0 87 140 1 0 87 2 185 8 115 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 +# + +let "node = ${args[0]}" # Get node number +#let "node = $node & 31" # strip ack/dst/ctl flags + +let "command = ${args[1]}" # Get command byte + +let "attempts = ${args[2]} >> 4" +let "missedACK = ${args[2]} & 15" + +let "movement = ${args[3]} & 8" +let "battery = ${args[3]} & 4" + +let "count = ${args[3]}" +#let "count = $count >> 1" +#echo "Count10=$count" + +let "pressure = ${args[6]} << 8" +let "pressure = $pressure + ${args[5]}" +let "pressure = $pressure << 8" +let "pressure = $pressure + ${args[4]}" + +let "light = ${args[7]}" + +let "humidity = ${args[9]} << 8" +let "humidity = $humidity + ${args[8]}" +# +let "temp = ${args[11]} << 8" +let "temp = $temp + ${args[10]}" +let temp=$(($temp<<48)); let temp=$(($temp>>48)) # Preserve signed number +# +# 149 == 4.06v +# 108 is minimum that node stays active ~ 2.7v +let "vcc = ${args[12]}" +# +echo $temp $humidity $pressure $vcc > /tmp/Jee18-BME280.temp +#cp /tmp/BME280.temp /tmp/BME280.roomNode +# +echo `date "+%Y/%m/%d %X"` $node $light $command $attempts $missedACK $count $movement $battery $pressure $humidity $temp $vcc >> /etc/heyu/Jee18.dat +# +#post "http://api.thingspeak.com/update?key=AG0FOXOMBA68DDOR&field1=$light&field2=$movement&field3=$humidity&field4=$temp&field5=$battery" + +if [[ $vcc -le 110 ]]; + then + who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'"Low Battery Node $node $vcc" > /dev/$pty; done +fi + +else + echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/Jee18.skipped +################################################################# +rm -rf "${LOCKDIR}" +fi +################################################################# + diff --git a/Bash Scripts/JeeActivity.sh b/Bash Scripts/JeeActivity.sh new file mode 100755 index 0000000..b529189 --- /dev/null +++ b/Bash Scripts/JeeActivity.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [ -f /tmp/seconds ] ; + then + read lastLtime < /tmp/seconds + let "thisLtime = `date +%s` " + let "thisLtime = $thisLtime - 6 " + echo $lastLtime + echo $thisLtime + if [ $thisLtime -lt $lastLtime ] ; + then + echo "Less than" + else + echo "More than" + else + echo "jeebash.sh hasn't set /tmp/seconds" >> /etc/heyu/RFxConsole.txt + fi +fi diff --git a/Bash Scripts/JeeCentralMonitor-MK1.sh b/Bash Scripts/JeeCentralMonitor-MK1.sh new file mode 100755 index 0000000..dafb122 --- /dev/null +++ b/Bash Scripts/JeeCentralMonitor-MK1.sh @@ -0,0 +1,78 @@ +#!/bin/bash +#echo "Start" +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeCentralMonitor-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +#echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt +yymmdd=`date "+%Y%m%d"` +#echo $yymmdd + args=("$@") # Assign to array +# 49 35 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +# +# 49 35 145 16 1 0 0 52 11 185 16 136 17 34 12 New (-70dB) +# 62 8 0 49 32 255 0 0 0 0 0 0 244 255 0 0 + +# Extract 8 bits XX 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "node = ${args[0]}" # Get node number +let "node = $node&31" # strip ack/dst/ctl flags +#echo $node #>> /tmp/node +# +# Extract last command received via ACK +let "command = ${args[1]}" +# +# Extract 2 bits of packet type +let "type = ${args[2]} >> 6" +# Extract 6 bits of RX CRC error count +let "badCRC = ${args[2]} & 63" +# +# Extract 4 bits 62 8 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "attempts = ${args[3]} & 15" # Get attempt number, strip high order 4 bits +#echo ${args[1]} $attempts #>> /tmp/attempts +# +# Extract 4 bits 49 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "sequence = ${args[3]} >> 4" # Get sequence number, loose low order 4 bits +#echo ${args[1]} $sequence #>> /tmp/sequence +# +# Extract battery voltage +let "Voltage = ${args[4]}" +# Extract Salus ID 49 145 XX 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "SalusID = ${args[5]}" +#echo $SalusID +# Extract Salus command 49 145 16 X 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "SalusCommand = ${args[6]}" # 1 = ON & 2 = OFF +#echo $SalusCommand +# +# Extract Salus noise counter +let "SalusNoise = ${args[7]}" +#echo $SalusNoise +# Extract Cold Feed Temperature +let "ColdFeed = (${args[9]} << 8) + ${args[8]}" +# Extract Boiler Feed Temperature +let "BoilerFeed = (${args[11]} << 8) + ${args[10]}" +# Extract Central Heating Return Temperature +let "CHreturn = (${args[13]} << 8) + ${args[12]}" +# Extract Tank Coil Return Temperature +let "TCreturn = (${args[15]} << 8) + ${args[14]}" + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/JeeRoomNodeDecoder.dat > /tmp/latestRoomNode.dat # /tmp is a ram disk on RPi +read date time RoomNode light movement humidity temperature < /tmp/latestRoomNode.dat + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/GasMeter > /tmp/GasMeter # /tmp is a ram disk on RPi +read date time GasMeter GasCount < /tmp/GasMeter + +echo `date "+%Y/%m/%d %X"` $node $command $type $badCRC $sequence $attempts $Voltage $SalusID $SalusCommand $SalusNoise $ColdFeed $BoilerFeed $CHreturn $TCreturn $temperature $GasMeter >> /etc/heyu/JeeCentralMonitor.dat + +################################################################# +rm -rf "${LOCKDIR}" +else +#echo "Finished" +echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/JeeCentralMonitor.skipped +fi +################################################################# +wget -q -O- "https://api.thingspeak.com/update?key=O64IA4X1ZIVU9DWN&field4=$Voltage&field5=$ColdFeed&field6=$BoilerFeed&field7=$CHreturn&field8=$TCreturn" > /dev/null 2>&1 +# \ No newline at end of file diff --git a/Bash Scripts/JeeCentralMonitor.sh b/Bash Scripts/JeeCentralMonitor.sh new file mode 100755 index 0000000..5441dc2 --- /dev/null +++ b/Bash Scripts/JeeCentralMonitor.sh @@ -0,0 +1,149 @@ +#!/bin/bash +#echo "Start JeeCentralMonitor.sh" >> /tmp/JeeCentralMonitor +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeCentralMonitor-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt +#echo `date "+%d/%m/%Y %X"` $@ +yymmdd=`date "+%Y%m%d"` +#echo $yymmdd + args=("$@") # Assign to array +# OK 49 35 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 +# +# OK 49 35 145 16 1 0 0 52 11 185 16 136 17 34 12 New (-70dB) +# OK 62 8 0 49 32 255 0 0 0 0 0 0 244 255 0 0 + +# Extract 8 bits XX 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "node = ${args[1]}" # Get node number +let "node = $node&31" # strip ack/dst/ctl flags +#echo $node #>> /tmp/node +# +# Extract last command received via ACK +let "command = ${args[2]}" +# +# Extract 2 bits of packet type +#let "type = 0" +let "type = ${args[3]} >> 6" +let "type = $type + 0" +#echo "`date "+%Y/%m/%d %X"`"#"$type"#"" +# Extract 2 bit setback indicator +let "setBack = ${args[3]} >> 5" +let "setBack = $setBack & 1" +# Extract 6 bits of RX CRC error count +let "badCRC = ${args[3]} & 15" +# +# Extract 4 bits 62 8 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "attempts = ${args[4]} & 15" # Get attempt number, strip high order 4 bits +#echo ${args[1]} $attempts #>> /tmp/attempts +# +# Extract 4 bits 49 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "sequence = ${args[4]} >> 4" # Get sequence number, loose low order 4 bits +#echo ${args[1]} $sequence #>> /tmp/sequence +# +# Extract battery voltage +let "Voltage = ${args[5]}" +# Extract Salus ID 49 145 XX 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +#let "SalusID = ${args[5]}" +let "SalusID = (${args[7]} << 8) + ${args[6]}" +#echo $SalusID +# Extract Salus command 49 145 16 X 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "SalusCommand = ${args[8]}" # 32 = ON & 0 = OFF +#echo $SalusCommand +# +# Extract Salus noise counter +let "SalusNoise = ${args[9]}" +#echo $SalusNoise +# Extract current temperature +let "currentTemp = (${args[11]} << 8) + ${args[10]}" +# Extract lowest temperature +let "lowestTemp = (${args[13]} << 8) + ${args[12]}" +# Extract target temperature +let "targetTemp = (${args[15]} << 8) + ${args[14]}" +# +# Check for temperature overrun, underrun or match +let "misMatch = 0" +if [ $targetTemp -ne $lowestTemp ] + then + let "misMatch = ($currentTemp - $targetTemp) / 10" +fi + +# +# Extract Cold Feed Temperature +let "ColdFeed = (${args[17]} << 8) + ${args[16]}" +# Extract Boiler Feed Temperature +let "BoilerFeed = (${args[19]} << 8) + ${args[18]}" +# Extract Central Heating Return Temperature +let "CHreturn = (${args[21]} << 8) + ${args[20]}" +# Extract Tank Coil Return Temperature +let "HWTankTemp = (${args[23]} << 8) + ${args[22]}" +# Extract Boiler Target +let "BTarget = (${args[25]} << 8) + ${args[24]}" + +let "Delta=($BoilerFeed - $CHreturn)" +Delta=`echo "scale=2;$Delta / 100" | bc -l | sed -e 's/^-\./-0./' -e 's/^\./0./'` +#echo `date "+%Y/%m/%d %X"` $CHreturn $BoilerFeed $Delta >> /etc/heyu/CH-Delta.txt + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/JeeRoomNodeDecoder.dat > /tmp/latestRoomNode.dat # /tmp is a ram disk on RPi +read date time RoomNode light movement humidity temperature < /tmp/latestRoomNode.dat + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/GasMeter > /tmp/GasMeter # /tmp is a ram disk on RPi +read date time GasMeter GasCount < /tmp/GasMeter + +# Get current Raspi temperaature +#let raspiTemp=`cat /sys/class/thermal/thermal_zone0/temp` +echo `date "+%Y/%m/%d %X"` $node $command $type $setBack $badCRC $sequence $attempts $Voltage $SalusID $SalusCommand $SalusNoise $currentTemp $lowestTemp $targetTemp $ColdFeed $BoilerFeed $CHreturn $HWTankTemp $tempShederature $GasMeter $raspiTemp >> /etc/heyu/JeeCentralMonitor.dat +# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 +# Collect latest noise floor from tx.sh +# /usr/bin/tail -n1 /etc/heyu/tx.txt > /tmp/tx.txt # /tmp is a ram disk on RPi +# read date time noiseFloor < /tmp/tx.txt +# echo "$noiseFloor" > /tmp/noiseFloor + + +if [ -f /tmp/BME280.temp ] ; + then + read bmeTemp bmeHumidity bmePressure < /tmp/BME280.temp + post "http://api.thingspeak.com/update?key=O64IA4X1ZIVU9DWN&field1=$bmeTemp&field2=$setBack&field3=$BTarget&field4=$misMatch&field5=$ColdFeed&field6=$BoilerFeed&field7=$Delta&field8=$HWTankTemp" # >> /etc/heyu/JeeCentral1.post + rm /tmp/BME280.temp + else + post "http://api.thingspeak.com/update?key=O64IA4X1ZIVU9DWN&field2=$setBack&field3=$BTarget&field4=$misMatch&field5=$ColdFeed&field6=$BoilerFeed&field7=$Delta&field8=$HWTankTemp" # >> /etc/heyu/JeeCentral1.post +fi + +#let "ret = $?" +#if [ "$ret" -ne "0" ] ; +# then +# echo `date "+%Y/%m/%d %X "` "One $ret" >> /etc/heyu/JeeCentralMonitor.dat +#fi + +#if [ "$type" -gt "1" ] ; +# then +# wget -q -t 1 -O- "https://api.thingspeak.com/update?key=8M3XA5UWS5A1L1RN&field1=$currentTemp&field2=$lowestTemp&field3=$targetTemp" > /dev/null 2>&1 + +if [ -f /tmp/Jee18-BME280.temp ] ; + then + /usr/bin/tail -n1 /tmp/Jee18-BME280.temp > /tmp/Jee18.dat # /tmp is a ram disk on RPi + read tempShed humidity pressure vcc < /tmp/Jee18.dat # Read back last data stored + tempShed=`echo "scale=2;$tempShed / 100" | bc -l | sed -e 's/^-\./-0./' -e 's/^\./0./'` + post "http://api.thingspeak.com/update?key=8M3XA5UWS5A1L1RN&field1=$currentTemp&field2=$lowestTemp&field3=$targetTemp&field4=$type&field5=$sequence&field6=$attempts&field7=$badCRC&field8=$tempShed" # | grep Status >> /etc/heyu/JeeCentral2.post + rm /tmp/Jee18-BME280.temp + else + post "http://api.thingspeak.com/update?key=8M3XA5UWS5A1L1RN&field1=$currentTemp&field2=$lowestTemp&field3=$targetTemp&field4=$type&field5=$sequence&field6=$attempts&field7=$badCRC" # | grep Status >> /etc/heyu/JeeCentral2.post +fi +# if [ "$ret" -ne "0" ] ; +# then +# echo `date "+%Y/%m/%d %X"` "Two $ret" >> /etc/heyu/JeeCentralMonitor.dat +# fi +#fi + +################################################################# +rm -rf "${LOCKDIR}" +else +#echo "Finished" +echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/JeeCentralMonitor.skipped +################################################################# +fi +# diff --git a/Bash Scripts/JeeCentralTest.sh b/Bash Scripts/JeeCentralTest.sh new file mode 100755 index 0000000..1da4d05 --- /dev/null +++ b/Bash Scripts/JeeCentralTest.sh @@ -0,0 +1,89 @@ +#!/bin/bash +echo "Start JeeCentralTest.sh" >> /tmp/JeeCentralTest +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeCentralTest-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralTest.txt +yymmdd=`date "+%Y%m%d"` +#echo $yymmdd + args=("$@") # Assign to array +# 49 35 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 +# +# 49 35 145 16 1 0 0 52 11 185 16 136 17 34 12 New (-70dB) +# 62 8 0 49 32 255 0 0 0 0 0 0 244 255 0 0 + +# Extract 8 bits XX 145 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "node = ${args[0]}" # Get node number +let "node = $node&31" # strip ack/dst/ctl flags +#echo $node #>> /tmp/node +# +# Extract last command received via ACK +let "command = ${args[1]}" +# +# Extract 2 bits of packet type +let "type = ${args[2]} >> 6" +# Extract 2 bit setback indicator +let "setBack = ${args[2]} >> 4" +let "setBack = $setBack & 3" +# Extract 6 bits of RX CRC error count +let "badCRC = ${args[2]} & 15" +# +# Extract 4 bits 62 8 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "attempts = ${args[3]} & 15" # Get attempt number, strip high order 4 bits +#echo ${args[1]} $attempts #>> /tmp/attempts +# +# Extract 4 bits 49 XX 16 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "sequence = ${args[3]} >> 4" # Get sequence number, loose low order 4 bits +#echo ${args[1]} $sequence #>> /tmp/sequence +# +# Extract battery voltage +let "Voltage = ${args[4]}" +# Extract Salus ID 49 145 XX 2 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +#let "SalusID = ${args[5]}" +let "SalusID = (${args[6]} << 8) + ${args[5]}" +#echo $SalusID +# Extract Salus command 49 145 16 X 0 0 0 0 255 255 0 0 0 0 0 0 (-70dB) +let "SalusCommand = ${args[7]}" # 1 = ON & 2 = OFF +#echo $SalusCommand +# +# Extract Salus noise counter +let "SalusNoise = ${args[8]}" +#echo $SalusNoise +# Extract current temperature +let "currentTemp = (${args[10]} << 8) + ${args[9]}" +# Extract lowest temperature +let "lowestTemp = (${args[12]} << 8) + ${args[11]}" +# Extract target temperature +let "targetTemp = (${args[14]} << 8) + ${args[13]}" + # +# Extract Cold Feed Temperature +let "ColdFeed = (${args[16]} << 8) + ${args[15]}" +# Extract Boiler Feed Temperature +let "BoilerFeed = (${args[18]} << 8) + ${args[17]}" +# Extract Central Heating Return Temperature +let "CHreturn = (${args[20]} << 8) + ${args[19]}" +# Extract Tank Coil Return Temperature +let "TCreturn = (${args[22]} << 8) + ${args[21]}" + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/JeeRoomNodeDecoder.dat > /tmp/latestRoomNode.dat # /tmp is a ram disk on RPi +read date time RoomNode light movement humidity temperature < /tmp/latestRoomNode.dat + +# Collect latest temperature from RoomNode +/usr/bin/tail -n1 /etc/heyu/GasMeter > /tmp/GasMeter # /tmp is a ram disk on RPi +read date time GasMeter GasCount < /tmp/GasMeter + +echo `date "+%Y/%m/%d %X"` $node $command $type $setBack $badCRC $sequence $attempts $Voltage $SalusID $SalusCommand $SalusNoise $currentTemp $lowestTemp $targetTemp $ColdFeed $BoilerFeed $CHreturn $TCreturn $temperature $GasMeter >> /etc/heyu/JeeCentralTest.dat + +################################################################# +rm -rf "${LOCKDIR}" +else +#echo "Finished" +echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/JeeCentralTest.skipped +fi +################################################################# +#wget -q -O- "https://api.thingspeak.com/update?key=O64IA4X1ZIVU9DWN&field4=$Voltage&field5=$ColdFeed&field6=$BoilerFeed&field7=$CHreturn&field8=$TCreturn" > /dev/null 2>&1 +# diff --git a/Bash Scripts/JeeElec.sh b/Bash Scripts/JeeElec.sh new file mode 100755 index 0000000..c3aa44c --- /dev/null +++ b/Bash Scripts/JeeElec.sh @@ -0,0 +1,12 @@ +#!/bin/bash +if [ -f /tmp/cumElec ] ; + then + read cumulative < /tmp/cumElec + echo 0 > /tmp/cumElec + if [ "$cumulative" -ne 0 ]; + then + post "http://api.thingspeak.com/update?key=QA676KGFLDQ1B1JW&field3=$cumulative" > /dev/null 2>&1 + fi + else + echo 0 > /tmp/cumElec +fi diff --git a/Bash Scripts/JeeGasCounterDecoder.sh b/Bash Scripts/JeeGasCounterDecoder.sh new file mode 100755 index 0000000..dd9be11 --- /dev/null +++ b/Bash Scripts/JeeGasCounterDecoder.sh @@ -0,0 +1,138 @@ +#!/bin/bash +#if [ $# -ne 9 ] +#then +# echo "Incorrect number ($#) of arguments $@" >> /etc/heyu/JeeGasCounterDecoder.err +# exit 65 +#fi +#################################################### +##### Sandhurst ##### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeGasCounterDecoder-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +yymmdd=`date "+%Y%m%d"` + args=("$@") # Assign to array +# 17 42 40 0 65 0 37 150 +# args 0 1 2 3 4 5 6 7 +# +let "node = ${args[0]}" # Get node number +let "sequence = ${args[1]}" # Get sequence sequence number +# +# let "count = 65535" # maximum count expected 255 255 +let "count = ${args[3]}" +let "count = $count << 8" +let "count = $count + ${args[2]}" +# +# let "timer = 65535" # maximum timer expected 255 255 +let "timer = ${args[5]}" +#echo "T1:" $timer >> timer.txt +let "timer = $timer << 8" +#echo "T2:" $timer >> timer.txt +let "timer = $timer + ${args[4]}" +#echo "T3:" $timer >> timer.txt +# +#let "timer = $timer / 1000" # Reduce to seconds +#echo "T4:" $timer >> timer.txt +# +# let "temperature = 65535" # maximum timer expected 255 255 +let "temperature = ${args[6]}" +let "temperature = $temperature-9" # Calibration + +#echo "Temperature at gas meter:$temperature" + +#if [ "$temperature" -lt "1" ] +# then +# /usr/bin/jee 17,154p +# else +# /usr/bin/jee 17,152p +#fi +# +let "voltage = ${args[7]}" +#echo "V1=" $voltage >> voltage.txt +let "voltage = $voltage * 20" +#echo "V2=" $voltage >> voltage.txt +let "voltage = $voltage + 1000" +#echo "V3=" $voltage >> voltage.txt +# +/usr/bin/tail -n1 /etc/heyu/GasMeter > /tmp/GasMeter # /tmp is a ram disk on RPi +read date time meter jeecount < /tmp/GasMeter # 1283036400 NNNNNnnn NNN +#echo "DEBUG:($date)($time)($meter)($jeecount)" >> /etc/heyu/debug +#echo ${yymmdd:6:2} ${date:8:2} +if [ "${yymmdd:6:2}" -ne "${date:8:2}" ] + then +# echo JeeGasCounterDecoder.sh >&2 + mv /etc/heyu/GasMeter /etc/heyu/archive/GasMeter-${date:0:4}${date:5:2}${date:8:2} + echo `date "+%Y/%m/%d %X"` $meter $jeecount > /etc/heyu/GasMeter + mv /etc/heyu/JeeGasCounterDecoder.skipped /etc/heyu/archive/JeeGasCounterDecoder-${date:0:4}${date:5:2}${date:8:2}.skipped + touch /etc/heyu/JeeGasCounterDecoder.skipped + echo '----------JeeGasCounterDecoder.txt--------------' > /tmp/email + /usr/bin/tail /etc/heyu/JeeGasCounterDecoder.txt -n1 >> /tmp/email + mv /etc/heyu/JeeGasCounterDecoder.txt /etc/heyu/archive/JeeGasCounterDecoder-${date:0:4}${date:5:2}${date:8:2}.txt + touch /etc/heyu/JeeGasCounterDecoder.txt + echo '----------JeeGasCounterDecoder.dat--------------' >> /tmp/email + /usr/bin/tail /etc/heyu/JeeGasCounterDecoder.dat -n1 >> /tmp/email + mv /etc/heyu/JeeGasCounterDecoder.dat /etc/heyu/archive/JeeGasCounterDecoder-${date:0:4}${date:5:2}${date:8:2}.dat + touch /etc/heyu/JeeGasCounterDecoder.dat + echo '------------jeebash.err------------' >> /tmp/email + /bin/cat /etc/heyu/jeebash.err >> /tmp/email + mv /etc/heyu/jeebash.err /etc/heyu/archive/jeebash-${date:0:4}${date:5:2}${date:8:2}.err + touch /etc/heyu/jeebash.err + echo '------------burl.err------------' >> /tmp/email + /bin/cat /etc/heyu/burl.err >> /tmp/email + mv /etc/heyu/burl.err /etc/heyu/archive/burl-${date:0:4}${date:5:2}${date:8:2}.err + touch /etc/heyu/burl.err + echo '------------post.err------------' >> /tmp/email + /bin/cat /etc/heyu/post.err >> /tmp/email + mv /etc/heyu/post.err /etc/heyu/archive/post-${date:0:4}${date:5:2}${date:8:2}.err + touch /etc/heyu/post.err + echo '------------receive.log------------' >> /tmp/email + touch /tmp/receive.log + /bin/cat /tmp/receive.log >> /tmp/email + echo '------------df -h------------' >> /tmp/email + /bin/df -h >> /tmp/email + echo '------------------------' >> /tmp/email + /usr/sbin/ssmtp itaide@googlemail.com << EOF +To: itaide@googlemail.com +Date: `date` +Subject: Sandhurst Energy Management: JeeGasCounterDecoder `date -R` +Body: +------------------------ +`/bin/cat /tmp/email` +------------------------ +EOF +# +# echo "Log Cleared by script on `date`" > /tmp/receive.txt +fi +echo `date "+%Y/%m/%d %X"` $# $@ >> /etc/heyu/JeeGasCounterDecoder.txt +echo `date "+%Y/%m/%d %X"` $node $sequence $count $timer $temperature $voltage >> /etc/heyu/JeeGasCounterDecoder.dat +if [ "$count" -lt "$jeecount" ]; then + let jeecount=$count # JeeNode integer overflow or restart + let count=$count+1 # Resync and assume 1 unit used + echo "DEBUG1:($date)($time),M=($meter),C=($count),J=($jeecount)" >> /etc/heyu/DEBUG1-INC +fi +if [ "$count" -gt "$jeecount" ]; then + let "inc=($count-$jeecount)*10" # Multiplied by 10 in Sandhurst *10 + let "newmeter=$meter+$inc" + echo `date "+%Y/%m/%d %X"` $newmeter $count >> /etc/heyu/GasMeter # Append to avoid flash wear on RPi SD card +fi +# echo "DEBUG2:($date)($time),M=($meter),C=($count),J=($jeecount),I=($inc)" >> /etc/heyu/DEBUG2-INC +# +# Update COSM +# { +# "version":"1.0.0", +# "datastreams":[ +# {"id":"Sequence", "current_value":"2"}, +# {"id":"temperature", "current_value":"4"}, +# {"id":"voltage", "current_value":"4351"} +# ] +# } +# REMOVED from end of line below ,{"id":"voltage", "current_value":"'$voltage'"},{"id":"meter", "current_value":"'$newmeter'"} +#echo '{ "version":"1.0.0","datastreams":[ {"id":"temperature", "current_value":"'$temperature'"}]}' > /tmp/cosm.json +#/usr/bin/curl --request PUT --data-binary @/tmp/cosm.json --header "X-ApiKey: aykgZFSvrNzXgHpIrDVF4Zhat3OSAKx1SUJ1bDlTMU5IQT0g" http://api.cosm.com/v2/feeds/84359 >/dev/null 2>&1 +#echo $count $meter $jeecount >> count.txt +################################################################# +rm -rf "${LOCKDIR}" +else + echo `date "+%Y/%m/%d %X"` $# $@ >> /etc/heyu/JeeGasCounterDecoder.skipped +fi +################################################################# diff --git a/Bash Scripts/JeeGraphGas.sh b/Bash Scripts/JeeGraphGas.sh new file mode 100755 index 0000000..cd2dec4 --- /dev/null +++ b/Bash Scripts/JeeGraphGas.sh @@ -0,0 +1,20 @@ +#!/bin/bash +if [ -f /tmp/GraphGas ] ; + then + read Ldate Ltime Lnode Lsequence Lcount Ltimer Ltemperature Lvoltage < /tmp/GraphGas + tail /etc/heyu/JeeGasCounterDecoder.dat -n1 > /tmp/GraphGas + read date time node sequence count timer temperature voltage < /tmp/GraphGas + + if [ $sequence -ne $Lsequence ] ; + then + let "used = $count - $Lcount" +# wget -q -t 1 -O- "https://api.thingspeak.com/update?key=7XBDAG15IIQ5HWV9&field3=$used&field4=$temperature&field5=$voltage" > /dev/null 2>&1 + post "http://api.thingspeak.com/update?key=7XBDAG15IIQ5HWV9&field3=$used&field4=$temperature&field5=$voltage" > /dev/null 2>&1 +# else +# wget -q -t 1 -O- "https://api.thingspeak.com/update?key=7XBDAG15IIQ5HWV9&field3=0" > /dev/null 2>&1 +# post "http://api.thingspeak.com/update?key=7XBDAG15IIQ5HWV9&field3=0" > /dev/null 2>&1 + fi + else + tail /etc/heyu/JeeGasCounterDecoder.dat -n1 > /tmp/GraphGas +fi +#/etc/heyu/JeeElec.sh diff --git a/Bash Scripts/JeePowerSneakDecoder.sh b/Bash Scripts/JeePowerSneakDecoder.sh new file mode 100755 index 0000000..4f7cf9d --- /dev/null +++ b/Bash Scripts/JeePowerSneakDecoder.sh @@ -0,0 +1,29 @@ +#!/bin/bash +#################################################### +##### Sandhurst ##### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeePowerSneakDecoder-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### + args=("$@") # Assign to array +# OK 7 117 134 201 26 65 +# args 0 1 2 3 4 5 +# +let "node = ${args[0]}" # Get node number +let "count = ${args[1]}" +let "voltage = 27900 / ${args[2]}" +if [ -f /tmp/cumElec ] ; + then + read cumulative < /tmp/cumElec + let "cumulative = $cumulative + $voltage" + echo $cumulative > /tmp/cumElec + else + echo $voltage > /tmp/cumElec + let "cumulative = $voltage" +fi +echo `date "+%Y/%m/%d %X"` $node $count $voltage $minV $cumulative >> /etc/heyu/JeePowerSneakDecoder.dat +#wget -q -O- "https://api.thingspeak.com/update?key=8M3XA5UWS5A1L1RN&field5=$voltage" > /dev/null 2>&1 +rm -rf "${LOCKDIR}" +else + echo `date "+%Y/%m/%d %X"` $# $@ >> /etc/heyu/JeePowerSneakDecoder.skipped +fi diff --git a/Bash Scripts/JeeRoomNodeDecoder.sh b/Bash Scripts/JeeRoomNodeDecoder.sh new file mode 100755 index 0000000..4072b3a --- /dev/null +++ b/Bash Scripts/JeeRoomNodeDecoder.sh @@ -0,0 +1,74 @@ +#!/bin/bash +#################################################### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeRoomNodeDecoder-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### +yymmdd=`date "+%Y%m%d"` +/usr/bin/tail -n1 /etc/heyu/JeeRoomNodeDecoder.dat > /tmp/JeeRoomNodeDecoder.dat # /tmp is a ram disk on RPi +read date time node light movement humidity temp < /tmp/JeeRoomNodeDecoder.dat # Read back last data stored +if [ "${yymmdd:6:2}" -ne "${date:8:2}" ] + then + mv /etc/heyu/JeeRoomNodeDecoder.dat /etc/heyu/archive/JeeRoomNodeDecoder-${date:0:4}${date:5:2}${date:8:2}.dat + touch /etc/heyu/JeeRoomNodeDecoder.dat + mv /etc/heyu/JeeRoomNodeDecoder.skipped /etc/heyu/archive/JeeRoomNodeDecoder-${date:0:4}${date:5:2}${date:8:2}.skipped + touch /etc/heyu/JeeRoomNodeDecoder.skipped +fi +#echo `date "+%Y/%m/%d %X"` $@ >> ./JeeRoomNodeDecoder.txt + args=("$@") # Assign to array +# +# RoomNode +# 0 4 17 111 12 1 0 +# args 0 1 2 3 4 5 6 +# +#struct { +# byte command; // ACK command return field +# byte light; // (arg 2) light sensor: 0..255 +# byte moved :1; // (arg 3) motion detector: 0..1 +# byte humi :7; // (arg 3) humidity: 0..100 +# int temp :10; // (arg 4)+(arg 4) temperature: -500..+500 (tenths) +# byte lobat :1; // (arg 5) supply voltage dropped under 3.1V: 0..1 +#// int voltage :13; //(arg 4)+(arg 5) AA-Board Battery voltage +#} payload; + +let "command = ${args[1]}" # Get command byte +let "node = ${args[0]}" # Get node number +#let "node = $node & 31" # strip ack/dst/ctl flags +let "light = ${args[2]}" # Get light level +# +# let "timer = 4294967295" # maximum timer expected 255 255 255 255 +let "movement = ${args[3]} & 1" # Low order bit indicates movement +#let "movement = $movement / 128" # Low order bit indicates movement +# +let "humidity = ${args[3]} >> 1" # +#let "humidity = $humidity & 127" # Loose low order bit if present +# +let "temp = ${args[5]} & 3" # Clear all but top 2 bits +let "temp = temp << 8" # Position bits 9&10 +let "temp = temp + ${args[4]}" # Add in bits 1-8 +# +let "battery = ${args[5]} >> 7" + +echo `date "+%Y/%m/%d %X"` $node $light $movement $humidity $temp $battery >> /etc/heyu/JeeRoomNodeDecoder.dat +# +if [ -f /tmp/BME280.roomNode ] ; + then + read bmeTemp bmeHumidity bmePressure bmeVcc < /tmp/BME280.roomNode + post "http://api.thingspeak.com/update?key=AG0FOXOMBA68DDOR&field1=$light&field2=$movement&field3=$humidity&field4=$temp&field5=$battery&field6=$bmeVcc&field7=$bmeHumidity&field8=$bmePressure" + rm /tmp/BME280.roomNode + else + post "http://api.thingspeak.com/update?key=AG0FOXOMBA68DDOR&field1=$light&field2=$movement&field3=$humidity&field4=$temp&field5=$battery" +fi + +if [[ $battery == 1 ]]; + then + who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'"Low Battery Node $node" > /dev/$pty; done +fi + +else + echo `date "+%Y/%m/%d %X"` $@ >> /etc/heyu/JeeRoomNodeDecoder.skipped +################################################################# +rm -rf "${LOCKDIR}" +fi +################################################################# + diff --git a/Bash Scripts/JeeTempDecoder.sh b/Bash Scripts/JeeTempDecoder.sh new file mode 100755 index 0000000..81b7f76 --- /dev/null +++ b/Bash Scripts/JeeTempDecoder.sh @@ -0,0 +1,59 @@ +#!/bin/bash +#if [ $# -ne 5 ] +#then +# echo "Incorrect number ($#) of arguments $@" >> /etc/heyu/JeePowerSneakDecoder.err +# exit 65 +#fi +#################################################### +##### Sandhurst ##### +####################LOCKFILE######################## +LOCKDIR="/tmp/JeeTempDecoder-lock" +if mkdir "${LOCKDIR}" &>/dev/null; then +#################################################### + args=("$@") # Assign to array +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 +# 36 0 0 113 0 255 0 178 161 251 52 33 133 14 0 +# +let "node = ${args[0]}" # Get node number +# +let "command = ${args[1]}" +# +let "badCRC = ${args[2]} & 15" +let "packetType = ${args[2]} >> 4" +# +let "attempts = ${args[3]} & 15" +let "count = ${args[3]} >> 4" +# +let "NoiseFloor = ${args[4]}" +# +let "failNoiseFloor = ${args[5]}" +# +let "failNoiseCount = ${args[6]}" +# +let "rxRssi = ${args[7]}" +#echo "rxRSSI $rxRssi" +# args 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 +# 36 0 0 113 0 255 0 178 161 251 52 33 133 14 0 +let "rxFei = ${args[9]} * 256" +let "rxFei = $rxFei + ${args[8]}" +#echo "rxFEI $rxFei" +# +#echo "Temp: ${args[10]} ${args[11]} " + +let "temp = ${args[11]} * 256" +let "temp = $temp + ${args[10]}" +#echo "Temp:$temp" +# +let "voltage = ${args[13]} * 256" +let "voltage = $voltage + ${args[12]}" +#echo "Voltage $voltage" +# +echo `date "+%Y/%m/%d %X"` $node $command $packetType $badCRC $attempts $count $NoiseFloor $failNoiseFloor $failNoiseCount $rxRssi $temp $voltage >> /etc/heyu/JeeTempDecoder.dat +wget -q -t 1 -O- "https://api.thingspeak.com/update?key=8M3XA5UWS5A1L1RN&field4=$temp&field6=$voltage&field7=$NoiseFloor&field8=$rxRssi" > /dev/null 2>&1 +wget -q -t 1 -O- "https://api.thingspeak.com/update?key=O64IA4X1ZIVU9DWN&field3=$temp" > /dev/null 2>&1 + +rm -rf "${LOCKDIR}" +else + echo `date "+%Y/%m/%d %X"` $# $@ >> /etc/heyu/JeeTempDecoder.skipped +fi +################################################################# diff --git a/Bash Scripts/Outside.sh b/Bash Scripts/Outside.sh new file mode 100755 index 0000000..892083c --- /dev/null +++ b/Bash Scripts/Outside.sh @@ -0,0 +1,51 @@ +#!/bin/bash +args=("$@") # Assign to array +let "t=${args[0]}" +if [ -f /tmp/avgOutside ] ; + then + read ts lastAvg r1 r2 r3 r4 r5 r6 r7 r8 r9 overflow < /tmp/avgOutside + else + let "ts=0" + let "lastAvg = 0" + let "r1=r2=r3=r4=r5=r6=r7=r8=r9=$t" +fi +printf -v now '%(%s)T' -2 # Epoc when shell started +if (( $now > $ts+59 )); then # Max one sample per minute + let "Avg=$t+$r1+$r2+$r3+$r4+$r5+$r6+$r7+$r8+$r9+5" + let "Avg=$Avg/10" + if [ "$lastAvg" -ne "$Avg" ]; then + echo `date "+%d/%m/%Y %X"` $@ $Avg >> /etc/heyu/Outside.txt + echo "$now $Avg $Avg $Avg $Avg $Avg $Avg $Avg $Avg $Avg $Avg $Avg" > /tmp/avgOutside + echo "$now $Avg $t $r1 $r2 $r3 $r4 $r5 $r6 $r7 $r8 $r9" >> /tmp/DEBUGavgOutside + if [ "$Avg" -gt "17" ]; then + /usr/bin/jee 17,130p # 46° + elif [ "$Avg" -eq "17" ]; then + /usr/bin/jee 17,135p # 47° + elif [ "$Avg" -eq "16" ]; then + /usr/bin/jee 17,143p # 48.6° + elif [ "$Avg" -eq "15" ]; then + /usr/bin/jee 17,155p # 51° Reasonable 14/1/19 + elif [ "$Avg" -eq "14" ]; then + /usr/bin/jee 17,160p # 52° Reasonable 8/1/19 + elif [ "$Avg" -eq "13" ]; then + /usr/bin/jee 17,163p # 52.6° Tuned 9/1/19 + elif [ "$Avg" -eq "12" ]; then + /usr/bin/jee 17,170p # 54.0° Reasonable 4/1/19 + elif [ "$Avg" -eq "11" ]; then + /usr/bin/jee 17,176p # 55.2° Reasonable 4/1/19 + elif [ "$Avg" -eq "10" ]; then + /usr/bin/jee 17,177p # 55.4° Reasonable 23/1/19 + elif [ "$Avg" -eq "9" ]; then + /usr/bin/jee 17,181p # 56.2° + elif [ "$Avg" -eq "8" ]; then # -2 + /usr/bin/jee 17,189p # 57.8° + elif [ "$Avg" -eq "7" ]; then # -4 + /usr/bin/jee 17,194p # 58.8° + elif [ "$Avg" -lt "6" ]; then + /usr/bin/jee 17,199p # 59.8° + fi + else + echo "$now $Avg $t $r1 $r2 $r3 $r4 $r5 $r6 $r7 $r8 $r9" > /tmp/avgOutside + fi +fi +# \ No newline at end of file diff --git a/Bash Scripts/RFxConsole.sh b/Bash Scripts/RFxConsole.sh new file mode 100755 index 0000000..159f953 --- /dev/null +++ b/Bash Scripts/RFxConsole.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +cd /etc/heyu +stty -F /dev/JeeLink -hupcl +./RFxConsole >> /etc/heyu/RFxConsole.txt 2>&1 +# +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: Raspberry Pi #1-2 RFxConsole exited on `date -R` +Body: +------------------------ +`tail /etc/heyu/RFxConsole.txt` +------------------------ +`ps aux` +------------------------ + +EOF +/etc/heyu/restart.sh & +# diff --git a/Bash Scripts/RasPi-Console.sh b/Bash Scripts/RasPi-Console.sh new file mode 100755 index 0000000..a256e0a --- /dev/null +++ b/Bash Scripts/RasPi-Console.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# Script by AndrewS to make it easier to enable/disable the serial console +# (which allows the UART to be used by other programs) +# version 1.1 - better error handling +ACTION=$1 +BAUDRATE=${2:-115200} +UART=ttyAMA0 +CMDLINE=/boot/cmdline.txt +INITTAB=/etc/inittab +if [[ ! -f "$CMDLINE" ]]; then + echo "$CMDLINE is missing" 1>&2 + exit 1 +fi +if [[ ! -f "$INITTAB" ]]; then + echo "$INITTAB is missing" 1>&2 + exit 1 +fi +CMDLINE_STATUS=disabled +if [[ $(grep $UART "$CMDLINE") ]]; then + CMDLINE_STATUS=enabled +fi +INITTAB_STATUS=disabled +if [[ $(grep -v ^# "$INITTAB" | grep $UART) ]]; then + INITTAB_STATUS=enabled +fi +LIVE_STATUS=disabled +if [[ $(grep $UART /proc/cmdline) ]]; then + LIVE_STATUS=enabled +fi +if [[ $CMDLINE_STATUS != $INITTAB_STATUS ]]; then + echo "Inconsistent status! $CMDLINE is $CMDLINE_STATUS, but $INITTAB is $INITTAB_STATUS" 1>&2 + exit 1 +fi +if [[ "$ACTION" != "enable" && "$ACTION" != "disable" && "$ACTION" != "status" ]]; then + echo "Missing / incorrect command-line argument. Use enable, disable or status" 1>&2 + exit 1 +fi +if [[ $ACTION == status ]]; then + if [[ $CMDLINE_STATUS != $LIVE_STATUS ]]; then + echo "Serial console on /dev/$UART will be $CMDLINE_STATUS after the next reboot" + else + echo "Serial console on /dev/$UART is $CMDLINE_STATUS" + fi +else + if [[ $EUID -ne 0 ]]; then + echo "Serial console can only be ${ACTION}d by root user" 1>&2 + exit 1 + fi + if [[ ${ACTION}d == $CMDLINE_STATUS ]]; then + echo "Serial console is already ${ACTION}d" + else + if [[ ! -f "${CMDLINE}.bak" ]]; then + cp "$CMDLINE" "${CMDLINE}.bak" + fi + if [[ ! -f "${INITTAB}.bak" ]]; then + cp "$INITTAB" "${INITTAB}.bak" + fi + CMDLINE_CONTENTS=$(cat "$CMDLINE") + TMPFILE="${INITTAB}.tmp" + grep -v $UART "$INITTAB" > "$TMPFILE" + if [[ $ACTION == enable ]]; then + echo "T0:23:respawn:/sbin/getty -L $UART $BAUDRATE vt100" >> "$TMPFILE" + mv "$TMPFILE" "$INITTAB" + echo "$CMDLINE_CONTENTS console=$UART,$BAUDRATE kgdboc=$UART,$BAUDRATE" > "$CMDLINE" + else + echo "#serial getty on $UART removed by "$(basename $0) >> "$TMPFILE" + mv "$TMPFILE" "$INITTAB" + NEW_CMDLINE_CONTENTS= + for p in $CMDLINE_CONTENTS; do + if [[ ${p%%=*} == console || ${p%%=*} == kgdboc ]]; then + if [[ $(echo ${p#*=} | grep $UART) ]]; then + continue + fi + fi + if [[ "$NEW_CMDLINE_CONTENTS" != "" ]]; then + NEW_CMDLINE_CONTENTS="$NEW_CMDLINE_CONTENTS " + fi + NEW_CMDLINE_CONTENTS="$NEW_CMDLINE_CONTENTS$p" + done + echo "$NEW_CMDLINE_CONTENTS" > "$CMDLINE" + fi + REBOOT_NEEDED= + if [[ ${ACTION}d != $LIVE_STATUS ]]; then + REBOOT_NEEDED=", a reboot is required to make this take effect" + fi + echo "Serial console has been ${ACTION}d$REBOOT_NEEDED" + fi +fi \ No newline at end of file diff --git a/Bash Scripts/Xrestart.sh b/Bash Scripts/Xrestart.sh new file mode 100755 index 0000000..552f0e5 --- /dev/null +++ b/Bash Scripts/Xrestart.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +cd /etc/heyu +killall RFxConsole +/bin/sleep 5 +FILE=/etc/heyu/RFxConsole.new +if [ -f $FILE ]; then + rm /etc/heyu/RFxConsole.old + mv /etc/heyu/RFxConsole /etc/heyu/RFxConsole.old + cp $FILE /etc/heyu/RFxConsole + echo "New version of RFxConsole loaded" >> /etc/heyu/RFxConsole.txt +fi + +echo "RFxConsole Restart on `date`" >> /etc/heyu/RFxConsole.txt +nohup ./RFxConsole.sh >> /etc/heyu/RFxConsole.txt 2>&1 +# +if [ -f $FILE ]; then + rm /etc/heyu/RFxConsole.old + mv /etc/heyu/RFxConsole /etc/heyu/RFxConsole.old + cp $FILE /etc/heyu/RFxConsole + echo "New version of RFxConsole loaded" >> /etc/heyu/RFxConsole.txt +fi + +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +Subject: RFxConsole Restart #1-2 on `date -R` +Body: +------------------------ +`tail /etc/heyu/RFxConsole.txt` +------------------------ +`ps aux | grep RFxConsole` +------------------------ + +EOF +# + diff --git a/Bash Scripts/burl b/Bash Scripts/burl new file mode 100644 index 0000000..91d71ea --- /dev/null +++ b/Bash Scripts/burl @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +INCLUDE_HEADERS=0 +HTTP_PORT=80 + +burl() { + shopt -s extquote + + export LC_ALL=C + unset headers_read + + host=${1%%/*} + path=${1#*/} + + [[ $path == $host ]] && path="" + + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then + + printf "GET /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 + + IFS= + while read -r -t 1 line 0<&3; do + line=${line//$'\r'} + + if [[ ! -v headers_read && $INCLUDE_HEADERS -eq 0 ]]; then + [[ -z $line ]] && headers_read=yes + continue + fi + + echo "$line" + done + + exec 3<&- + else + echo "`basename $0`: unable to connect to $host:$HTTP_PORT" + exit 1 + fi +} + +usage() { + cat < use alternative port number (default: 80) +EOF +} + +if [[ $# -eq 0 ]]; then + usage + exit 1 +fi + +while getopts 'hip:' option; do + case "$option" in + h) + usage + exit 0 + ;; + + i) + INCLUDE_HEADERS=1 + ;; + + p) + HTTP_PORT=$OPTARG + ;; + + *) + usage + exit 1 + ;; + esac +done +shift $(( $OPTIND - 1)) + +burl ${1/http:\/\/} + +# vim: ft=sh ts=4 et \ No newline at end of file diff --git a/Bash Scripts/fbtunnel.sh b/Bash Scripts/fbtunnel.sh new file mode 100755 index 0000000..7c50435 --- /dev/null +++ b/Bash Scripts/fbtunnel.sh @@ -0,0 +1,3 @@ +#!/bin/bash +IP=$(dig sandhurst.strangled.net +short) +sudo /home/john/fbtunnel 5 mysecret 192.168.250.22 $IP diff --git a/Bash Scripts/heating.sh b/Bash Scripts/heating.sh new file mode 100755 index 0000000..1093797 --- /dev/null +++ b/Bash Scripts/heating.sh @@ -0,0 +1,20 @@ +#!/bin/bash +sleep 5 +/usr/bin/jee 212,17,11p +sleep 180 +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: Sandhurst Heating #1-2 on `date -R` +Body: +------------------------ +`tail /etc/heyu/JeeCentralMonitor.dat` +------------------------ +`tail /tmp/RFxConsole.txt` +------------------------ +`tail /etc/heyu/Posted.txt +------------------------ +` +EOF +/usr/bin/jee 212,17,99p diff --git a/Bash Scripts/heating_OFF.sh b/Bash Scripts/heating_OFF.sh new file mode 100755 index 0000000..ed2e53c --- /dev/null +++ b/Bash Scripts/heating_OFF.sh @@ -0,0 +1,20 @@ +#!/bin/bash +/usr/bin/jee 17,10p +sleep 180 +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: Sandhurst Heating Off #1-2 on `date -R` +Body: +------------------------ +`tail /etc/heyu/JeeCentralMonitor.dat` +------------------------ +`tail /etc/heyu/RFxConsole.txt` +------------------------ +`tail /etc/heyu/Posted.txt` +------------------------ + +EOF +## + diff --git a/Bash Scripts/heating_ON.sh b/Bash Scripts/heating_ON.sh new file mode 100755 index 0000000..bd99c08 --- /dev/null +++ b/Bash Scripts/heating_ON.sh @@ -0,0 +1,20 @@ +#!/bin/bash +/usr/bin/jee 17,11p +sleep 180 +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: Sandhurst Heating On #1-2 on `date -R` +Body: +------------------------ +`tail /etc/heyu/JeeCentralMonitor.dat` +------------------------ +`tail /etc/heyu/RFxConsole.txt` +------------------------ +`tail /etc/heyu/Posted.txt` +------------------------ + +EOF + +## diff --git a/Bash Scripts/jee b/Bash Scripts/jee new file mode 100644 index 0000000..15d9dac --- /dev/null +++ b/Bash Scripts/jee @@ -0,0 +1,13 @@ +#!/bin/bash +#echo +if [ $# -eq 0 ]; then +# echo "No commands" + echo -e -n "123U" >> /tmp/RFxSerial.input +else + echo -e -n "$@" >> /tmp/RFxSerial.input +fi +tail /etc/heyu/RFxConsole.txt -n24 +#echo +/usr/bin/log 10 & +echo -e "echo -e -n $@ >> /tmp/RFxSerial.input" + diff --git a/Bash Scripts/jeebash-old.sh b/Bash Scripts/jeebash-old.sh new file mode 100755 index 0000000..308a8fe --- /dev/null +++ b/Bash Scripts/jeebash-old.sh @@ -0,0 +1,144 @@ +#!/bin/bash +date +%s > /tmp/seconds +echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/jeebash.txt +#tail -n1 /etc/heyu/jeebash.txt +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +TX="TX" +RX="RX" +ReInit="ReInit" +RFM69="RFM69x" +HASH0="0" +HASH1="1" +HASH0="2" +HASH1="3" +HASH0="4" +HASH1="5" + +if [[ "${args[0]}" == "$RX" ]]; + then + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/rxArgs.txt + /etc/heyu/rx.sh $@ + exit +fi + +if [[ "${args[0]}" == "$TX" ]]; + then +# echo "$@" >> /etc/heyu/jeebash.txt + /etc/heyu/tx.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} + exit +fi + +if [[ "${args[0]}" == "$RFM69" ]]; + then + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/rfm69.txt + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/RFxConsole.txt +# /etc/heyu/RFM69.sh ${args[0]} ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} \ +# ${args[9]} ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15} ${args[16]} \ +# ${args[17]} ${args[18]} & + exit +fi + +if [[ "${args[0]}" == "$ReInit" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/ReInit.txt + exit +fi + +if [[ "${args[0]}" == "OK" ]]; + then + # + # OK 16 5 254 33 0 0 245 10 0 0 + # args 0 1 2 3 4 5 6 7 8 9 A + # + #The node number occupies 5 bits. + + #The A bit (ACK) 32 indicates whether this packet wants to get an ACK back. The C bit needs to be zero in this case (the name is somewhat confusing). + + #The D bit (DST) 64 indicates whether the node ID specifies the destination node or the source node. For packets sent to a specific node, DST = 1. For broadcasts, DST = 0, in which case the node ID refers to the originating node. + + #The C bit (CTL) 128 is used to send ACKs, and in turn must be combined with the A bit set to zero. + + # Get node number + let node=${args[1]} + #let "node=$node&159" # strip dst and ack flags +# echo $@ >> args.txt +# echo $node >> node.txt + # + # If ctl bit is set node will not match below - ignore ACK returns + case $node in + 18) /etc/heyu/Jee18.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i18.txt + ;; + 50) /etc/heyu/Jee18.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i18.txt + ;; + 19) /etc/heyu/Jee19.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i19.txt + ;; + 21) /etc/heyu/JeeRoomNodeDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeRoomNodeDecoder.txt + ;; + 53) /etc/heyu/JeeRoomNodeDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeRoomNodeDecoder.txt + ;; + 4) /etc/heyu/JeeTempDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeTempDecoder.txt + ;; + 36) /etc/heyu/JeeTempDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeTempDecoder.txt + ;; + 131) + ;; + 70) /etc/heyu/JeePowerSneakDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeePowerSneakDecoder.txt + ;; + 8) /etc/heyu/JeePowerSneakDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeePowerSneakDecoder.txt + ;; + 15) /etc/heyu/JeeGasCounterDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeGasCounterDecoder.txt + /etc/heyu/Outside.sh ${args[7]} + ;; + 47) /etc/heyu/JeeGasCounterDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeGasCounterDecoder.txt + /etc/heyu/Outside.sh ${args[7]} + ;; +# 143) +# ;; + 17) /etc/heyu/JeeCentralMonitor.sh $@ & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt + ;; + 49) /etc/heyu/JeeCentralMonitor.sh $@ & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt + ;; +# 145) +# ;; + 22) + # /etc/heyu/JeeCentralTest.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} ${args[18]} ${args[19]} ${args[20]} ${args[21]} ${args[22]} ${args[23]} & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralTest.txt + ;; +# 54) +# ;; + *) echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/jeebash.err + echo `date "+%d/%m/%Y %X"` Unknown $@ >> /etc/heyu/RFxConsole.txt + ;; + esac + else + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/hash.txt + fi diff --git a/Bash Scripts/jeebash.sh b/Bash Scripts/jeebash.sh new file mode 100755 index 0000000..69e836d --- /dev/null +++ b/Bash Scripts/jeebash.sh @@ -0,0 +1,136 @@ +#!/bin/bash +date +%s > /tmp/seconds +echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/jeebash.txt +#tail -n1 /etc/heyu/jeebash.txt +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +TX="TX" +RX="RX" +ReInit="ReInit" +RFM69="RFM69x" +HASH0="0" +HASH1="1" +HASH0="2" +HASH1="3" +HASH0="4" +HASH1="5" + +if [[ "${args[0]}" == "$RX" ]]; + then + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/rxArgs.txt + /etc/heyu/rx.sh $@ + exit +elif [[ "${args[0]}" == "$TX" ]]; + then +# echo "$@" >> /etc/heyu/jeebash.txt + /etc/heyu/tx.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} + exit +elif [[ "${args[0]}" == "$RFM69" ]]; + then + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/rfm69.txt + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/RFxConsole.txt +# /etc/heyu/RFM69.sh ${args[0]} ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} \ +# ${args[9]} ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15} ${args[16]} \ +# ${args[17]} ${args[18]} & + exit +elif [[ "${args[0]}" == "$ReInit" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/ReInit.txt + exit +elif [[ "${args[0]}" == "OK" ]]; + then + # + # OK 16 5 254 33 0 0 245 10 0 0 + # args 0 1 2 3 4 5 6 7 8 9 A + # + #The node number occupies 5 bits. + + #The A bit (ACK) 32 indicates whether this packet wants to get an ACK back. The C bit needs to be zero in this case (the name is somewhat confusing). + + #The D bit (DST) 64 indicates whether the node ID specifies the destination node or the source node. For packets sent to a specific node, DST = 1. For broadcasts, DST = 0, in which case the node ID refers to the originating node. + + #The C bit (CTL) 128 is used to send ACKs, and in turn must be combined with the A bit set to zero. + + # Get node number + let node=${args[1]} + #let "node=$node&159" # strip dst and ack flags +# echo $@ >> args.txt +# echo $node >> node.txt + # + # If ctl bit is set node will not match below - ignore ACK returns + case $node in + 18) /etc/heyu/Jee18.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i18.txt + ;; + 50) /etc/heyu/Jee18.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i18.txt + ;; + 19) /etc/heyu/Jee19.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + # echo "After" > /tmp/After + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/i19.txt + ;; + 21) /etc/heyu/JeeRoomNodeDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeRoomNodeDecoder.txt + ;; + 53) /etc/heyu/JeeRoomNodeDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeRoomNodeDecoder.txt + ;; + 4) /etc/heyu/JeeTempDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeTempDecoder.txt + ;; + 36) /etc/heyu/JeeTempDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeTempDecoder.txt + ;; + 131) + ;; + 70) /etc/heyu/JeePowerSneakDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeePowerSneakDecoder.txt + ;; + 8) /etc/heyu/JeePowerSneakDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} \ + ${args[10]} ${args[11]} ${args[12]} ${args[13]} & + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeePowerSneakDecoder.txt + ;; + 15) /etc/heyu/JeeGasCounterDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeGasCounterDecoder.txt + /etc/heyu/Outside.sh ${args[7]} + ;; + 47) /etc/heyu/JeeGasCounterDecoder.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeGasCounterDecoder.txt + /etc/heyu/Outside.sh ${args[7]} + ;; +# 143) +# ;; + 17) /etc/heyu/JeeCentralMonitor.sh $@ & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt + ;; + 49) /etc/heyu/JeeCentralMonitor.sh $@ & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralMonitor.txt + ;; +# 145) +# ;; + 22) + # /etc/heyu/JeeCentralTest.sh ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} ${args[10]} ${args[11]} ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} ${args[18]} ${args[19]} ${args[20]} ${args[21]} ${args[22]} ${args[23]} & + # echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/JeeCentralTest.txt + ;; +# 54) +# ;; + *) echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/jeebash.err + echo `date "+%d/%m/%Y %X"` Unknown $@ >> /etc/heyu/RFxConsole.txt + ;; + esac + else + echo `date "+%d/%m/%Y %X"` $@ >> /etc/heyu/hash.txt + fi diff --git a/Bash Scripts/log b/Bash Scripts/log new file mode 100644 index 0000000..cb6bdba --- /dev/null +++ b/Bash Scripts/log @@ -0,0 +1,7 @@ +#!/bin/bash +if [ $# -ne 0 ]; then +# echo "Sleep $@" + sleep "$@" +fi +tail /etc/heyu/RFxConsole.txt -n30 + diff --git a/Bash Scripts/post b/Bash Scripts/post new file mode 100644 index 0000000..583999f --- /dev/null +++ b/Bash Scripts/post @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +HTTP_PORT=80 + +post() { + shopt -s extquote + + export LC_ALL=C + unset headers_read + + host=${1%%/*} + path=${1#*/} + + [[ $path == $host ]] && path="" + + if exec 3<>/dev/tcp/${host}/${HTTP_PORT}; then + printf "POST /${path} HTTP/1.1\r\nHost: ${host}\r\nUser-Agent: bURL/Bash ${BASH_VERSION}\r\n\r\n" >&3 + IFS= + while read -r -t 1 line 0<&3; do + if [ "${line:0:12}" == "HTTP/1.1 200" ]; then + break + else + echo "`date "+%d/%m/%Y %X"` post: $host:$HTTP_PORT/${path} ${line:0:12}" 1>&2 + echo "`date "+%d/%m/%Y %X"` post: $host:$HTTP_PORT/${path} ${line:0:12}" 1>> post.err + exit 1 + fi + done + exec 3<&- + else + exec 3<&- + echo "`date "+%d/%m/%Y %X"` post unable to connect: $host:$HTTP_PORT/${path}" 1>&2 + echo "`date "+%d/%m/%Y %X"` post unable to connect: $host:$HTTP_PORT/${path}" 1>>post.err + exit 1 + fi +} + +usage() { + cat < use alternative port number (default: 80) +EOF +} + +if [[ $# -eq 0 ]]; then + usage + exit 1 +fi + +while getopts 'hip:' option; do + case "$option" in + h) + usage + exit 0 + ;; + + p) + HTTP_PORT=$OPTARG + ;; + + *) + usage + exit 1 + ;; + esac +done +shift $(( $OPTIND - 1)) + +post ${1/http:\/\/} + diff --git a/Bash Scripts/reboot.sh b/Bash Scripts/reboot.sh new file mode 100755 index 0000000..9f7a07b --- /dev/null +++ b/Bash Scripts/reboot.sh @@ -0,0 +1,36 @@ +#!/bin/bash +cd /etc/heyu +killall RFxConsole +#chmod 0777 /dev/ttyUSB0 +#chmod 0777 /dev/JeeLink +#chown john /dev/JeeLink +#chown john /dev/ttyUSB0 +chgrp dialout /dev/ttyUSB* +systemctl disable serial-getty@ttyUSB*.service +#chgrp dialout /dev/JeeLink +#stty -F /dev/JeeLink -echok -echoctl hupcl hup +stty -F /dev/ttyUSB* -echok -echoctl hupcl hup +echo "`date` Reboot" >> /etc/heyu/RFxConsole.txt +nohup ./restart.sh >> /etc/heyu/RFxConsole.txt 2>&1 & +# +/usr/bin/tail -n1 /etc/heyu/GasMeter > /tmp/GasMeter # /tmp is a ram disk on RPi +read date time meter jeecount < /tmp/GasMeter +echo $meter 0 > /tmp/Min5Gas +#echo "System Startup on `date`" > /tmp/receive.txt +# +df -h > /tmp/mail_report.log +free -m >> /tmp/mail_report.log +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: Raspberry Pi #1-2 Startup on `date -R`: reboot.sh +Body: +------------------------ +`cat /tmp/mail_report.log` +------------------------ + +EOF +# +sleep 5 +/usr/bin/jee 2U190R159T diff --git a/Bash Scripts/restart.sh b/Bash Scripts/restart.sh new file mode 100755 index 0000000..94abcc2 --- /dev/null +++ b/Bash Scripts/restart.sh @@ -0,0 +1,40 @@ +#!/bin/bash +cd /etc/heyu +killall RFxConsole +/bin/sleep 5 +FILE=/etc/heyu/RFxConsole.new +if [ -f $FILE ]; then + rm /etc/heyu/RFxConsole.old + mv /etc/heyu/RFxConsole /etc/heyu/RFxConsole.old + mv $FILE /etc/heyu/RFxConsole + echo "`date` New version of RFxConsole loaded" >> /etc/heyu/RFxConsole.txt +fi + +echo "`date` RFxConsole Restart" >> /etc/heyu/RFxConsole.txt +sudo systemctl disable serial-getty@ttyUSB*.service +stty -F /dev/ttyUSB* -echok -echoctl hupcl hup +nohup ./RFxConsole.sh >> /etc/heyu/RFxConsole.txt 2>&1 +# +if [ -f $FILE ]; then + rm /etc/heyu/RFxConsole.old + mv /etc/heyu/RFxConsole /etc/heyu/RFxConsole.old + mv $FILE /etc/heyu/RFxConsole + echo "New version of RFxConsole loaded" >> /etc/heyu/RFxConsole.txt +fi + +/usr/sbin/ssmtp itaide@googlemail.com << EOF +To: John O'Hare +Date: `date` +From: RasPi1-2 +Subject: RFxConsole Restart #1-2 on `date -R`: restart.sh +Body: +------------------------ +`tail /etc/heyu/RFxConsole.txt` +------------------------ +`ps aux | grep RFxConsole` +------------------------ + +EOF +# +sleep 5 +/usr/bin/jee 2U190R159T diff --git a/Bash Scripts/rx.sh b/Bash Scripts/rx.sh new file mode 100755 index 0000000..7f235de --- /dev/null +++ b/Bash Scripts/rx.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# RX Stats 200 13229 7 7 108 108 2952981 1431 13229 [1 223 0 13215] [2 157 0 2] [3 141 0 2] [5 102 0 10] +# 2 3 4 5 6 7 8 9 10 +# RX Stats 180 504 71 71 54 450 10606 621 0 54 [1 196 10 0 49] [2 194 20 0 5] +# 2 3 4 5 6 7 8 9 10 11 +#2 Threshold in use +#3 RSSIrestart count +#4 syncMatch count +#5 goodCRC count +#6 restartRate +#7 maxRestartRate +#8 cumRSSI +#9 cumFEI +#10 cumCount +# +# [1 196 10 0 49] [2 194 20 0 5] +# [0 1 2 3 4] +#0 Auto LNA used on restart +#1 Average RSSI in sample period +#2 Average FEI in sample period +#3 Number of zero FEI in sample period +#4 Number of restarts in sample period +# +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +Stats="Stats" +if [[ "${args[1]}" == "$Stats" ]]; + then + let "threshold = ${args[2]}" + let "restarts = ${args[3]}" +# let "syncLessCRC = ${args[4]} - ${args[5]}" + let "zeroFEI = ${args[10]}" + let "goodCRC = ${args[5]}" + let "rate = ${args[6]}" + let "maxRate = ${args[7]}" + if [[ "${args[11]}" -ne 0 ]]; + then + let "avgRSSI = ${args[8]} / ${args[11]}" + avgRSSI=$(bc <<< "scale=1;$avgRSSI/-2") + let "avgFEI = ${args[9]} / ${args[11]}" + else + unset avgRSSI + unset avgFEI + fi + echo "`date "+%d/%m/%Y %X"` ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} ${args[8]} ${args[9]} ${args[10]} ${args[11]} $avgRSSI $avgFEI" >> /etc/heyu/rx_stats.txt + post "http://api.thingspeak.com/update?key=BTLO8PRRC6ZY0MJ1&field1=$threshold&field2=$restarts&field3=$zeroFEI&field4=$goodCRC&field5=$rate&field6=$maxRate&field7=$avgRSSI&field8=$avgFEI" + if [ "$rate" -lt "500" ]; + then + echo "`date "+%d/%m/%Y %X"` $rate ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} ${args[18]} ${args[19]} ${args[20]} ${args[21]} ${args[22]} ${args[23]} ${args[24]} ${args[25]} ${args[26]} ${args[27]} ${args[28]} ${args[29]} ${args[30]} ${args[31]} ${args[32]}" >> /etc/heyu/low.rate + else + echo "`date "+%d/%m/%Y %X"` $rate ${args[12]} ${args[13]} ${args[14]} ${args[15]} ${args[16]} ${args[17]} ${args[18]} ${args[19]} ${args[20]} ${args[21]} ${args[22]} ${args[23]} ${args[24]} ${args[25]} ${args[26]} ${args[27]} ${args[28]} ${args[29]} ${args[30]} ${args[31]} ${args[32]}" >> /etc/heyu/high.rate + fi +fi diff --git a/Bash Scripts/rx_threshold.sh b/Bash Scripts/rx_threshold.sh new file mode 100755 index 0000000..ebfa459 --- /dev/null +++ b/Bash Scripts/rx_threshold.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# RX threshold change 208 209 103 1 0 0 345957 +# 3 4 5 6 7 8 9 +# RX threshold change 210 211 38873 3 0 0 169910292 +# 3 4 5 6 7 8 9 + +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +threshold="threshold" +if [[ "${args[1]}" == "$threshold" ]]; + then + read prevRestarts prevSyncMatch prevGoodCRC< /tmp/rx_restarts.txt + let "restarts = (${args[5]} - $prevRestarts)" + let "syncMatch = (${args[6]} - $prevSyncMatch)" + let "goodCRC = (${args[7]} - $prevGoodCRC)" + let "SyncLessCRC = ($syncMatch - $goodCRC)" + let "RSSIlessSync = ($restarts - $syncMatch)" + echo "${args[5]} ${args[6]} ${args[7]}" > /tmp/rx_restarts.txt + echo "`date "+%d/%m/%Y %X"` ${args[3]} ${args[4]} $restarts $syncMatch $goodCRC" >> /etc/heyu/rx.txt +# wget -q -t 1 -O- "https://api.thingspeak.com/update?key=BTLO8PRRC6ZY0MJ1&field1=${args[4]}&field2=$restarts&field3=$syncMatch&field4=$goodCRC&field5=$SyncLessCRC&field6=$RSSIlessSync" > /dev/null 2>&1 + post "https://api.thingspeak.com/update?key=BTLO8PRRC6ZY0MJ1&field1=${args[4]}&field2=$restarts&field3=$syncMatch&field4=$goodCRC&field5=$SyncLessCRC&field6=$RSSIlessSync" +fi diff --git a/Bash Scripts/tx-old.sh b/Bash Scripts/tx-old.sh new file mode 100755 index 0000000..6e082c1 --- /dev/null +++ b/Bash Scripts/tx-old.sh @@ -0,0 +1,32 @@ +#!/bin/bash +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +# TX 161 -> ack i17 Posted and cleared 48 +# 0 1 2 3 4 5 6 7 +#echo "`date "+%d/%m/%Y %X"` ${args[0]}" >> /etc/heyu/tx.txt +echo `date "+%d/%m/%Y %X"` ${args[0]} ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} >> /etc/heyu/tx.txt + +let "noiseFloor = ${args[0]}" + +if [[ "${args[2]}" == "Busy" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/Busy.txt + exit +elif [[ "${args[4]}" == "Aborted" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> Aborted.txt + exit +elif [[ "${args[4]}" == "Posted" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> Posted.txt + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/RFxConsole.txt +# who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'`date '+%d/%m/%Y %X'` $@ > /dev/$pty; done + who | awk '$1 == "john" { print $2 }' | while read pty; do echo $'\x07'`date '+%d/%m/%Y %X'` $@ > /dev/$pty; done + exit +else + echo `date "+%d/%m/%Y %X"` "$@" >> Posted-Unkown.txt +fi + diff --git a/Bash Scripts/tx.sh b/Bash Scripts/tx.sh new file mode 100755 index 0000000..9845280 --- /dev/null +++ b/Bash Scripts/tx.sh @@ -0,0 +1,37 @@ +#!/bin/bash +if [ $# -eq 1 ] # Arguments received as a single string? + then + set -- $@ # Chop it up +fi + args=("$@") # Assign to array +# TX 161 -> ack i17 Posted and cleared 48 +# 0 1 2 3 4 5 6 7 +#echo "`date "+%d/%m/%Y %X"` ${args[0]}" >> /etc/heyu/tx.txt +echo `date "+%d/%m/%Y %X"` ${args[0]} ${args[1]} ${args[2]} ${args[3]} ${args[4]} ${args[5]} ${args[6]} ${args[7]} >> /etc/heyu/tx.txt + +#let "noiseFloor = ${args[0]}" + +if [[ "${args[2]}" == "Busy" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/Busy.txt + exit +elif [[ "${args[4]}" == "Aborted" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> Aborted.txt + exit +elif [[ "${args[4]}" == "Posted" ]]; + then + echo `date "+%d/%m/%Y %X"` "$@" >> Posted.txt + echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/RFxConsole.txt +# who | awk '$1 == "john" { print $2 }' | while read pty; do echo "Sending to $pty"; echo $'\n'$'\x07'`date '+%d/%m/%Y %X'` $@ > /dev/$pty; done + who | awk '$1 == "john" { print $2 }' | while read pty; do echo $'\x07'`date '+%d/%m/%Y %X'` $@ > /dev/$pty; done + exit +elif [[ "${args[2]}" == "ack" ]]; + then +# echo `date "+%d/%m/%Y %X"` "$@" >> /etc/heyu/Ack.txt + exit +else + echo `date "+%d/%m/%Y %X"` "$@" >> Posted-Unkown.txt + echo `date "+%d/%m/%Y %X"` "$@" >> RFxConsole.txt +fi +