Monitoring our Bosch Indego lawnmower with Grafana

Come, We continue with a somewhat geeky post, but if you have a garden you may be interested… The thing is, I have one of those robots that mow the lawn at home, specifically a Bosch Indego 350, and through an API given to us by the manufacturer we will be able to know the status of the lawnmower at all times, as well as having access to some interesting values; And by the way, with this API we will also be able to control it, At the end of the post we will see how to check the weather and if it is not raining, Well, we sent it to be cut 😉

 

GOOD, We will use this cool app Controller application and API for Bosch Indego Connect, The first thing will be to install the requirements, Maven, We download the latest build, We compile and install it. We will see that it generates a fully functional binary for our distribution, in this case I seem to remember that I'm using a Raspbian Stretch, I leave you the steps to have it ready:

[SourceCode]sudo apt-get install maven
wget https://github.com/zazaz-de/iot-device-bosch-indego-controller/archive/bosch-indego-controller-0.8.zip
Unzip bosch-indego-controller-0.8.zip
cd iot-device-bosch-indego-controller-bosch-indego-controller-0.8/
MVN compile
MVN package
MVN Install
cd bosch-indego-controller-dist/target
Unzip bosch-indego-controller-dist-0.8-bin.zip
cd bosch-indego-controller-dist-0.8/Bin/
./IndegoController[/SourceCode]

 

Let's go to the directory where the binary left us, and we tried to execute it, We will send you as parameters with -u our username with which we have registered the Indego lawnmower and -p the password of the account, With -Q we can make a query and see the data of our device, We will see consumption, Times, completed… With -C we can send commands, such as MOW for you to go for a walk and cut the grass.

[SourceCode]cd ~/iot-device-bosch-indego-controller-bosch-indego-controller-0.8/bosch-indego-controller-dist/target/bosch-indego-controller-dist-0.8/bin
./IndegoController -u US*****@MA**. AndUNDER -p PASSWORD -q
./IndegoController -u US*****@MA**. AndUNDER -p PASSWORD -c MOW -q[/SourceCode]

 

If we have problems when executing it due to certificate issues, we will have to import the Bosch Indego certificates to the Java keystore. We lower the 3 CA chain certificates https://https://api.indego.iot.bosch-si.com even with an Internet Explorer, we save them in DER X.509 format.

Y los importamos en el keystore de Java, nos pedirá password, la contraseña por defecto del keystore cacerts es changeit:

[SourceCode]keytool -import -alias INDEGO_CER -keystore $JAVA_HOME/jre/lib/security/cacerts -file /home/pi/indego.cer
keytool -import -alias INDEGO_CA1 -keystore $JAVA_HOME/jre/lib/security/cacerts -file /home/pi/indegoCA1.cer
keytool -import -alias INDEGO_CA2 -keystore $JAVA_HOME/jre/lib/security/cacerts -file /home/pi/indegoCA2.cer[/SourceCode]

 

Y nada probamos de nuevo el script y veremos cómo obtenemos nuestros datos! Si queremos explotarlos, os dejo un ejemplo de un script cutrecillo lque tengo llamado ‘cortacesped_estado.sh’, bien este script lo que hará es buscar ciertas palabras en ese output anterior y guardará los valores obtenidos en una base de datos con MySQL, que luego podremos atacar fácilmente desde Grafana y obtener algún dashboard muy cuco.

[SourceCode]#!/bin/bash
/home/pi/indego/bin/IndegoController -u US*****@MA**. AndUNDER -p PASSWORD -q > /home/pi/indego/estado.txt
completado=`cat /home/pi/indego/estado.txt | grep Completed| aw '{print $2}’`
completado=`echo "${completado//\,/.}"`
session_operate=`cat /home/pi/indego/estado.txt | grep ‘Runtime session / operate:’| aw '{print $5}’`
session_operate=`echo "${session_operate//\,/.}"`
session_charge=`cat /home/pi/indego/estado.txt | grep ‘Runtime session / charge’| aw '{print $5}’`
session_charge=`echo "${session_charge//\,/.}"`
total_operate=`cat /home/pi/indego/estado.txt | grep ‘Runtime total / operate’| aw '{print $5}’`
total_operate=`echo "${total_operate//\,/.}"`
total_charge=`cat /home/pi/indego/estado.txt | grep ‘Runtime total / charge’| aw '{print $5}’`
total_charge=`echo "${total_charge//\,/.}"`
estado=`cat /home/pi/indego/estado.txt | grep ‘DeviceStatus’| aw '{print $4}’ |sed -e ‘s#.*=\(\)#\1#’ | rev | cut -c 2- | rev`
estado="’$estado’"
echo "INSERT INTO cortacesped (completed, session_operate, session_charge, total_operate, total_charge, state) VALUES ($completed,$session_operate,$session_charge,$total_operate,$total_charge,$state);" | mysql -uUSUARIO -pCONTRASEÑA -h SERVIDOR_MYSQL NOMBRE_BD;
[/SourceCode]

 

