Since I am still convinced in the hardware design (battery life of more than two years, accuracy ~1cm) I started to analyse the traffic from the device and found that it is communicating via HTTP POST messages wiht the amazon cloud
In the next step I got a cheap D-Link DIR645 on a flea market and I installed the stock OpenWrt firmware on it along with some kernel modules to be able to write to an external usb-stick
Additionally I installed tcpdump, mosquitto_server and the cron package; the usb-stick was mounted to /tmp/fs
I enabled the tcpdump tool on the wifi interface and directed it to put all data on the usbstick in a file called tcpdump.dump
tcpdump -i wlan0 -s 0 -w /tmp/fs/tcpdump.dump
a message from the oilfox device looks like this:
{"token":"00000000-0000-0000-0000-000000000000","hwid":"xx:xx:xx:xx:xx:xx","value":16.98794,"battery":736,"version":"173.OF_PROD","temperature":23.5,"serialNumber":"OFXXXXXXXX","measurements":[[16.98794,3
4.60138,34.32509,34.23875,39.22923,39.64366,58.46587,61.79861,79.04942,96.55927,143.4076,180.7584],[17.26423,20.66604,34.25602,34.23875,39.22923,39.64366,59.01845,61.86768,79.04942,96.55927,143.4076,180.758
4],[17.3333,20.66604,34.39417,34.23875,39.22923,39.64366,58.53494,61.79861,79.25665,96.74921,143.4766,180.7584],[17.40237,20.68331,34.32509,34.23875,39.22923,39.71273,58.46587,61.86768,79.1185,96.74921,143.
4766,180.7584],[17.3333,20.66604,34.39417,34.23875,39.2983,39.78181,58.46587,61.86768,79.1185,96.74921,143.6148,180.7584]]}
then I created a scriptfile which is run once per day via cron to extract the measurement data and publish it to the installed mosquitto server:
File send_level.sh
#!/bin/sh
sh /tmp/fs/filter.sh /tmp/fs/tcpdump.dump | tail -1 > /tmp/output.mqtt
mosquitto_pub -t 'home/oil' -p 1883 -m "`cat /tmp/output.mqtt`"
The filtercommand looks like this:
File filter.sh
#!/bin/sh
tcpdump -r $1 -tttt -A | egrep -o '\{\"token.*\}|201.-..-..' | sed -n -e '/\"version\"/{p;x;p;d;}' -e x | sed 'N;s/\n/ /' | awk -F [,\ ] '{print $3 ":" $6 ":" $NF}' | awk -F ":" '{print "{ \"datum\": \""$5"\",\"level\" : \"" $2 "\", \"battery\":\"" $4 "\"\}" }'
I'm sure I won't win any beauty contest with this filter command but I wanted to be sure to preserve all data transferred from the device in case some format changes (suggestions are highly welcome ;-) )
The measuring device submits the distance measured to the amazon cloud service. All calculation of the fill grade of the tank is apparently done in the mobile phone app. In this case I will do the calculation in my Openhab home automation client.
The message which is sent via MQTT looks like this:
{ "datum": "2018-09-16","level" : "18.64783", "battery":"20"}
Finally, I just need to enable the mqtt client in my openhab2 installation and additionally install the jsonfilter package (yes I searched some hours why the parsing didnt work until I found out I had to install a special package)
The rule I created to parse the mqtt command looks like this:
File oelstand.rules
rule "Convert JSON to Item Type Number"
when
Item Oelstand_json changed
then
var float hoehe_tank=151.0
var float liter_je_cm=75.0
// use the transformation service to retrieve the value
val newDate = transform("JSONPATH","$.datum", Oelstand_json.state.toString)
val newDist = transform("JSONPATH","$.level", Oelstand_json.state.toString)
val newBattery = transform("JSONPATH","$.battery", Oelstand_json.state.toString)
// var float newLevel = hoehe_tank - (newDist as float)
var float newLevel = hoehe_tank - Float::parseFloat(newDist.toString)
var float newLiter = newLevel * liter_je_cm
var float newProzent = newLevel / hoehe_tank *100.0
// post the new value to the Number Item
...