MQTT Server in Freedombox (Ejabberd Easter Egg)

TL;DR MQTT uses port 1883 for unsecure communication and port 8883 for secure communication. Port 1883 is active by default, just make sure to activate 8883 in your ejabberd configuration and you’re good to go.

We live in a very dense metropolitan city and getting around / commuting is not really for the faint-hearted. However, I’ve been trying to support my 10 year old to start going to school on his own. It’s a 20 min. walk but he has to carefully cross a couple of streets, have an eye out for the traffic and move through some dense crowd. Childhood here and now, isn’t like it was for us.

Knowing the risks but also to promote his self-confidence, I’ve convinced him to walk every morning on his own. We’re both a little timid so I have been placing some safety measures to make it easier easier for the both of us (i.e. I kindly asked a teacher / friend from school to make sure he’s there in the morning, arranged a classmate in the neighbourhood so he had a buddy to meet and walk together). However, I also wanted to put an old phone with GPS in his school-bag so I could also see that he reaches his destination without any problems. Thankfully, the school is a “no phone” zone, so all the kids handover any phones they may have with them to the security at entrance.

There are a ton of services out there that makes location sharing a breeze. However, hardly any of them are free-software. Digging around I discovered a nice little FOSS app called Owntracks. The idea is that this app sends location data in JSON format to an “MQTT Broker” (server), and the server publishes it to other registered users. The same app allows you to see all registered user locations being published. So it can easily be used as a nice “real-time” location sharing app for the family / close friends.

To my surprise, I learnt that the ejabberd software (bundled with FBX) is also an MQTT Broker. Already a fan of XMPP, this came to me as great news, feeling the joy of having discovered an easter egg on my home server. I’m sharing the steps to activate the MQTT potential of your ejabberd software below. The reference information can be found here. Owntracks was straightforward to setup, so I’m not getting on any details here – just be careful about making sure to use TLS - but feel free to ask.

  1. If you’re using a router make sure to forward ports 1883 and 8883 to your FBX.

  2. On your FBX firewall, allow connection to ports 1883 and 8883. You can easily do this with Cockpit Network Settings as these ports are already pre-labed for MQTT.

  3. In your /etc/ejabberd/ejabberd.yml file, add the following:

listen:
- port: 5280
  ip: "::"
  module: ejabberd_http
  tls: false
  protocol_options: 'TLS_OPTIONS'
  request_handlers:
    /admin: ejabberd_web_admin
    /.well-known/acme-challenge: ejabberd_acme
    /mqtt: mod_mqtt
- port: 1883
  ip: "::"
  module: mod_mqtt
  backlog: 1000
- port: 8883
  ip: "::"
  module: mod_mqtt
  backlog: 1000
  tls: true

modules:
  mod_mqtt: {}

Restart your ejabberd service and you should now (hopefully) be able to communicate through MQTT with your FBX credentials.

Good Luck.

I found MQTT has a lot of other use-cases, especially for IoT.

3 Likes

However, I’ve been trying to support my 10 year old to start going to school on his own. It’s a 20 min. walk but he has to carefully cross a couple of streets, have an eye out for the traffic and move through some dense crowd. Childhood here and now, isn’t like it was for us.

Good for you and your kiddo, and what an amazing application for Freedombox. To be sure, I think we all cheated death in our childhood, so don’t be too hard on yourself but it’s still okay to worry a little. Just wait until you give your child the car keys.

1 Like

One step at a time @joseph : ) hopefully will be getting there : )
Thank you for the kind comment…

This is quite an interesting discovery! Thanks for sharing a working configuration with the community.

Among other things, I found that Owntracks can also be used as a Pedometer to count your steps per day.

@jvalleroy @sunil We can discuss in the next hack call about how to expose the MQTT server and its use cases in the FreedomBox UI.

3 Likes

Are the hack calls announced? I’d like to listen in to that.

Hack and progress calls are announced here:

https://wiki.debian.org/FreedomBox/ProgressCalls

1 Like

Sorry, my bad. I didn’t bring this up in the hack calls.

This was discussed in today’s hack call.
https://wiki.debian.org/FreedomBox/ProgressCalls/2024-02-10

1 Like