From 9d87c925a9eaa4fc256be3173c14a20d1469472d Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Wed, 9 Sep 2020 11:53:37 +0100 Subject: everything, mostly, working --- boiler-monster/mr3020/.gitignore | 1 + boiler-monster/mr3020/Makefile | 5 +++ boiler-monster/mr3020/etc/init.d/stm32 | 7 ++++ boiler-monster/mr3020/etc/rc.d/S99stm32 | 1 + boiler-monster/mr3020/etc/stm32/startup | 50 +++++++++++++++++++++++ boiler-monster/mr3020/stamp | 0 boiler-monster/mr3020/usr/bin/thermostat | 70 ++++++++++++++++++++++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 boiler-monster/mr3020/.gitignore create mode 100644 boiler-monster/mr3020/Makefile create mode 100755 boiler-monster/mr3020/etc/init.d/stm32 create mode 120000 boiler-monster/mr3020/etc/rc.d/S99stm32 create mode 100755 boiler-monster/mr3020/etc/stm32/startup create mode 100644 boiler-monster/mr3020/stamp create mode 100755 boiler-monster/mr3020/usr/bin/thermostat (limited to 'boiler-monster/mr3020') diff --git a/boiler-monster/mr3020/.gitignore b/boiler-monster/mr3020/.gitignore new file mode 100644 index 0000000..859afb1 --- /dev/null +++ b/boiler-monster/mr3020/.gitignore @@ -0,0 +1 @@ +stamp diff --git a/boiler-monster/mr3020/Makefile b/boiler-monster/mr3020/Makefile new file mode 100644 index 0000000..26efbc3 --- /dev/null +++ b/boiler-monster/mr3020/Makefile @@ -0,0 +1,5 @@ +STUFF=$(shell find etc usr \! -type d -print) + +stamp: ${STUFF} + tar cf - ${STUFF} | ssh boiler-monster "cd / && tar xvpf -" + touch $@ diff --git a/boiler-monster/mr3020/etc/init.d/stm32 b/boiler-monster/mr3020/etc/init.d/stm32 new file mode 100755 index 0000000..6dce9bf --- /dev/null +++ b/boiler-monster/mr3020/etc/init.d/stm32 @@ -0,0 +1,7 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2006 OpenWrt.org + +START=99 +boot() { + /etc/stm32/startup > /var/log/stm32.log +} diff --git a/boiler-monster/mr3020/etc/rc.d/S99stm32 b/boiler-monster/mr3020/etc/rc.d/S99stm32 new file mode 120000 index 0000000..a3b0774 --- /dev/null +++ b/boiler-monster/mr3020/etc/rc.d/S99stm32 @@ -0,0 +1 @@ +../init.d/stm32 \ No newline at end of file diff --git a/boiler-monster/mr3020/etc/stm32/startup b/boiler-monster/mr3020/etc/stm32/startup new file mode 100755 index 0000000..9422745 --- /dev/null +++ b/boiler-monster/mr3020/etc/stm32/startup @@ -0,0 +1,50 @@ +#!/bin/sh + +logger -t stm32 "startup" + +LOCK=/var/lock/LCK..ttyATH0 +echo $$ > ${LOCK}.tmp + +#killall -9 ser2net + +FW="/etc/stm32/boiler.fw" +TFW="/tmp/stm32.fw" + +PORT="/dev/ttyATH0" + +echo 5 > /sys/class/gpio/export +echo out > /sys/class/gpio/gpio5/direction + +for i in $(seq 0 20); do + echo 1 > /sys/class/leds/tp-link\:green\:wps/brightness + echo 0 > /sys/class/leds/tp-link\:green\:wps/brightness + + if stm32flash "${PORT}"; then + break + fi + sleep 1 +done + +if [ -z "$1" ]; then + logger -t stm32 "reading ROM" + if ! stm32flash -r "${TFW}" "${PORT}" ; then + exit 1 + fi + + if diff -q "${TFW}" "${FW}"; then + logger -t stm32 "Code in ROM matches file" + echo "Code in ROM matches file" + else + logger -t stm32 "Flashing" + echo "Code in ROM doesn't match file, flashing" + stm32flash -w "${FW}" "${PORT}" + fi +else + echo "Flashing..." + stm32flash -w "$1" "${PORT}" +fi + +logger -t stm32 "Booting" +stm32flash -g 0 "${PORT}" + +rm -f ${LOCK} diff --git a/boiler-monster/mr3020/stamp b/boiler-monster/mr3020/stamp new file mode 100644 index 0000000..e69de29 diff --git a/boiler-monster/mr3020/usr/bin/thermostat b/boiler-monster/mr3020/usr/bin/thermostat new file mode 100755 index 0000000..1689964 --- /dev/null +++ b/boiler-monster/mr3020/usr/bin/thermostat @@ -0,0 +1,70 @@ +#!/bin/sh + +LOCK=/var/lock/LCK..ttyATH0 +M=10.32.139.1 + +WATERS=0 +MAX=70 + +# conventions +# POWER is power to valve coil +# OPEN is valve state +# DELTA is temp difference +# var1 is low set point +# var2 is high set point +# var3 is manual override + +# towel radiators + +for i in laundry_radiator bathroom_radiator; do + O="$(mosquitto_sub -t stat/$i/OPEN -h ${M} -W 1 -C 1)" + + W=0 + if [ "$O" == "1" ]; then + W=$MAX + fi + WATERS="$WATERS $W" + + logger -t thermostat " $i O=$O W=$W" +done + +#... others where we care about the delta + +for i in kstudy_radiator bedroom_radiator spare_bedroom_radiator dd_radiator1 dd_radiator2 dd_radiator3 hall_radiator kitchen_radiator music_room_radiator; do + O="$(mosquitto_sub -t stat/$i/OPEN -h ${M} -W 1 -C 1)" + D="$(mosquitto_sub -t stat/$i/DELTA -h ${M} -W 1 -C 1 | sed -e 's/\..*$//g') " + + W=0 + if [ "$O" == "1" ]; then + W=$[ $D * 3 + 40] + fi + + logger -t thermostat " $i O=$O D=$D W=$W" + + WATERS="$WATERS $W" +done + + +R=0 +for w in ${WATERS}; do + if [ $w -gt $R ]; then + R=$w + fi +done + +if [ $R -gt $MAX ]; then + R=$MAX +fi + + + + +if [ ! -f "${LOCK}" ]; then + logger -t thermostat "Requesting water temp of $R" + printf "\nCH=%d\n" $R > /dev/ttyATH0 +else + logger -t thermostat "Interface is locked, so cant request water temp of $R" +fi + + + -- cgit v1.2.3