diff --git a/controller.py b/arduinos.py similarity index 100% rename from controller.py rename to arduinos.py diff --git a/counter b/contador similarity index 100% rename from counter rename to contador diff --git a/uninstall.sh b/desinstalar similarity index 100% rename from uninstall.sh rename to desinstalar diff --git a/register.sh b/enviar similarity index 100% rename from register.sh rename to enviar diff --git a/funciones b/funciones new file mode 100644 index 0000000..8f7e633 --- /dev/null +++ b/funciones @@ -0,0 +1,30 @@ +#!/bin/bash + +get_stack () { + if [[ ! -z $1 && $1 == "wc" ]];then + ls /opt/nodemecu/stack | wc -l + else + ls /opt/nodemecu/stack | tail -1 + fi +} + + + +funcion_datos_simulados() { + + 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" +} + + + + + + + + + + + + + + diff --git a/functions b/functions deleted file mode 100644 index 1f0f68e..0000000 --- a/functions +++ /dev/null @@ -1,10 +0,0 @@ -get_stack () { - if [[ ! -z $1 && $1 == "wc" ]];then - ls /opt/nodemecu/stack | wc -l - else - ls /opt/nodemecu/stack | tail -1 - fi -} - - - diff --git a/data_gen.sh b/generador_json similarity index 67% rename from data_gen.sh rename to generador_json index acf5728..da64e2f 100755 --- a/data_gen.sh +++ b/generador_json @@ -1,12 +1,17 @@ #!/bin/bash -source /etc/nodemecu.conf - +#source /etc/nodemecu.conf +source funciones + funcion_datos_simulados + echo $lecturas + exit 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" + funcion_datos_simulados ;; esac +# ARMADO DE FICHERO JSON + for i in $lecturas;do case $i in id*) @@ -38,6 +43,10 @@ case $i in ;; esac done + + + + counter=$(cat $install_dir/counter) uuid="$(uuidgen)" timestamp="$(date +%s)" diff --git a/instalador b/instalador new file mode 100755 index 0000000..5d5e333 --- /dev/null +++ b/instalador @@ -0,0 +1,67 @@ +#!/bin/bash +set -x +configuracion=nodemecu.conf.ejemplo +source $configuracion + +if [ $UID -ne 0 ]; then + echo "Ejecute 'sudo $0'" + exit +fi + +test -d $directorio_instalacion && $(echo "nodemec ya se encuentra instalado"; date) + +exit + + +ficheros="bin arduinos.py contador generador_json funciones instalador monitor monitor_web nodemecu.conf.ejemplo nodemecu.service enviar desinstalar" + + +# Dependencias + +echo "1. Instalando dependencias +" +#pip install pyserial +#apt update && apt install -y jsonlint + +echo "" + +# Directorio de instalación + +echo "2. Creando directorios y copiando archivos" +echo " +Creación de directorios +" +mkdir -vp $directorio_instalacion/archives/historical +mkdir -v $directorio_instalacion/archives/logs +mkdir -v $registros_corruptos +mkdir -v $envios_fallidos +mkdir -v $historicos +mkdir -v $registros +echo " +Copiado de archivos +" +cp -vr $ficheros $directorio_instalacion +cp -v $configuracion /etc/nodemecu.conf +echo " +Enlaces a binarios +" +ln -vs $directorio_instalacion/bin/nodemecu /usr/bin/nodemecu +echo " +Fichero de logs +" +touch $log +ls $log + + +echo "3. Configurando systemd +" + +cp nodemecu.service /lib/systemd/system/ +systemctl daemon-reload +systemctl enable nodemecu.service +systemctl start nodemecu.service +systemctl status nodemecu.service + + + + diff --git a/install.sh b/install.sh deleted file mode 100755 index 81fdf8c..0000000 --- a/install.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -files="data_gen.sh monitor.sh register.sh uninstall.sh monitor.web bin functions counter" -config=nodemecu.conf.sample -source $config - -echo -e "1. Instalando dependencias" - -#sudo apt update && sudo apt install -y jq uuid-runtime dnsmasq dnsutils -sudo pip install pyserial -echo "" - - -# Estructura de directorios -echo -e "2. Creando directorios y copiando archivos" - -sudo mkdir -vp $install_dir/archives/historical -sudo mkdir -vp $install_dir/archives/logs -sudo mkdir $historical -sudo mkdir $stack -echo "" -sudo cp -vr $files $install_dir -sudo cp -v $config /etc/nodemecu.conf -sudo ln -s $install_dir/bin/nodemecu /usr/bin/nodemecu -sudo touch $log -echo "" -echo "3. Configurando systemd" - -sudo cp nodemecu.service /lib/systemd/system/ -sudo systemctl daemon-reload -sudo systemctl enable nodemecu.service -sudo systemctl start nodemecu.service -sudo systemctl status nodemecu.service -echo "" -echo ". Alias de comandos." -echo "alias nodemecu='sudo nodemecu'" >> $HOME/.bashrc -echo "" -echo "Ejecute 'source ~/.bashrc' para aplicar los cambios." -echo "" - - - - diff --git a/monitor.sh b/monitor similarity index 100% rename from monitor.sh rename to monitor diff --git a/monitor.web b/monitor_web similarity index 100% rename from monitor.web rename to monitor_web diff --git a/nodemecu.conf.ejemplo b/nodemecu.conf.ejemplo new file mode 100644 index 0000000..ea938d1 --- /dev/null +++ b/nodemecu.conf.ejemplo @@ -0,0 +1,19 @@ +url= +name= +interval= +mode=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 + diff --git a/nodemecu.conf.sample b/nodemecu.conf.sample deleted file mode 100644 index bfb5883..0000000 --- a/nodemecu.conf.sample +++ /dev/null @@ -1,16 +0,0 @@ -url=https://ectomobile.sutty.nl/transactions -name= -interval= -mode=test - - -# AJUSTES GENERALES -# SE RECOMIENDA NO MODIFICAR ESTAS LINEAS -curl_err=/tmp/curl_err -historical_file_size=1440 -logs_file_size=1440 -install_dir=/opt/nodemecu -stack=$install_dir/stack -historical=$install_dir/historical -log=$install_dir/errors.log -corrupt=$install_dir/corrupt diff --git a/nodemecu.service b/nodemecu.service index fcaa0fb..29a714e 100644 --- a/nodemecu.service +++ b/nodemecu.service @@ -2,6 +2,8 @@ Description=Procesador de pila y transmisor de datos Nodemecu. [Service] +Restart=on-failure +RestartSec=5s ExecStart=/opt/nodemecu/register.sh [Install]