Storing OpenDTU data in Influx DB

Motivation

I just bought Solar panel set. And i wanted to monitor everything, but looking at prices of monitoring equipment costs 150 or more € i decided to look up for cheaper solution. So everything i needed costed me around 20€.

How to connect everything

To star this i would like to say that I am using my infrastructure, and everything is self hosted in my network. So there are maybe some security issues and some similar things, but to be honest there are only inside network, and as it is not available from outside, and guests uses other network that can not communicate with my own network i have decided to ignore this for now.

My network is based on Mikrotik Routers and APs, configured with CAPsMAN. And server is inside network, connected with cable. Basic hardware is Celeron J1900 with 4 GB RAM. There are more stuff running on that machine. CPU is around 0.20 and Ram about 1.5 GB used. So hardware requirements are really small. And everything is running on Docker Containers.

OpenDTU

Introduction

I am using Firmware Version / Git Hash: 13b22de

I will not write here much. You can read here everything: https://github.com/tbnobody/OpenDTU

Basically i build the hardware, purchased ESP32 board and NRF24L01+ radio board from links on GitHub. Wired everything and flashed ESP32, had some issues, had to change some board config. In My case i had to change IRQ pin to 2. You can see this directly on board.

[env:generic]
board = esp32dev
build_flags = ${env.build_flags}
    -DHOYMILES_PIN_MISO=19
    -DHOYMILES_PIN_MOSI=23
    -DHOYMILES_PIN_SCLK=18
    -DHOYMILES_PIN_IRQ=2
    -DHOYMILES_PIN_CE=4
    -DHOYMILES_PIN_CS=5

After that I was able to connect to Inverter and i got data.

Configuration to send data to mosquitto

This can work after you have installed and configured mosquitto

You have to enable MqTT

You need to enter hostname where the data is send to, and port.

Should look something like this:

mosquitto

I used mosquitto as MQTT broker. In my case i used it as container. As i like to use containers i configured evertything using contaners on my server.

I used version 2.0.15

Path i have used are:

  • /data/mosquitto/data
  • /data/mosquitto/log
  • /data/mosquitto/config

You have to create your own paths.

After you have created paths in config directory you have create config file mosquitto.conf

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883 0.0.0.0
listener 9001 0.0.0.0
allow_anonymous true

now you can start container

To start the container:

docker run \
  -v /data/mosquitto/data:/mosquitto/data \
  -v /data/mosquitto/log:/mosquitto/log \
  -v /data/mosquitto/config:/mosquitto/config \
  -p 1883:1884 \
  -p 9001:9002 \
  eclipse-mosquitto:2.0.15

InfluxDB

InfluxDB is used to store all the data and get good looking graphs.

I am using version 2.4.0

Path i have used are:

  • /data/influxdb
  • /data/influxdb/config

To start the container

docker run \
  -v /data/influxdb:/var/lib/influxdb2 \
  -v /data/influxdb/config /etc/influxdb2 \
  -p 8086:8086 \
  influxdb:2.4.0

After you start InfluxDB you have to configure bucket where the data should be going, and token for for telegraf. Plese refer to official documentation how to do that. Here is documentation: https://docs.influxdata.com/influxdb/v2.4/get-started/

In short you have to go to UI and there in buckets create a new bucket. The you have to API Token and create a token there.

InfluxDB UI is avalaible on port 8086

telegraf

Telegraf is used to transport data from mosqutto to influx db

I used version 1.24.2

This has the most complicated configuration of all

Path i have used are:

  • /data/telegraph

At that path you have to put your configuration file telegraf.conf

First you have to configure output plugin. Change values to fit your system

[[outputs.influxdb_v2]]
http://InfluxDB_URL:8086
token = "TOKEN_FOR_INFLUX_DB"
organization = "YOUR_ORGANIZATION"
bucket = "YOUR_BUCKET"

Then you have to configure input plugin

[[inputs.mqtt_consumer]]
        servers = ["tcp://MOSQUITTO_URL:1883"]
        topics = [ "solar/#" ]
        qos = 0
        connection_timeout = "30s"
        data_format = "value"
        data_type = "float"

after this you can start telegraf container with

docker run \
  -v /data/telegraph:/etc/telegraf \
  -p 8094:8094 \
  -p 8125:8125 \
  -p 8092:8092/udp \
  telegraf:1.24.2

After this telegraf should start and send data to influxdb. And in some time you can configure nice grafs

Dashboard creation

You can to DataExplorer. There you have to select bucket that you created, in my case solar, then mqqt_consumer and everything else and data should be there. Take a look at screenshot.

Conclusion

After this is completed, you have a decent system where you can monitor and store data about you Solar Power Plant.

I have here developed nothing i have just put all pieces together and connected everything to get everything working.