diff --git a/raspberry/bin/nodemecu b/raspberry/bin/nodemecu index 429c146..623509a 100755 --- a/raspberry/bin/nodemecu +++ b/raspberry/bin/nodemecu @@ -7,7 +7,9 @@ fi # LECTURA FICHERO DE CONFIGURACION config=/etc/nodemecu.conf +envs=/opt/nodemecu/envs source $config +source $envs source $funciones [ -z $1 ] && exit diff --git a/raspberry/desinstalar b/raspberry/desinstalar index 2a75417..f0425a7 100755 --- a/raspberry/desinstalar +++ b/raspberry/desinstalar @@ -1,6 +1,6 @@ #!/bin/bash source /etc/nodemecu.conf - +source /opt/nodemecu/envs if [ $UID -ne 0 ]; then echo "Ejecute 'sudo $0'" exit diff --git a/raspberry/funciones b/raspberry/funciones index f59f357..22a0eea 100644 --- a/raspberry/funciones +++ b/raspberry/funciones @@ -8,11 +8,7 @@ get_stack () { fi } - - # Generar una llave privada ECDSA si no existe -# -# Uso: generate_private_key "comentario" generate_private_key () { test -f "$private_key" && return 1 @@ -33,7 +29,6 @@ sign_file () { } - 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" diff --git a/raspberry/generador_json b/raspberry/generador_json index 1d5cbaa..d2dc5cc 100755 --- a/raspberry/generador_json +++ b/raspberry/generador_json @@ -1,7 +1,7 @@ #!/bin/bash source /etc/nodemecu.conf -source $env +source /opt/nodemecu/envs source $funciones conteo=$(cat $contador) diff --git a/raspberry/instalador b/raspberry/instalador index 5e462ad..32ca55e 100755 --- a/raspberry/instalador +++ b/raspberry/instalador @@ -1,25 +1,18 @@ #!/bin/bash #set -x +if [ $UID -ne 0 ]; then + echo "Ejecute 'sudo $0'" + exit +fi basedir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) configuracion=$basedir/nodemecu.conf.ejemplo envs=$basedir/envs - -cat $configuracion -cat $envs -exit - - - source $configuracion - -if [ $UID -ne 0 ]; then - echo "Ejecute 'sudo $0'" - exit -fi +source $envs if [ -d $directorio_instalacion ] ; then echo "nodemecu ya se encuentra instalado" @@ -27,15 +20,14 @@ if [ -d $directorio_instalacion ] ; then fi -ficheros="bin env arduinos.py contador generador_json funciones monitor monitor_web registrador desinstalar" - +ficheros="bin envs arduinos.py contador generador_json funciones monitor monitor_web registrador desinstalar" # Dependencias echo "1. Instalando dependencias " -apt update && apt install -y python3-pip jsonlint jq uuid -pip3 install pyserial +#apt update && apt install -y python3-pip jsonlint jq uuid +#pip3 install pyserial echo "" @@ -81,7 +73,7 @@ echo " sn=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2) -sed -i 's/numero_serie=/numero_serie/' $env +sed -i 's/numero_serie=/numero_serie='$sn'/' $directorio_instalacion/envs echo "NĂºmero de serie: $sn" diff --git a/raspberry/registrador b/raspberry/registrador index bf9655b..a3f1447 100755 --- a/raspberry/registrador +++ b/raspberry/registrador @@ -1,5 +1,7 @@ #!/bin/bash +set -x source /etc/nodemecu.conf +source /opt/nodemecu/envs source $funciones @@ -38,18 +40,18 @@ while :;do #fi # firma de registros - sign_file $registros/$file - firma="$(cat $registros/$file.sign)" + sign_file $registros/$file + exit 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_transaction=$(curl -s --connect-timeout 1,5 --show-error -w "~%{http_code}" -X POST -H "X-Signature: $(sign_file $registros/$file.sig)" -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 + mv $registros/$file $registros/$file.sig $historicos echo -e "$remote_response: \e[92mOK\e[0m" fi else