2022-02-23 14:42:32 +00:00
#!/bin/bash
source /etc/nodemecu.conf
case $mode in
test )
lecturas = " id:dummy_plug-01 ts: $( date +%s) tp:temp vl: $(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR ts: $( date +%s) tp:hum vl: $(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-02 ts: $( date +%s) tp:temp vl: $(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR ts: $( date +%s) tp:hum vl: $(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-03 ts: $( date +%s) tp:temp vl: $(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR ts: $( date +%s) tp:hum vl: $(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-04 ts: $( date +%s) tp:temp vl: $(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR ts: $( date +%s) tp:hum vl: $(( $RANDOM % 50 + 35 )) un:percent er:99 END "
; ;
esac
for i in $lecturas ; do
case $i in
id*)
sensores = " $sensores { $( echo \" id\" :\" $( echo $i | cut -d ":" -f 2) \" , \" sensores\" : [ ) "
; ;
ts*)
sensores = " $sensores { $( echo \" timestamp\" : $( echo $i | cut -d ":" -f 2) ,) "
; ;
tp*)
sensores = " $sensores $( echo \" type\" : \" $( echo $i | cut -d ":" -f 2) \" ,) "
; ;
vl*)
sensores = " $sensores $( echo \" value\" : $( echo $i | cut -d ":" -f 2) ,) "
; ;
un*)
sensores = " $sensores $( echo \" unit\" : \" $( echo $i | cut -d ":" -f 2) \" ,) "
; ;
er*)
sensores = " $sensores $( echo \" error\" : $( echo $i | cut -d ":" -f 2) } ) "
; ;
AD_SENSOR)
sensores = " $sensores , "
; ;
AD_ARDUINO)
sensores = " $sensores ]}, "
; ;
END)
sensores = " $sensores ]} "
; ;
esac
done
counter = $( cat $install_dir /counter)
uuid = " $( uuidgen) "
timestamp = " $( date +%s) "
json = " {\"transaction_uuid\":\" $uuid \",\"controller_id\":\" $name \",\"timestamp\":\" $timestamp \",\"error_code\":\"10\",\"coordinates\":{\"lat\":1,\"lng\":1},\"battery_status\":\"98\",\"sample\":\"0\",\"storage\":\"uso del almacenamiento\",\"arduinos\":[ $sensores ]} "
2022-03-03 17:11:32 +00:00
touch $install_dir /lock
2022-03-03 17:53:01 +00:00
file = $( date +%Y%m%d%H%M%S) -$uuid
2022-02-23 14:42:32 +00:00
for ( ( i = 1 ; i <= 3 ; i++) ) ; do
2022-03-03 17:28:11 +00:00
if echo $json | $json_linter >/dev/null 2>& 1 ; then
echo $json > $install_dir /stack/$file && rm $install_dir /lock && echo $(( counter+1)) > $install_dir /counter && break
2022-02-23 14:42:32 +00:00
else
2022-03-03 17:33:24 +00:00
echo " $( date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información. " >> $log && sleep 1
2022-02-23 14:42:32 +00:00
fi
done