Data visualisations

Sure! Once you have docker properly installed, you start both containers like this:

sudo docker run -d -p 8083:8083 -p 8086:8086 --name influxdb -e PRE_CREATE_DB="sensors" -v /media/nas/data/influxdb:/data --restart=unless-stopped tutum/influxdb:0.10
sudo docker run -d -p 3000:3000 --name grafana -v /media/nas/data/grafana/lib:/var/lib/grafana -v /media/nas/data/grafana/etc:/etc/grafana --restart=unless-stopped grafana/grafana:2.6.0

The directories /media/nas/data/* listed above are local directories that will be mounted inside the docker container. This allows you to delete and recreate the docker containers without loosing any of your data or configuration. This way, upgrading InfluxDB or Grafana is super simple, all it takes is a “docker rm -f” and a new “docker run”.

The next thing you need to do is log in to Grafana (https://localhost:3000) and add an InfluxDB data source pointing to http://localhost:8086. And you’re done!

Now you just have to get your Photon to send data to InfluxDB, like this:

#include "HttpClient/HttpClient.h"
...
#define INFLUXDB_HOST   "influxhost"
#define INFLUXDB_PORT   8086
#define INFLUXDB_DB     "sensors"
...
HttpClient http;

// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
    { "Host", INFLUXDB_HOST },
    { "Connection", "close" },
    { "Accept" , "application/json" },
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};


bool sendInflux(String payload) {   
    http_request_t     request;
    http_response_t    response;
    
    request.hostname = INFLUXDB_HOST;
    request.port     = INFLUXDB_PORT;
    request.path     = "/write?db=" + String(INFLUXDB_DB);
    request.body     = payload;
   
    http.post(request, response, headers);
    
    if (response.status == 204) {
        return true;
    } else {
        return false;
    }
}

void setup() {
    ...
    // hello,zone=bla,sensor=XXX version="0.4.9",count=X
    String hello = "hello,zone=" + String(ZONE) + ",sensor="+System.deviceID() + " version=\"" + System.version() + "\",count=1";
    sendInflux(hello);
    ....
}

Let me know if you need any help!

6 Likes