This commit is contained in:
Sergio Pernas 2022-03-05 17:09:45 -03:00
parent 9ebc511ab0
commit fd4fde4e5c
6 changed files with 80 additions and 6 deletions

20
bin/nodemecu Normal file → Executable file
View file

@ -8,6 +8,7 @@ fi
config=/etc/nodemecu.conf
source $config
source $funciones
[ -z $1 ] && exit
@ -16,6 +17,25 @@ com=$1
case $com in
configurar)
echo "Complete los cambios a continuación:
"
echo "Nombre del dispositivo."
read -p "nombre: " -a entrada_usuario
funcion_configurar nombre ${entrada_usuario[@]}
echo ""
echo "Servidor de entrega de datos."
read -p "servidor (ej. https://url.del/servidor): " entrada_usuario
funcion_configurar servidor $entrada_usuario
echo ""
echo "Intervalo de toma de muestras, entre 1 y 60 minutos."
read -p "intervalo: " entrada_usuario
funcion_configurar intervalo $entrada_usuario
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'
"
;;
start)
if [ -z $interval ]; then
echo "Asegurese de haber establecido 'intervalo' de regitro y envio de datos."

View file

@ -15,7 +15,54 @@ 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"
}
funcion_configurar() {
local comando=$1
local parametro=$2
local parametros=$*
local url_regex='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
case $comando in
nombre)
while :;do
nombre=$(echo $parametros | sed 's/nombre //g' | sed 's/ /_/g')
if [[ "$nombre" =~ ^[a-zA-Z0-9_]+$ ]];then
sed -i 's/nombre=*/nombre='$nombre'/' $config
break
else
echo "El nombre solo puede contener carateres alfanumericos."
read -p "nombre: " parametro
fi
done
;;
servidor)
while :;do
if [[ $parametro =~ $url_regex ]]; then
sed -i 's}servidor=*}servidor='"$parametro"'}' $config
echo "Servidor $parametro"
break
else
echo "Intruzca una url válida."
read -p "url: " parametro
fi
done
;;
intervalo)
while :;do
if [[ $parametro -ge 1 && $parametro -le 60 ]]; then
sed -i 's/intervalo=[0-9]*/intervalo='$parametro'/' $config
echo "Intervalo seteado en $parametro"
break
else
echo "Establezca un valor entre 1 y 60."
read -p "Intervalo: " parametro
fi
done
;;
esac
}

View file

@ -2,7 +2,7 @@
#set -x
source /etc/nodemecu.conf
source funciones
source $funciones
conteo=$(cat $contador)
uuid="$(uuidgen)"

View file

@ -46,6 +46,7 @@ cp -v $configuracion /etc/nodemecu.conf
echo "
Enlaces a binarios
"
chmod 755 $directorio_instalacion/bin/nodemecu
ln -vs $directorio_instalacion/bin/nodemecu /usr/bin/nodemecu
echo "
Fichero de logs
@ -64,5 +65,9 @@ systemctl start nodemecu.service
systemctl status nodemecu.service
echo "
4. Configurar
"
echo "Ejecute 'sudo nodemecu configurar' para comenzar.
"

View file

@ -1,6 +1,6 @@
url=
name=
interval=
servidor=
nombre=
intervalo=
modo=test
@ -18,3 +18,4 @@ registros_corruptos=$directorio_instalacion/corruptos
envios_fallidos=$directorio_instalacion/fallidos
contador=$directorio_instalacion/contador
lock=$directorio_instalacion/lock
funciones=$directorio_instalacion/funciones

1
url Normal file
View file

@ -0,0 +1 @@
https://ectomobile.sutty.nl/readings