No debemos olvidar crear en cron la programación que nos interese para que se ejecute el script, en mi caso se ejecuta cada 5 minutos para recolectar información.

 

But of course, antes debemos crear la tabla en alguna base de datos de nuestro servidor MySQL, como veis es muy sencillica, Has 7 campos que almacenarán los datos que le mande, os dejo el código de MySQL por si queréis ver el tipo de columnas:

[SourceCode]CREATE TABLE `cortacesped` (
`completado` FLOAT NULL DEFAULT NULL,
`session_operate` FLOAT NULL DEFAULT NULL,
`session_charge` FLOAT NULL DEFAULT NULL,
`total_operate` FLOAT NULL DEFAULT NULL,
`total_charge` FLOAT NULL DEFAULT NULL,
'status' CHAR(20) NULL DEFAULT NULL,
'date' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
COLLATE='utf8mb4_general_ci’
ENGINE=InnoDB
ROW_FORMAT=COMPACT;[/SourceCode]

And that's it! Con la BD alimentándose, ya podremos configurar un dashboard con los paneles que nos interese, I leave you with this example, os paso las querys que utilicé. Ah y por cierto, si no tienes el DataSource en Grafana creado contra el servidor MySQL, acuérdate de hacerlo antes 😉

  • Último segado:

[SourceCode]SELECT timestamp(DATE_FORMAT(date, '%Y/%m/%d %H:%i:%s’)) as time_sec FROM cortacesped where estado = ‘MowingORDER BY fecha DESC LIMIT 1[/SourceCode]

  • Jardín segado:

[SourceCode]SELECT completado FROM cortacesped ORDER BY fecha DESC LIMIT 1[/SourceCode]

  • Query para la gráfica de los últimos 15 days, donde vemos el % avanzado a lo largo del tiempo:

[SourceCode]SELECT UNIX_TIMESTAMP(date) So time_sec, completado as value, "Time" as metric FROM cortacesped WHERE $__timeFilter(date) and estado = ‘MowingORDER BY fecha, time_sec ASC[/SourceCode]

  • Segados totales:

[SourceCode]SELECT COUNT(*) FROM cortacesped where estado = ‘Mowingand completado = 0[/SourceCode]

  • Total cortando:

[SourceCode]SELECT total_operate FROM cortacesped ORDER BY fecha DESC LIMIT 1[/SourceCode]

 

And while we're at it,, si os interesa, este es un script txorra que utilizo para programar que salga el robot a cortar el césped, primeramente en cron le tengo que se ejecute los Lunes, Miercoles y Viernes a las 8:30AM, y lo que hace primero es checkear el tiempo, mira el tiempo actual y el que hará a lo largo del día, si va a hacer malo (lluvia, nieve, granizo…) pues no saldrá a segar, le llamo enciende_cortacesped.sh:

[SourceCode]#!/bin/bash
curl wttr.in/Bilbao?1 > /tmp/eltiempo.txt
if grep ‘rain\|drizzle\|snow\|sleet\|freez\thunder’ /tmp/eltiempo.txt > /dev/null
then
echo "Hará o hace malo"
else
echo "Hará o hace bueno"
/home/pi/indego/bin/IndegoController -u US*****@MA**. AndUNDER -p CONTRASEÑA -c MOW
fi[/SourceCode]

 

I hope you found it interesting, se pueden hacer muchas cosas más que iremos viendo con el tiempo, So what I said, espero que os haya gustado!

 

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!

Monitoring a Synology Array

3 of July de 2019