Compare commits
No commits in common. "9a98c0c9d8212fbe47e6c41905888072106b2e49" and "00ee8245aca431ed91e4a9b513f61f7d01322866" have entirely different histories.
9a98c0c9d8
...
00ee8245ac
|
@ -7,9 +7,7 @@ fi
|
||||||
# LECTURA FICHERO DE CONFIGURACION
|
# LECTURA FICHERO DE CONFIGURACION
|
||||||
|
|
||||||
config=/etc/nodemecu.conf
|
config=/etc/nodemecu.conf
|
||||||
envs=/opt/nodemecu/envs
|
|
||||||
source $config
|
source $config
|
||||||
source $envs
|
|
||||||
source $funciones
|
source $funciones
|
||||||
|
|
||||||
[ -z $1 ] && exit
|
[ -z $1 ] && exit
|
||||||
|
@ -36,8 +34,7 @@ case $com in
|
||||||
echo ""
|
echo ""
|
||||||
echo "Creando juego de llaves"
|
echo "Creando juego de llaves"
|
||||||
source $config
|
source $config
|
||||||
comentario="$nombre $numero_serie"
|
generate_private_key
|
||||||
generate_private_key "$comentario"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "El modo de operación por defecto es 'test' y se envían datos simulados, cambie a 'sensores' con el comando 'sudo nodemecu modo sensores'
|
echo "El modo de operación por defecto es 'test' y se envían datos simulados, cambie a 'sensores' con el comando 'sudo nodemecu modo sensores'
|
||||||
"
|
"
|
||||||
|
|
1
raspberry/contador
Normal file
1
raspberry/contador
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0
|
|
@ -1,12 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source /etc/nodemecu.conf
|
source /etc/nodemecu.conf
|
||||||
source /opt/nodemecu/envs
|
|
||||||
if [ $UID -ne 0 ]; then
|
if [ $UID -ne 0 ]; then
|
||||||
echo "Ejecute 'sudo $0'"
|
echo "Ejecute 'sudo $0'"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
seguro="Si, se lo que estoy haciendo."
|
seguro="Si, Estoy Seguro."
|
||||||
|
|
||||||
|
|
||||||
echo "Está a punto de desinstalar nodemecu, esta acción eliminará todos los archivos de instalacion y registros que se hayan tomado sin posiblidad de recuperación, haga un backup de:
|
echo "Está a punto de desinstalar nodemecu, esta acción eliminará todos los archivos de instalacion y registros que se hayan tomado sin posiblidad de recuperación, haga un backup de:
|
||||||
|
@ -18,9 +18,9 @@ echo "Está a punto de desinstalar nodemecu, esta acción eliminará todos los a
|
||||||
Para continuar escriba la frase '$seguro'.
|
Para continuar escriba la frase '$seguro'.
|
||||||
"
|
"
|
||||||
|
|
||||||
#read -p "frase: " frase
|
read -p "frase: " frase
|
||||||
|
|
||||||
#if [ "$frase" = "$seguro" ];then
|
if [ "$frase" = "$seguro" ];then
|
||||||
|
|
||||||
|
|
||||||
rm /etc/nodemecu.conf
|
rm /etc/nodemecu.conf
|
||||||
|
@ -32,8 +32,8 @@ systemctl disable nodemecu.service
|
||||||
rm /lib/systemd/system/nodemecu.service
|
rm /lib/systemd/system/nodemecu.service
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
#else
|
else
|
||||||
echo "La frase de seguridad no concuerda.
|
echo "La frase de seguridad no concuerda.
|
||||||
"
|
"
|
||||||
|
|
||||||
#fi
|
fi
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
# NO MODIFICAR ESTE FICHERO !!!!!!!!!!
|
|
||||||
|
|
||||||
numero_serie=
|
|
||||||
curl_err=/tmp/curl_err
|
|
||||||
historical_file_size=1440
|
|
||||||
logs_file_size=1440
|
|
||||||
directorio_instalacion=/opt/nodemecu
|
|
||||||
registros=$directorio_instalacion/registros
|
|
||||||
historicos=$directorio_instalacion/historicos
|
|
||||||
log=/var/log/nodemecu_errors.log
|
|
||||||
registros_corruptos=$directorio_instalacion/corruptos
|
|
||||||
envios_fallidos=$directorio_instalacion/fallidos
|
|
||||||
contador=$directorio_instalacion/contador
|
|
||||||
lock=$directorio_instalacion/lock
|
|
||||||
funciones=$directorio_instalacion/funciones
|
|
||||||
arduinos_py=$directorio_instalacion/arduinos.py
|
|
||||||
key_dir=$directorio_instalacion/llaves
|
|
||||||
private_key=$key_dir/$numero_serie.key
|
|
||||||
public_key=$key_dir/$numero_serie.key.pub
|
|
|
@ -2,32 +2,40 @@
|
||||||
#set -x
|
#set -x
|
||||||
get_stack () {
|
get_stack () {
|
||||||
if [[ ! -z $1 && $1 == "wc" ]];then
|
if [[ ! -z $1 && $1 == "wc" ]];then
|
||||||
ls -I "*.sig" $registros | wc -l
|
ls -I "*.sign" $registros | wc -l
|
||||||
else
|
else
|
||||||
ls -I "*.sig" $registros | tail -1
|
ls -I "*.sign" $registros | tail -1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Generar una llave privada ECDSA si no existe
|
# Generar una llave privada ECDSA si no existe
|
||||||
generate_private_key () {
|
generate_private_key () {
|
||||||
test -f "$private_key" && return 1
|
test -f "$private_key" && return 1
|
||||||
|
|
||||||
ssh-keygen -t ecdsa -f "$private_key" -N "" -C "$@"
|
ssh-keygen -t ecdsa -f "$private_key" -N "" -m PEM
|
||||||
}
|
}
|
||||||
|
|
||||||
# Firmar el archivo usando la llave privada.
|
# Firmar el archivo usando la llave privada.
|
||||||
#
|
#
|
||||||
# Uso: sign_file archivo.json
|
# Uso: sign_file archivo.json
|
||||||
# Devuelve: La firma
|
# Devuelve: archivo.json.sign
|
||||||
sign_file () {
|
sign_file () {
|
||||||
local _file="$1"
|
local _file="$1"
|
||||||
|
|
||||||
test ! -f "$_file" && return 1
|
test ! -f "$_file" && return 1
|
||||||
test -f "$_file.sig" || ssh-keygen -Y sign -f "$private_key" -n file "$_file" >/dev/null 2>&1
|
|
||||||
cat "${_file}.sig" | grep -v SIGNATURE | tr -d "\n"
|
if ! openssl dgst -sha512 -sign "$private_key" "$_file" | base64 | tr -d "\n" > "$_file.sign" ; then
|
||||||
|
rm -f "$_file.sign"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$_file.sign"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
funcion_datos_simulados() {
|
funcion_datos_simulados() {
|
||||||
|
|
||||||
lecturas="id:dummy_plug-01 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-02 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-03 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-04 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 END"
|
lecturas="id:dummy_plug-01 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-02 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-03 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 AD_ARDUINO id:dummy_plug-04 tp:temp vl:$(( $RANDOM % 20 + 15 )) un:C er:99 AD_SENSOR tp:hum vl:$(( $RANDOM % 50 + 35 )) un:percent er:99 END"
|
||||||
|
@ -169,42 +177,3 @@ funcion_captura() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
funcion_validador_json() {
|
|
||||||
|
|
||||||
validar="$@"
|
|
||||||
|
|
||||||
echo $validar | jsonlint-php > /dev/null 2>&1 || return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
funcion_verificar_internet() {
|
|
||||||
|
|
||||||
if host fsf.org > /dev/null 2>&1; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
funcion_espera() {
|
|
||||||
|
|
||||||
sleep ${intervalo:-1}m
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
funcion_envio_registro() {
|
|
||||||
|
|
||||||
curl -s --show-error -w "~%{http_code}" \
|
|
||||||
-X POST -H "X-Signature: $(sign_file $registros/$file)" \
|
|
||||||
-H "Content-Type: application/json" -d @$registros/$file \
|
|
||||||
$servidor 2> $curl_err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source /etc/nodemecu.conf
|
source /etc/nodemecu.conf
|
||||||
source /opt/nodemecu/envs
|
|
||||||
source $funciones
|
source $funciones
|
||||||
|
|
||||||
conteo=$(cat $contador)
|
conteo=$(cat $contador)
|
||||||
uuid="$(uuid)"
|
uuid="$(uuidgen)"
|
||||||
marca_de_tiempo="$(date +%s)"
|
marca_de_tiempo="$(date +%s)"
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,17 +52,29 @@ done
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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]}"
|
json="{\"transaction_uuid\":\"$uuid\",\"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
|
touch $lock
|
||||||
file=$(date +%Y%m%d%H%M%S -d @$marca_de_tiempo)-$uuid
|
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
|
|
||||||
|
if echo $json | jsonlint-php 2> /dev/null;then
|
||||||
|
echo $json > $registros/$file && rm $lock && echo $((conteo+1)) > $contador
|
||||||
else
|
else
|
||||||
echo "$(date +%Y-%m-%d-%H:%M:%S -d @$marca_de_tiempo) - No se pudo generar fichero json:" >> $log
|
echo "$(date +%Y-%m-%d-%H:%M:%S -d @$marca_de_tiempo) - No se pudo obtener información." >> $log
|
||||||
echo $json >> $log
|
|
||||||
rm $lock
|
rm $lock
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
# habia una razon para esto, ya va a saltar
|
||||||
|
|
||||||
|
for ((i=1 ; i <=3 ; i++));do
|
||||||
|
if echo $json | jsonlint-php 2> /dev/null;then
|
||||||
|
echo $json > /opt/nodemecu/stack/$file && rm /opt/nodemecu/lock && echo $((counter+1)) > $contador && break
|
||||||
|
else
|
||||||
|
echo "$(date +%Y-%m-%d-%H:%M:%S) - No se pudo obtener información." >> /opt/nodemecu/errors.log && sleep 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
|
@ -1,33 +1,28 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#set -x
|
#set -x
|
||||||
|
configuracion=nodemecu.conf.ejemplo
|
||||||
|
source $configuracion
|
||||||
|
|
||||||
if [ $UID -ne 0 ]; then
|
if [ $UID -ne 0 ]; then
|
||||||
echo "Ejecute 'sudo $0'"
|
echo "Ejecute 'sudo $0'"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
basedir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
||||||
|
|
||||||
configuracion=$basedir/nodemecu.conf.ejemplo
|
|
||||||
envs=$basedir/envs
|
|
||||||
|
|
||||||
source $configuracion
|
|
||||||
source $envs
|
|
||||||
|
|
||||||
if [ -d $directorio_instalacion ] ; then
|
if [ -d $directorio_instalacion ] ; then
|
||||||
echo "nodemecu ya se encuentra instalado"
|
echo "nodemecu ya se encuentra instalado"
|
||||||
exit
|
exit
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ficheros="bin envs arduinos.py generador_json funciones registrador desinstalar"
|
ficheros="bin arduinos.py contador generador_json funciones monitor monitor_web nodemecu.service registrador desinstalar"
|
||||||
|
|
||||||
|
|
||||||
# Dependencias
|
# Dependencias
|
||||||
|
|
||||||
echo "1. Instalando dependencias
|
echo "1. Instalando dependencias
|
||||||
"
|
"
|
||||||
#apt update && apt install -y python3-pip jsonlint jq uuid
|
apt update && apt install -y python3-pip jsonlint jq uuid
|
||||||
#pip3 install pyserial
|
pip3 install pyserial
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
@ -43,7 +38,7 @@ mkdir -v $registros_corruptos
|
||||||
mkdir -v $envios_fallidos
|
mkdir -v $envios_fallidos
|
||||||
mkdir -v $historicos
|
mkdir -v $historicos
|
||||||
mkdir -v $registros
|
mkdir -v $registros
|
||||||
mkdir -v $key_dir
|
mkdir -v $private_key_dir
|
||||||
echo "
|
echo "
|
||||||
Copiado de archivos
|
Copiado de archivos
|
||||||
"
|
"
|
||||||
|
@ -64,23 +59,12 @@ ls $log
|
||||||
echo "3. Configurando systemd
|
echo "3. Configurando systemd
|
||||||
"
|
"
|
||||||
|
|
||||||
cp -v nodemecu.service /lib/systemd/system/
|
cp nodemecu.service /lib/systemd/system/
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
|
||||||
echo "
|
|
||||||
4. Obteniendo numero de serie
|
|
||||||
"
|
|
||||||
|
|
||||||
sn=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)
|
|
||||||
|
|
||||||
sed -i 's/numero_serie=/numero_serie='$sn'/' $directorio_instalacion/envs
|
|
||||||
|
|
||||||
echo "Número de serie: $sn"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
5. Configurar
|
4. Configurar
|
||||||
"
|
"
|
||||||
|
|
||||||
echo "- Ejecute 'sudo nodemecu configurar' para comenzar.
|
echo "- Ejecute 'sudo nodemecu configurar' para comenzar.
|
||||||
|
|
16
raspberry/monitor
Executable file
16
raspberry/monitor
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source /etc/nodemecu.conf
|
||||||
|
while :;do
|
||||||
|
clear
|
||||||
|
echo "$(date)"
|
||||||
|
echo "Stack: $(ls $stack | wc -l) ficheros"
|
||||||
|
echo "Historicos: $(ls $historical | wc -l) ficheros"
|
||||||
|
echo "Testigo: $(cat $install_dir/counter)"
|
||||||
|
echo "Errores: $(wc -l $log) registros"
|
||||||
|
echo "Ultimo error registrado:"
|
||||||
|
tail -1 $log
|
||||||
|
echo ""
|
||||||
|
echo "'ctrl-c' para salir."
|
||||||
|
sleep 100
|
||||||
|
done
|
11
raspberry/monitor_web
Executable file
11
raspberry/monitor_web
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source /etc/nodemecu.conf
|
||||||
|
echo "<p>$(date)<br>"
|
||||||
|
echo "Stack: $(ls $stack | wc -l) ficheros<br>"
|
||||||
|
echo "Historicos: $(ls $historical | wc -l) ficheros<br>"
|
||||||
|
echo "Testigo: $(cat $install_dir/counter)<br>"
|
||||||
|
echo "Errores: $(wc -l $log) registros<br>"
|
||||||
|
echo "Ultimos errores registrados<br>"
|
||||||
|
tail -1 $log
|
||||||
|
echo "<br></p>"
|
|
@ -2,3 +2,23 @@ nombre=
|
||||||
servidor=
|
servidor=
|
||||||
intervalo=
|
intervalo=
|
||||||
modo=test
|
modo=test
|
||||||
|
|
||||||
|
|
||||||
|
# AJUSTES GENERALES
|
||||||
|
# SE RECOMIENDA NO MODIFICAR ESTAS LINEAS
|
||||||
|
|
||||||
|
curl_err=/tmp/curl_err
|
||||||
|
historical_file_size=1440
|
||||||
|
logs_file_size=1440
|
||||||
|
directorio_instalacion=/opt/nodemecu
|
||||||
|
registros=$directorio_instalacion/registros
|
||||||
|
historicos=$directorio_instalacion/historicos
|
||||||
|
log=/var/log/nodemecu_errors.log
|
||||||
|
registros_corruptos=$directorio_instalacion/corruptos
|
||||||
|
envios_fallidos=$directorio_instalacion/fallidos
|
||||||
|
contador=$directorio_instalacion/contador
|
||||||
|
lock=$directorio_instalacion/lock
|
||||||
|
funciones=$directorio_instalacion/funciones
|
||||||
|
arduinos_py=$directorio_instalacion/arduinos.py
|
||||||
|
private_key_dir=$directorio_instalacion/llaves
|
||||||
|
private_key=$private_key_dir/$nombre.pem
|
||||||
|
|
|
@ -1,79 +1,69 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#set -x
|
|
||||||
source /etc/nodemecu.conf
|
source /etc/nodemecu.conf
|
||||||
source /opt/nodemecu/envs
|
|
||||||
source $funciones
|
source $funciones
|
||||||
|
|
||||||
|
|
||||||
|
# Revisando stack
|
||||||
|
|
||||||
|
for registro_json in $registros/*;do
|
||||||
|
test "$registro_json" = "/opt/nodemecu/stack/\*" || break
|
||||||
|
jsonlint-php $registro_json > /dev/null || mv -v $registro_json $registros_corruptos
|
||||||
|
done
|
||||||
|
|
||||||
while :;do
|
while :;do
|
||||||
|
|
||||||
# archivo a procesar
|
# archivo a procesar
|
||||||
file=$(get_stack)
|
file=$(get_stack)
|
||||||
|
|
||||||
# si no hay nada que procesar reinicia el bucle
|
|
||||||
test -z $file && funcion_espera && continue
|
|
||||||
|
|
||||||
# si no hay servidor definido se reinicia el bucle
|
# si no hay servidor definido se reinicia el bucle
|
||||||
test -z $servidor && echo "No se configuró nigun servidor de entrega." && funcion_espera && continue
|
# espera el intervalo definido o 1 minuto.
|
||||||
|
#[ -z $servidor ] && echo "no se ha definido un servidor de entrega" && sleep ${intervalo:-1}m && continue
|
||||||
|
|
||||||
# si no hay internet reinica el bucle
|
|
||||||
if ! funcion_verificar_internet; then
|
# si no hay nada en el directorio registros reinicia el bucle
|
||||||
echo "Parece no haber internet."
|
# espera el intervalo definido o 1 minuto.
|
||||||
funcion_espera
|
[ -z $file ] && sleep ${intervalo:-1}m && continue
|
||||||
continue
|
|
||||||
fi
|
# si no respone el ping reinica el bucle
|
||||||
|
ping -c 1 fsf.org > /dev/null 2>&1 || continue
|
||||||
|
|
||||||
# si el fichero 'lock' existe (se esta creando un nuevo registro) reinicia el bucle
|
# si el fichero 'lock' existe (se esta creando un nuevo registro) reinicia el bucle
|
||||||
test -f $lock && continue
|
[ -f $lock ] && continue
|
||||||
|
|
||||||
# validación del fichero
|
|
||||||
if ! funcion_validador_json "$(cat $registros/$file)";then
|
|
||||||
mv $registros/$file $registros_corruptos
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# firmado de regisro
|
|
||||||
firma=$(sign_file $registros/$file)
|
|
||||||
|
|
||||||
# UUID del registro a enviar
|
|
||||||
uuid_registro=$(jq -r '."transaction_uuid"' $registros/$file)
|
|
||||||
|
|
||||||
# envio de registro
|
|
||||||
transaccion=$(curl -v -s --show-error -w "~%{http_code}" -X POST -H "X-Signature: $(sign_file $registros/$file)" -H "Content-Type: application/json" -d @$registros/$file $servidor 2> $curl_err)
|
|
||||||
|
|
||||||
# respuestas del servidor
|
|
||||||
respuesta_servidor="$(echo $transaccion | cut -d '~' -f 1)"
|
|
||||||
error_servidor="$(echo $transaccion | cut -d '~' -f 2)"
|
|
||||||
|
|
||||||
if [ ${#respuesta_servidor} -eq 36 ] && [ "$uuid_registro" == "$respuesta_servidor" ]; then
|
|
||||||
echo -e "$respuesta_servidor: \e[92mOK\e[0m"
|
|
||||||
mv $registros/$file $registros/$file.sig $historicos
|
|
||||||
else
|
|
||||||
echo -e "$uuid_registro: \e[91mFAIL\e[0m"
|
|
||||||
|
|
||||||
err_time=$(date +%Y-%m-%d-%H:%M:%S)
|
|
||||||
srv_msg="$(echo $respuesta_servidor | grep -o '<body.*>.*</body>')"
|
|
||||||
|
|
||||||
echo "$err_time - $uuid_registro - Error del servidor: $error_servidor" >> $log
|
|
||||||
echo "$err_time - $uuid_registro - Mensaje del servidor:" >> $log
|
|
||||||
echo "$srv_msg" >> $log
|
|
||||||
if [ -s $curl_err ];then
|
|
||||||
echo "$err_time - $uuid_registro - Salida de curl:" >> $log
|
|
||||||
cat $curl_err >> $log
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm $curl_err
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
done
|
|
||||||
exit
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######
|
|
||||||
|
|
||||||
# se testea que el servidor responda
|
# se testea que el servidor responda
|
||||||
#test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $servidor)"
|
#test_url="$(curl -s -X POST -o /dev/null -w "%{http_code}" $servidor)"
|
||||||
#if [ $test_url -eq 404 ];then
|
#if [ $test_url -eq 404 ];then
|
||||||
# echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> /opt/nodemecu/errors.log && sleep 300 && continue
|
# echo "$(date +%Y-%m-%d-%H:%M:%S) - $url - $test_url" >> /opt/nodemecu/errors.log && sleep 300 && continue
|
||||||
#fi
|
#fi
|
||||||
|
|
||||||
|
# firma de registros
|
||||||
|
sign_file $registros/$file
|
||||||
|
firma="$(cat $registros/$file.sign)"
|
||||||
|
|
||||||
|
|
||||||
|
local_transaction_uuid=$(jq -r '."transaction_uuid"' $registros/$file)
|
||||||
|
remote_transaction=$(curl -s --connect-timeout 1,5 --show-error -w "~%{http_code}" -X POST -H "X-Signature: $firma" -H "Content-Type: application/json" -d @$registros/$file $servidor 2> $curl_err)
|
||||||
|
remote_response="$(echo $remote_transaction | cut -d '~' -f 1)"
|
||||||
|
server_error="$(echo $remote_transaction | cut -d '~' -f 2)"
|
||||||
|
if [ ${#remote_response} -eq 36 ];then
|
||||||
|
|
||||||
|
if [ $local_transaction_uuid == $remote_response ]; then
|
||||||
|
mv $registros/$file $registros/$file.sign $historicos
|
||||||
|
echo -e "$remote_response: \e[92mOK\e[0m"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "$local_transaction_uuid: \e[91mFAIL\e[0m"
|
||||||
|
# errores
|
||||||
|
unset srv_msg
|
||||||
|
unset curl_msg
|
||||||
|
err_time=$(date +%Y-%m-%d-%H:%M:%S)
|
||||||
|
[ ! -z "$remote_response" ] && srv_msg="- $( echo $remote_response | grep -o '<body.*>.*</body>')"
|
||||||
|
[ -s "$curl_err" ] && curl_msg="- $(</tmp/curl_err)"
|
||||||
|
echo $err_time - $local_transaction_uuid - server status: $server_error $srv_msg $curl_msg >> $log
|
||||||
|
rm $curl_err
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
exit
|
||||||
|
|
||||||
|
|
13
raspberry/test
Executable file
13
raspberry/test
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if timeout 1 python arduinos.py 0x05; then
|
||||||
|
|
||||||
|
echo respondio
|
||||||
|
else
|
||||||
|
echo "No respondio, erro $?"
|
||||||
|
|
||||||
|
fi
|
Loading…
Reference in a new issue