Files
usbserial-dw/openwrt/files/usbserial-dw.sh
2021-10-15 18:55:13 +02:00

63 lines
2.0 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2018 wongsyrone
. /lib/functions.sh
PROG=/usr/bin/usbserial-dw
CURL=/usr/bin/curl
parse_capture() {
local section="$1"
local _port
local _speed
local _dir
local _file
config_get _port "$section" "port"
config_get _speed "$section" "speed"
config_get _dir "$section" "directory"
config_get _file "$section" "file"
config_get _url "$section" "url"
echo $PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
$PROG --port $_port --speed $_speed --path $_dir --file $_file --capture
cd $_dir
echo $CURL -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
$CURL -X POST -F "submit=OK" -F "file=@camera.jpg" $_url
rm $_file
}
parse_post() {
local section="$1"
local _host
local _topic
local _mqtt_prg
config_get _host "$section" "host"
config_get _topic "$section" "topic"
config_get _mqtt_prg "$section" "mqtt_prg"
_tmp=`$PROG --temperature`
_hum=`$PROG --humidity`
_pre=`$PROG --pressure`
echo $_mqtt_prg -h $_host -t $_topic/temperature -m N:${_tmp}
$_mqtt_prg -h $_host -t $_topic/temperature -m N:${_tmp}
echo $_mqtt_prg -h $_host -t $_topic/humidity -m N:${_hum}
$_mqtt_prg -h $_host -t $_topic/humidity -m N:${_hum}
echo $_mqtt_prg -h $_host -t $_topic/pressure -m N:${_pre}
$_mqtt_prg -h $_host -t $_topic/pressure -m N:${_pre}}
}
start() {
echo "[OK] Starting USB serial"
config_load usbserial
config_foreach parse_capture capture
config_foreach parse_post post
}
stop() {
echo "[OK] Stoping USB serial"
killall -9 $PROG
}