Smart Meter Dashboard: Installing InfluxDB
For this project I knew I didn’t want to store a log of the information from the meter on the Pi. Through some testing, I determined that my power meter broadcasted it’s consumption about once every 30 seconds. While there isn’t much data overall that I wanted to store, I was kind of hesitant to write to a file on the Pi’s SD card that frequently. Looking around for a simple time series database, I found InfluxDB which seemed perfect for my use case.
Installation
After spinning up a new Debian droplet, the installation was pretty simple.
Creating a Database
Creating a database was pretty simple using the provided command line client.
Enable SSL
Since I planned on having authentication to prevent direct database access, I didn’t want the communication between my local machine and the server to be in clear text. By default influxDB does all of it’s communication over HTTP, but it does have support for SSL. To enable it I needed to create a PEM encoded SSL key and certificate. For my purposes a self-signed certificate was good enough, but for added security (namely SSL validation) a signed certificate should be used.
Influx uses a combined file for both the private key and the certificate file, so I had to append them together.
Once the combined file was created, I enable ssl by editing /etc/influxdb/influxdb.conf
.
I scrolled down to the sections for [admin]
changed the https-enabled
option
to true
and changed the https-certificate
to the path of the newly created
combined PEM file. For me that was https-certificate = "/etc/ssl/influxDB.pem"
.
I did the same in the [http]
section.
I tested if this was successful by restarting the influxdb service with
sudo service influxdb restart
and attempted to connect using the influx command
line tool. Since SSL is enabled you need to pass a few more flags in order for
this to work: influx -ssl -unsafeSsl
. Since I used a self-signed certificate, I had to use the -unsafeSsl
flag to disable the clients validation step.
Enable Authorization and Authentication
By default influxDB does not have authorization and authentication enabled. To enable it you must first create at least one administrator user account. I used the command line client to create two users: an admin user with all privileges and a power user that only has permissions to the power database I created earlier.
Once the users were created, I enabled authentication by editing
/etc/influxdb/influxdb.conf
again. In the [http]
section, I changed auth-enabled
to true
. I restarted the influx service and relaunch the influx command line
client. It should deny all requests to read data till you authenticate with
> auth <username> <password>
. Alternatively you can launch with
influx -ssl -unsafeSsl -username <username> -password <password>
to authenticate
before the client launches.
Next Step
Once I had a place to store my power usage information, I needed to setup the radio to pickup and send the information over to influxDB. That will be the topic of the next post.