Using Docker emoncms with inputs from MQTT

I’m new to OpenEnergyMonitor, but I think I’ve worked out that the standard Docker image for emoncms can’t accept data from MQTT because the process that subscribes to the relevant topic and handles the data doesn’t run (because Docker images typically only run one process and in this case it’s Apache).

On the assumption this is correct, I’m toying with the idea of modifying my image to use supvervisord to start both Apache and the MQTT reader process, though I’ve not looked into this very deeply as yet so there’s always the possibility of that approach being a dead end.

Has anyone already done this (or something similar) and care to share any ideas/information?


My experience with emoncms and Docker is years old. At that time, the integration was not very good and it didn’t appear that anybody was really working on it. I did a quick search and it seems other people have had more success and done things differently. There is nothing that says you HAVE to ONLY use one process in a Docker image. You can make an image that does lots of things. It goes against the pattern of single micro services per container, but that is just a pattern. People follow patterns because it makes some things easy.

I actually use NodeRED to translate from MQTT to emoncms and/or influxdb. I have individual containers (not using Docker, but could work with Docker too) for:

  • MQTT
  • NodeRED
  • InfluxDB
  • Grafana

I have emoncms running on a RPi. I found the Docker image for emoncms to be too hard to use. I also found the install process for emoncms to be very hard to use. Having worked on install processes for commercial software, I have some idea of how hard this can be to do well and how much effort it takes to make something complex easy to use. Docker is great when somebody takes the time to make an image that does just what you need and makes it easy to use that image. How hard it is to create that image depends on how hard/easy it is to install the actual product/components and configure them.

It seems this is not quite as simple as I was hoping for anyhow :frowning:

emoncms/scripts/phpmqtt_input.php appears to be somewhat confused about whether it needs Redis or not – the initialisation appears to be happy for it not to be there, but the code that submits data from emoncms to MQTT looks to require it. I don’t actually need that part as emoncms won’t be publishing anything, but I can’t see any mechanism to disable it.

I don’t see a compelling reason for running Redis at the moment so running that within the same Docker image or a separate one seems overkill.

Looks like I shall make a small tweak to the script so it doesn’t even consider publishing to MQTT unless Redis is enabled.

(I did look at using NodeRED to take data from MQTT and push it into emoncms using the API, but at the moment that seems like a lot of extra baggage just to implement something that ought to work anyhow. I may revisit that assumption should I later decide that NodeRED may be helpful elsewhere – I have lots of data from my weather station to publish to MQTT so it’s not impossible it may come in useful when I decided how I’m going to process that.)


Woo! I appear to have it working! :smiley:

I had to change the script so it just wouldn’t even check to see if there was data to publish to MQTT if Redis wasn’t enabled, and fix a couple (I think) of other code niggles. That got me most of the way, but it wasn’t until I realised that configuring anonymous read access to a topic in Mosquitto doesn’t actually give access to authenticated users (who knew?) that I started actually getting data being imported.

This feels like a big step forward. I have a fair bit of tidying up to do now, but I can be pleased with my evening’s work.