Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Working with Django
      • Background Jobs in Python
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Data For Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Add-ons
  • All Add-ons
  • Stackhero for MQTT Mosquitto
Stackhero for MQTT Mosquitto

This add-on is operated by Stackhero

Mosquitto on dedicated instances, up-to-date versions and attractive prices.

Stackhero for MQTT Mosquitto

Last updated March 25, 2022

Table of Contents

  • Provisioning the Add-on
  • Local Setup
  • Connect to Stackhero Dashboard
  • How to connect to Mosquitto/MQTT using mosquitto_pub and mosquitto_sub
  • Authentication
  • Connecting to MQTT Mosquitto
  • Upgrading Your Plan
  • Removing the Add-on
  • Support
  • Additional Resources

Stackhero for MQTT Mosquitto provides a managed MQTT Mosquitto instance running on a fully dedicated instance to handle thousands devices easily.

The Stackhero for MQTT Mosquitto add-on provides the folowing:

  • A private instance (dedicated VM)
  • A dedicated public IP (v4)
  • TLS encryption (aka SSL)
  • Devices authentication and advanced ACLs via external API
  • An automatic backup every 24 hours
  • One click to update to new MQTT Mosquitto versions

There is an MQTT client library available for most languages including Ruby, Node.js, Java, Python, Clojure, and Erlang.

Provisioning the Add-on

You can attach Stackhero for MQTT Mosquitto via the CLI:

A list of all plans available can be found here.

$ heroku addons:create ah-mosquitto-mqtt-stackhero --app <your app name>
-----> Adding ah-mosquitto-mqtt-stackhero to sharp-mountain-4005... done

After you provision Stackhero for MQTT Mosquitto, the STACKHERO_MOSQUITTO_HOST and STACKHERO_MOSQUITTO_URL_TLS config variables are available in your app’s configuration. They contain the URLs to connect to your MQTT Mosquitto instance.

If you’ve checked the Allow clear connections option in your Mosquitto service, the STACKHERO_MOSQUITTO_URL_CLEAR environment variable will also be available. We don’t recommend using clear connections.

You can see the content of those variables via the heroku config:get command:

$ heroku config:get STACKHERO_MOSQUITTO_URL_TLS
$ heroku config:get STACKHERO_MOSQUITTO_LOGIN
$ heroku config:get STACKHERO_MOSQUITTO_PASSWORD

Local Setup

After you provision the add-on, you must replicate its config variables locally.

Use the Heroku Local command-line tool to configure, run, and manage process types specified in your app’s Procfile. Heroku Local reads configuration variables from an .env file. Use heroku config to view your app’s config variables. Use the following command for each value that you want to add to your .env file:

$ heroku config:get <STACKHERO_MOSQUITTO_VARIABLE> -s  >> .env

For example:

$ heroku config:get STACKHERO_MOSQUITTO_URL_TLS -s  >> .env
$ heroku config:get STACKHERO_MOSQUITTO_LOGIN -s  >> .env
$ heroku config:get STACKHERO_MOSQUITTO_PASSWORD -s  >> .env

Don’t commit credentials and other sensitive configuration values to source-control. In Git, exclude the .env file with: echo .env >> .gitignore.

For more information, see Heroku Local.

Connect to Stackhero Dashboard

You can see your instance usage, restart your instance, and apply updates from the Stackhero dashboard. You can access the dashboard via the CLI:

$ heroku addons:open ah-mosquitto-mqtt-stackhero
Opening ah-mosquitto-mqtt-stackhero for sharp-mountain-4005

You can also visit the Heroku Dashboard, select your application, and then select Stackhero for MQTT Mosquitto from the Add-ons menu.

How to connect to Mosquitto/MQTT using mosquitto_pub and mosquitto_sub

Mosquitto pub/sub CLIs are useful to make some tests. If you want to use them, you will have first to disable the “Allow clear connections” option in your Mosquitto configuration (on Stackhero dashboard).

Once done, subscribe to your Mosquitto on topic #. It means that you will listen for every topics:

$ mosquitto_sub -L -d "mqtts://admin:<PASSWORD>@<STACKHERO_MOSQUITTO_HOST>:8883/#"

Then, in another console, publish the message It works to the topic /sensor/a:

$ mosquitto_pub -L -d "mqtts://admin:<PASSWORD>@<STACKHERO_MOSQUITTO_HOST>:8883/sensor/a" -m "It works"

You should see the message It works (and some debug logs because of the -d flag) appears in your first console.

Authentication

You can authenticate your users and devices connections to Mosquitto manually or with an external API.

Authenticating Manually

Manual authentication is useful when you are testing. If you want to handle more than 10 devices, you should authenticate with an external API.

You can use the manual authentication system to let your backend connect to Mosquitto and use the external API method to let your devices authenticate.

To add a new user, connect to your Stackhero dashboard, then select your Mosquitto service and choose “Configure”. For “Users”, specify a “login” and “password”. You can add up to 20 users with this method.

Authenticating using an External API

Use the external API to authenticate many devices. It can handle thousands of devices.

When a device connects to MQTT, Mosquitto makes an HTTP POST request to your API, passing a JSON string containing the username and the password for the device. If your API replies with an HTTP status code 200, the device is authorized. If it replies with a 401 (unauthorized) or another code, the device authentication is rejected.

The same mechanism is used to check if the device can connect as super user.

For ACLs, 4 parameters are be passed: username, clientId, topic, acc. Your API must confirm username is allowed to make an acc type request on topic. acc can have the following values:

  • 1 - read access
  • 2 - write access
  • 3 - read and write access
  • 4 - subscribe access

For example, if the user userA tries to subscribe to the topic sensors/temperatures, your API receives the following JSON data:

{
  "username": "userA",
  "clientId": "userA",
  "topic": "sensors/temperatures",
  "acc": 4
}

See Gettng Started with Mosquitto to see an example API authentication server written in Jode.js.

Connecting to MQTT Mosquitto

You can retrieve your MQTT Mosquitto URL, username, and password via the following environment variables:

  • STACKHERO_MOSQUITTO_URL_TLS
  • STACKHERO_MOSQUITTO_LOGIN
  • STACKHERO_MOSQUITTO_PASSWORD

Upgrading Your Plan

You can’t downgrade an existing add-on.

Use the heroku addons:upgrade command to migrate to a new plan.

$ heroku addons:upgrade ah-mosquitto-mqtt-stackhero:newplan
-----> Upgrading ah-mosquitto-mqtt-stackhero:newplan to sharp-mountain-4005... done
       Your plan has been updated to: ah-mosquitto-mqtt-stackhero:newplan

Manage migration timing to ensure your application is available during the migration process.

Removing the Add-on

You can remove Stackhero for MQTT Mosquitto via the CLI:

This destroys all associated data and can’t be undone!

$ heroku addons:destroy ah-mosquitto-mqtt-stackhero
-----> Removing ah-mosquitto-mqtt-stackhero from sharp-mountain-4005... done

Support

Stackhero for MQTT Mosquitto support and runtime issues should be submitted via one of the Heroku Support channels. We recommend adding support@stackhero.io in copy for urgent issues.

Additional Resources

  • MQTT Mosquitto documentation by Stackhero
  • MQTT Mosquitto managed cloud

Keep reading

  • All Add-ons

Feedback

Log in to submit feedback.

Ziggeo Stackhero for MySQL

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies
  • Cookie Preferences