how to add mqtt mosquitto config

Running BalenaSense with external ESP8266 that communicate over MQTT, so I need to add these lines to the end of /mosquitto/config/mosquitto.conf:

listener 1883
allow_anonymous true

How can I add this to docker-compose.yml?


Can you please elaborate a bit on what is the problem you’re trying to solve? Where is the BalenaSense running? How is ESP8266 communicating with it?

1 Like

Sure, the problem if I understand it correctly is BalenaSense uses the GPIO pins of the local Pi to receive data, so only internal MQTT connectivity is required.

I have BalenaSense running on a Pi Zero and instead of a local sensor I have temperature sensors connected to a number of 8266s that transmit the data over the network to the MQTT server on BalenaSense.

Mosquittos default configuration options is to listen internally only, which in my setup never allows for the incoming data to be received. At the moment every time the MQTT service is restarted I have to manually login to the container add the lines mentioned and manually run the mosquitto run command. Therefore, I’d like a way to allow the forementioned attributes to be present within the mosquitto.conf file by way of some docker compose magic, such that when the container is interpreted again these settings will be preserved.

1 Like

Hello @n1md4 what you are trying to do is very interesting!

Do you think you can share your docker-compose so we can try to replicate?

Having said that, did you try to use the connector block? i think it uses mosquitto and you may be able to get the data GitHub - balenablocks/connector: Auto-configured data connector block based on Telegraf

Of course, here is the file:

version: '2.1'
  sense-data: {}
    restart: always
      context: ./influxdb
      - 'sense-data:/data'
    restart: always
      context: ./grafana
      - '80'
      - 'sense-data:/data'
      HOME_DASHBOARD_UID: balenaSense
      GF_PATHS_DATA: /data/grafana
      context: ./telegraf
    restart: always
      - SYS_ADMIN
    image: arm32v6/eclipse-mosquitto
      - '1883:1883'
    restart: always

Hmm maybe I have not looked into using the connector block extensively enough. I set this up some time ago, so forget exactly what I’d tried at the time. If you think it’s worth looking into I’m all for using blocks (it is on my to-do list).

Thanks @n1md4

actually i would strongly recommend to get into the blocks!

Feel free to read this and test it! balenaSense v2: Updated temperature, pressure, and humidity monitoring for Raspberry Pi

Going to answer your issue. Stupid question are the esp8266 sensors connected to the same local network? Did you try to test

TELEGRAF_MQTT_URL_PORT: instead of internal if this is the URL of your mqtt broker.

@alanb128 do you know why MQTT is not running for external sensors on the local network?

Huh! I don’t appear to have a copy of the sense repo available to rebuild the project release. Oh well, good excuse to start new and utilise blocks.

The esp8266s are on the same network.

Sounds good, let us know if you make progress on rebuilding and deploying it successfully!

Hi there,

I’m facing a similar situation. I need to provide a custom default configuration to the mosquitto container and I have found yet a way to do it.

In a nutshell, I created a volume (mosquitto) where mosquitto configs, data, and logs are stored and I mapped it inside the mosquitto container.

My idea was to replace the existing mosquitto.conf (inside the volume) with my custom one, without needing to do it manually after deploying the container.

The docker-compose.yml file, I’m using is:

version: '2'

    hostname: mosquitto
    image: eclipse-mosquitto
    restart: always
      - 'mosquitto:/mosquitto'

      context: .
      dockerfile: ./my-app/Dockerfile.template
    restart: unless-stopped
      - mosquitto

Everything works perfectly fine, but the need of manually configure the mosquitto is not scalable.

I would like to hear from you if anyone has already faced a situation like this and how you overcame it.