70 lines
1.6 KiB
Bash
Executable file
70 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source /etc/nodemecu.conf
|
|
source /opt/nodemecu/envs
|
|
source $funciones
|
|
|
|
test -z $nombre && exit
|
|
test -f $public_key || exit
|
|
|
|
uuid="$(uuid)"
|
|
marca_de_tiempo="$(date +%s)"
|
|
|
|
|
|
case $modo in
|
|
test)
|
|
funcion_datos_simulados
|
|
;;
|
|
sensores)
|
|
funcion_datos_sensores
|
|
;;
|
|
esac
|
|
|
|
|
|
# ARMADO DE FICHERO JSON
|
|
|
|
for i in $lecturas;do
|
|
case $i in
|
|
id*)
|
|
sensores="$sensores { $(echo \"id\":\"$(echo $i | cut -d ":" -f 2)\", \"sensores\": [ )"
|
|
;;
|
|
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
|
|
|
|
sensores=$(echo $sensores | tr -d '[:blank:]')
|
|
|
|
json="{\"transaction_uuid\":\"$uuid\",\"serial_number\":\"$numero_serie\",\"public_key\":\"$(cat $public_key)\",\"controller_id\":\"$nombre\",\"timestamp\":\"$marca_de_tiempo\",\"error_code\":\"10\",\"coordinates\":{\"lat\":1,\"lng\":1},\"battery_status\":\"98\",\"sample\":\"0\",\"storage\":\"uso del almacenamiento\",\"arduinos\":[$sensores]}"
|
|
|
|
touch $lock
|
|
file=$(date +%Y%m%d%H%M%S -d @$marca_de_tiempo)-$uuid
|
|
|
|
if funcion_validador_json $json ;then
|
|
echo $json > $registros/$file && rm $lock
|
|
else
|
|
echo "$(date +%Y-%m-%d-%H:%M:%S -d @$marca_de_tiempo) - No se pudo generar fichero json:" >> $log
|
|
echo $json >> $log
|
|
rm $lock
|
|
fi
|
|
|
|
|