dec2018working

This commit is contained in:
ivan 2018-12-23 19:13:13 +03:00
parent c185c20a79
commit 8891ac2b95
19 changed files with 246 additions and 62 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
Salad testing faust-box files for OrangePi WinPlus
======
![saladtestingbox](https://dev.ussr.win/faust/saladtestingbox/raw/branch/master/saladtestingbox.jpg)

99
controller.ino Normal file
View File

@ -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 <Thread.h>
#include <OneWire.h> // DS18B20 temp sensor
#include <DallasTemperature.h>
#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);
}

6
crontab.txt Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,4 +0,0 @@
#!/bin/sh
# channel 1 off
echo 1 >/sys/class/gpio/gpio36/value

View File

@ -1,4 +0,0 @@
#!/bin/sh
# channel 1 on
echo 0 >/sys/class/gpio/gpio36/value

View File

@ -1,4 +0,0 @@
#!/bin/sh
# channel 2 off
echo 1 >/sys/class/gpio/gpio37/value

View File

@ -1,4 +0,0 @@
#!/bin/sh
# channel 2 on
echo 0 >/sys/class/gpio/gpio37/value

View File

@ -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

View File

@ -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

2
salad/compoff.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo "226" > /dev/ttyUSB0

2
salad/compon.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo "216" > /dev/ttyUSB0

View File

@ -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

View File

@ -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

5
salad/watering.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
cd /salad
echo "215" > /dev/ttyUSB0
sleep 2.5
echo "225" > /dev/ttyUSB0

BIN
saladtestingbox.fzz Normal file

Binary file not shown.

BIN
saladtestingbox.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

View File

@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="refresh" content="900" />
<title>system page</title>
<style type="text/css" media="screen">
body { background: #e7e7e7; font-family: Verdana, sans-serif; font-size: 11pt; }
#page { background: #ffffff; margin: 50px; border: 2px solid #c0c0c0; padding: 10px; }
#header { background: #4b6983; border: 2px solid #7590ae; text-align: center; padding: 10px; color: #ffffff; }
#header h1 { color: #ffffff; }
#body { padding: 10px; }
span.tt { font-family: monospace; }
span.bold { font-weight: bold; }
a:link { text-decoration: none; font-weight: bold; color: #C00; background: #ffc; }
a:visited { text-decoration: none; font-weight: bold; color: #999; background: #ffc; }
a:active { text-decoration: none; font-weight: bold; color: #F00; background: #FC0; }
a:hover { text-decoration: none; color: #C00; background: #FC0; }
</style>
</head>
<body>
<div id="page">
<div id="header">
<p align="center">
<img src="lastimage.jpg" width="640">
</p>
</div>
<div id="body">
<p align="center">
<iframe src="/sys/log.txt" width="640"></iframe>
</p>
</div>
</div>
</body>
</html>