summaryrefslogtreecommitdiffstats
path: root/boiler-monster/mr3020
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
committerfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
commit9d87c925a9eaa4fc256be3173c14a20d1469472d (patch)
tree50d63f87a47a0eac3f5b8058850184bcd4e6ee95 /boiler-monster/mr3020
parentdafd8cf2fdcdd637cc06f760d318cf8391b1a294 (diff)
downloadheating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.gz
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.bz2
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.zip
everything, mostly, working
Diffstat (limited to 'boiler-monster/mr3020')
-rw-r--r--boiler-monster/mr3020/.gitignore1
-rw-r--r--boiler-monster/mr3020/Makefile5
-rwxr-xr-xboiler-monster/mr3020/etc/init.d/stm327
l---------boiler-monster/mr3020/etc/rc.d/S99stm321
-rwxr-xr-xboiler-monster/mr3020/etc/stm32/startup50
-rw-r--r--boiler-monster/mr3020/stamp0
-rwxr-xr-xboiler-monster/mr3020/usr/bin/thermostat70
7 files changed, 134 insertions, 0 deletions
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
--- /dev/null
+++ b/boiler-monster/mr3020/stamp
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
+
+
+