find3 icon indicating copy to clipboard operation
find3 copied to clipboard

Store historical location data (e.g. in time series database)

Open victorhooi opened this issue 6 years ago • 13 comments

It would be awesome if we could store historical location data - e.g. how many devices, and which devices (by MAC address) were at each location, in say, 5 minute increments.

We could store this in a time-series DB like InfluxDB.

victorhooi avatar Mar 04 '18 07:03 victorhooi

That would be cool. I'm not sure how to use Influx, but this data could be pulled using SQLite pretty easily.

schollz avatar Mar 06 '18 13:03 schollz

I am currently hacking around and seeing if I can get anything like this up and running.

DatanoiseTV avatar Mar 26 '18 22:03 DatanoiseTV

If there is an api to query the current situation that reply could easily be used for Logstash or Telegraf

https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http_poller.html https://github.com/influxdata/telegraf/tree/master/plugins/inputs/http

elvarb avatar Mar 27 '18 08:03 elvarb

@elvarb But doesn't the telegraf JSON HTTP input just take integer and float responses? Could be problematic to deal with strings.

DatanoiseTV avatar Mar 27 '18 12:03 DatanoiseTV

@DatanoiseTV not sure how the telegraf json input works, not used it. The big picture I see that instead of integrating it against one system, provide an api or some interface so its easier to integrate with anything you like.

The big big reason this project is so interesting to me is that I have done a POC using ESP8266. Monitor for management frames and send them to the Elastic stack, providing a very nice interface with Kibana for the data.

elvarb avatar Mar 27 '18 14:03 elvarb

Hi, I implemented a HTTP endpoint in find that spits outs current state of each location. The JSON in my case looks like this,

{
    "total_number_of_devices": 1,
    "by_location": [
        {
            "device": "red",
            "timestamp": "2018-06-14T07:14:03.325Z",
            "probability": 0.79,
            "randomized": false,
            "num_scanners": 19,
            "active_mins": 80,
            "first_seen": "2018-06-13T07:38:05.953Z",
            "location": "unitech"
        }
    ]
}

Unfortunately, Influx DB/Telegraf does not support nested JSON. So, Integrating telegraf is not possible until this issue is resolved.

There is, however, another way, And that would be to send separate JSON for each device, But that might not be desirable.

Let me know what you guys think..

ishanjain28 avatar Jun 14 '18 08:06 ishanjain28

Did you try seriesly from dustin (https://github.com/dustin/seriesly/) it has an flexible api. I'm testing it with my own web based client, pretty cool performance also writen in go.

tevfik avatar Aug 31 '18 13:08 tevfik

I have this working by forwarding MQTT messages to influxdb through telegraf. Quite cool as then you can do any kind of visualization in grafana.

jekkos avatar Dec 23 '18 11:12 jekkos

@jekkos Wow, that seems pretty cool - much easier than polling get_locations (which seems to be currently broken - as it maxes out CPU on find3, and times out). Are you able to provide some more details on how you captured the MQTT messages, and forwarded them?

victorhooi avatar Dec 23 '18 20:12 victorhooi

well if you setup telegraf and connect it to your mqtt broker, then you can forward those messages to influxdb quite easily. Beside telegraf you will need the mqtt consumer plugin that you then configure to read from the mqtt topic that has the find3 messages.

jekkos avatar Dec 24 '18 12:12 jekkos

https://github.com/influxdata/telegraf/tree/master/plugins/inputs/mqtt_consumer

jekkos avatar Dec 24 '18 12:12 jekkos

Also check https://community.influxdata.com/t/sonoff-mqtt-json-parsing-to-influxdb/3448/3 and https://github.com/influxdata/telegraf/tree/master/plugins/parsers/json

jekkos avatar Dec 24 '18 12:12 jekkos

I subscribe to the mqtt channel somewhere/location/# to get location updates from all devices. Then I forward it to a more performant and secure mqtt server with channel name locations/somewhere/all using a simple forwarder written in QtMqtt (which is pretty robust). From there, I can forward to web via mqtt:ws protocol or I could write a client to listen to locations/# and forward all data to db.

nurettin avatar Mar 20 '19 14:03 nurettin