#!/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]}" touch $install_dir/lock file=$(date +%Y%m%d%H%M%S)-$(uuidgen) for ((i=1 ; i <=3 ; i++));do 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 else echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener informaciĆ³n." >> $log && sleep 1 fi done