diff --git a/README.md b/README.md new file mode 100644 index 0000000..75ba212 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Salad testing faust-box files for OrangePi WinPlus +====== +![saladtestingbox](https://dev.ussr.win/faust/saladtestingbox/raw/branch/master/saladtestingbox.jpg) diff --git a/controller.ino b/controller.ino new file mode 100644 index 0000000..a703920 --- /dev/null +++ b/controller.ino @@ -0,0 +1,99 @@ +// 8-channel relay on arduino serial control with led blink with DS18B20 +// v0.1 under dwtwl +// ch1 = pin2; ch2 = pin3; ch3 = pin4; ch4 = pin5; +// ch5 = pin6; ch6 = pin7; ch7 = pin8; ch8 = pin9; led = pin13; +// send: switch on = 21X; switch off = 22X; get status = 23X; +// codes: in = init; eX = enabled; dX = disabled; tX = power on; fX = off; +#include +#include // DS18B20 temp sensor +#include +#define ONE_WIRE_BUS 10 +OneWire oneWire(ONE_WIRE_BUS); +DallasTemperature sensors(&oneWire); +Thread ledThread = Thread(); + +int incomingNumber = 0; + +void setup() { + Serial.begin(9600); + pinMode(13, OUTPUT); + for(int i=2;i<10;i++){ + pinMode(i, OUTPUT); + digitalWrite(i, HIGH); + } + Serial.println("in"); + + ledThread.onRun(ledBlink); + ledThread.setInterval(1000); + + sensors.begin(); + +} + +void ledBlink() { + static bool ledStatus = false; + ledStatus = !ledStatus; + digitalWrite(13, ledStatus); +} + +void loop() { + // Thread init: + if (ledThread.shouldRun()) + ledThread.run(); + + if (Serial.available() > 0) { + int incomingByte = Serial.read()-48; + if (incomingByte>=0 && incomingByte<=9) { + incomingNumber=incomingNumber*10+incomingByte; + } else { + if (incomingNumber>=210 && incomingNumber<=219) { + delay(500); + int currentPin = incomingNumber - 209; + char currentChannel[] = "e0"; + currentChannel[1] = '0' + (currentPin - 1); + digitalWrite(currentPin, LOW); + Serial.println(currentChannel); + delay(500); + } + + if (incomingNumber>=220 && incomingNumber<=229) { + delay(500); + int currentPin = incomingNumber - 219; + char currentChannel[] = "d0"; + currentChannel[1] = '0' + (currentPin - 1); + digitalWrite(currentPin, HIGH); + Serial.println(currentChannel); + delay(500); + } + + if (incomingNumber>=230 && incomingNumber<=239) { + delay(500); + int currentPin = incomingNumber - 229; + if (digitalRead(currentPin)==HIGH) { + char currentChannel[] = "f0"; + currentChannel[1] = '0' + (currentPin - 1); + Serial.println(currentChannel); + } else { + char currentChannel[] = "t0"; + currentChannel[1] = '0' + (currentPin - 1); + Serial.println(currentChannel); + } + delay(500); + } + + if (incomingNumber == 99) { + int sensorData = readDS18B20(); + String temperature = "t"; + String stringToPrint = temperature + sensorData; + Serial.println(stringToPrint); + } + incomingNumber = 0; + } + } +} + +// DS18B20 Temperature +float readDS18B20() { + sensors.requestTemperatures(); // Send the command to get temperature readings + return sensors.getTempCByIndex(0); +} diff --git a/crontab.txt b/crontab.txt new file mode 100644 index 0000000..562c6b3 --- /dev/null +++ b/crontab.txt @@ -0,0 +1,6 @@ +*/2 * * * * sh /salad/checkled2.sh +01 02,10,18 * * * sh /salad/screenshot.sh +02,05 02,10,18 * * * sh /salad/watering.sh +03 01,05,09,13,17,21 * * * sh /salad/compon.sh +03 03,07,11,15,19,23 * * * sh /salad/compoff.sh +00,15,30,45 * * * * sh /salad/chtemphum.sh diff --git a/etc/systemd/system/opi.service b/etc/systemd/system/opi.service new file mode 100644 index 0000000..b441fd8 --- /dev/null +++ b/etc/systemd/system/opi.service @@ -0,0 +1,11 @@ +[Unit] +Description=Opi Service +After=network.target + +[Service] +Type=oneshot +User=root +ExecStart=/salad/gpioinit.sh + +[Install] +WantedBy=multi-user.target diff --git a/salad/SCRBLUE.sh b/salad/SCRBLUE.sh deleted file mode 100755 index 5a1f5a2..0000000 --- a/salad/SCRBLUE.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# files and dirs for backup: -SAVEDIR=/salad/screenshots/ -DATETIME=`date "+%Y-%m-%d-%H-%M-%S"` -ffmpeg -rtsp_transport tcp -i 'rtsp://ip.of.web.cam/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p ${SAVEDIR}${DATETIME}.jpeg diff --git a/salad/ch1off.sh b/salad/ch1off.sh deleted file mode 100755 index 7b511bb..0000000 --- a/salad/ch1off.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# channel 1 off -echo 1 >/sys/class/gpio/gpio36/value - diff --git a/salad/ch1on.sh b/salad/ch1on.sh deleted file mode 100755 index b6e822c..0000000 --- a/salad/ch1on.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# channel 1 on -echo 0 >/sys/class/gpio/gpio36/value - diff --git a/salad/ch2off.sh b/salad/ch2off.sh deleted file mode 100755 index 142fdce..0000000 --- a/salad/ch2off.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# channel 2 off -echo 1 >/sys/class/gpio/gpio37/value - diff --git a/salad/ch2on.sh b/salad/ch2on.sh deleted file mode 100755 index 50b55fc..0000000 --- a/salad/ch2on.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# channel 2 on -echo 0 >/sys/class/gpio/gpio37/value - diff --git a/salad/checkled.sh b/salad/checkled.sh index e81d934..b537078 100755 --- a/salad/checkled.sh +++ b/salad/checkled.sh @@ -1,18 +1,19 @@ #!/bin/sh HOUR=`date "+%H"` -CH1STATUS=`gpio read 21` cd /salad -if [ "$HOUR" = "10" ] || [ "$HOUR" = "11" ] || [ "$HOUR" = "12" ] || [ "$HOUR" = "13" ] +echo "231" > /dev/ttyUSB0 +LEDST=`dd if=/dev/ttyUSB0 count=1` +CH1STATUS="$(echo "${LEDST}" | tr -d '1')" + +if [ "$HOUR" = "10" ] || [ "$HOUR" = "11" ] || [ "$HOUR" = "12" ] || [ "$HOUR" = "13" ] || [ "$HOUR" = "14" ] || [ "$HOUR" = "15" ] || [ "$HOUR" = "16" ] || [ "$HOUR" = "17" ] then - if [ "$CH1STATUS" = "0" ]; then - echo $CH1STATUS - sh ch1off.sh - echo off + if [ "$CH1STATUS" = "t" ]; then + echo "221" > /dev/ttyUSB0 + echo "led off" fi else - if [ "$CH1STATUS" = "1" ]; then - echo $CH1STATUS - sh ch1on.sh - echo on + if [ "$CH1STATUS" = "f" ]; then + echo "211" > /dev/ttyUSB0 + echo "led on" fi fi diff --git a/salad/chtemphum.sh b/salad/chtemphum.sh index 34c4131..629ef5a 100755 --- a/salad/chtemphum.sh +++ b/salad/chtemphum.sh @@ -1,7 +1,62 @@ #!/bin/sh cd /salad DATETIME=`date "+%Y-%m-%d-%H-%M"` -HUM=`dht22 -p 38 -s hum` -sleep 1 -TEMP=`dht22 -p 38 -s temp` -echo "$DATETIME HUM = $HUM TEMP = $TEMP" >> SALAD_log.txt +COUNT=0 +while (!(echo "$TEMP" | grep -E -q "^-?[0-9]+([.][0-9]+)?$")) +do + COUNT=`expr $COUNT + 1` + TEMP=`dht22 -p 38 -s temp` + sleep 2 + if [ "$COUNT" -eq 10 ] + then + break + fi +done +COUNT=0 +while (!(echo "$HUM" | grep -E -q "^-?[0-9]+([.][0-9]+)?$")) +do + COUNT=`expr $COUNT + 1` + HUM=`dht22 -p 38 -s hum` + sleep 2 + if [ "$COUNT" -eq 10 ] + then + break + fi +done + +echo "99" > /dev/ttyUSB0 +WATER=`dd if=/dev/ttyUSB0 count=1` +WATERTEMP="$(echo "${WATER}" | tr -d 't')" + +if [ "$COUNT" -eq 10 ] +then + echo "Couldn't read temp/hum" +else + echo "$DATETIME HUM = $HUM TEMP = $TEMP WATER = $WATERTEMP" >> SALAD_log.txt +fi + +# air heater: +TEMPINT=${TEMP%.*} +if [ "$TEMPINT" -gt 21 ] +then + echo "224" > /dev/ttyUSB0 + echo "ST $DATETIME 224 - AIR HEAT OFF" >> SALAD_log.txt +fi +if [ "$TEMPINT" -lt 19 ] +then + echo "214" > /dev/ttyUSB0 + echo "ST $DATETIME 214 - AIR HEAT ON" >> SALAD_log.txt +fi +# water heater: +if [ "$WATERTEMP" -gt 21 ] +then + echo "227" > /dev/ttyUSB0 + echo "ST $DATETIME 227 - WATER HEAT OFF" >> SALAD_log.txt +fi +if [ "$WATERTEMP" -lt 19 ] +then + echo "217" > /dev/ttyUSB0 + echo "ST $DATETIME 217 - WATER HEAT ON" >> SALAD_log.txt +fi + +cp /salad/SALAD_log.txt /var/www/html/sys/log.txt diff --git a/salad/compoff.sh b/salad/compoff.sh new file mode 100755 index 0000000..dca408a --- /dev/null +++ b/salad/compoff.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "226" > /dev/ttyUSB0 diff --git a/salad/compon.sh b/salad/compon.sh new file mode 100755 index 0000000..253272a --- /dev/null +++ b/salad/compon.sh @@ -0,0 +1,2 @@ +#!/bin/sh +echo "216" > /dev/ttyUSB0 diff --git a/salad/gpioinit.sh b/salad/gpioinit.sh index 9559c65..b170eb1 100755 --- a/salad/gpioinit.sh +++ b/salad/gpioinit.sh @@ -2,29 +2,11 @@ ntpdate -q 0.rhel.pool.ntp.org -echo 361 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio361/direction -echo 1 >/sys/class/gpio/gpio361/value - -echo 68 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio68/direction -echo 1 >/sys/class/gpio/gpio68/value - echo 36 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio36/direction -echo 1 >/sys/class/gpio/gpio36/value +echo in >/sys/class/gpio/gpio36/direction echo 37 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio37/direction -echo 1 >/sys/class/gpio/gpio37/value - -echo 39 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio39/direction -echo 1 >/sys/class/gpio/gpio39/value - -echo 101 >/sys/class/gpio/export -echo out >/sys/class/gpio/gpio101/direction -echo 1 >/sys/class/gpio/gpio101/value +echo in >/sys/class/gpio/gpio37/direction echo 38 >/sys/class/gpio/export echo in >/sys/class/gpio/gpio38/direction diff --git a/salad/screenshot.sh b/salad/screenshot.sh index 7262fd3..4c4fad3 100755 --- a/salad/screenshot.sh +++ b/salad/screenshot.sh @@ -2,16 +2,20 @@ # 10-15sec for photo SAVEDIR=/salad/screenshots/ DATETIME=`date "+%Y-%m-%d-%H-%M-%S"` -CH1STATUS=`gpio read 21` +echo "231" > /dev/ttyUSB0 +LEDST=`dd if=/dev/ttyUSB0 count=1` +CH1STATUS="$(echo "${LEDST}" | tr -d '1')" cd /salad -./ch2on.sh +echo "213" > /dev/ttyUSB0 sleep 0.5 -./ch1off.sh -sleep 9 +echo "221" > /dev/ttyUSB0 +sleep 8 ffmpeg -rtsp_transport tcp -i 'rtsp://ip.of.web.cam/user=admin&password=&channel=1&stream=0.sdp' -f image2 -vframes 1 -pix_fmt yuvj420p ${SAVEDIR}${DATETIME}.jpeg -if [ "$CH1STATUS" = 0 ] +if [ "$CH1STATUS" = "t" ] then - ./ch1on.sh + echo "211" > /dev/ttyUSB0 fi sleep 0.1 -./ch2off.sh +echo "223" > /dev/ttyUSB0 +# copy +cp ${SAVEDIR}${DATETIME}.jpeg /var/www/html/sys/lastimage.jpg diff --git a/salad/watering.sh b/salad/watering.sh new file mode 100755 index 0000000..ef6c3a5 --- /dev/null +++ b/salad/watering.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd /salad +echo "215" > /dev/ttyUSB0 +sleep 2.5 +echo "225" > /dev/ttyUSB0 diff --git a/saladtestingbox.fzz b/saladtestingbox.fzz new file mode 100644 index 0000000..76c24bb Binary files /dev/null and b/saladtestingbox.fzz differ diff --git a/saladtestingbox.jpg b/saladtestingbox.jpg new file mode 100644 index 0000000..aa85809 Binary files /dev/null and b/saladtestingbox.jpg differ diff --git a/var/www/html/sys/index.html b/var/www/html/sys/index.html new file mode 100644 index 0000000..2318407 --- /dev/null +++ b/var/www/html/sys/index.html @@ -0,0 +1,35 @@ + + + + + +system page + + + +
+ +
+

+ +

+
+
+ +