MQTT subscriber problem

I’ve just installed emoncms on an Ubuntu VM, with install_mosquitto=false in config.ini. (I already have a working mqtt instance.)

I’m new to this, but my understanding is that there’s a service which runs emoncms_mqtt.php which in turn subscribes to emon/ topics and turns them into inputs. Please tell me if I’ve misunderstood.

In the admin panel, emoncms_mqtt is stuck at “Activating” and doesn’t appear to want to start.

I found the php file and ran it from a command line, and it outputs the following

PHP Fatal error:  Uncaught Error: Class "Mosquitto\Client" not found in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:123
Stack trace:
#0 {main}
  thrown in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 123

Fatal error: Uncaught Error: Class "Mosquitto\Client" not found in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:123
Stack trace:
#0 {main}
  thrown in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 123

I have a great deal of experience as a programmer and sys admin, but I seem to have totally avoided knowing anything useful about php.

Please could someone enlighten me? Is this error spurious or does it point to something that needs installing, and if so, how, please?


This means that the PHP mosquitto client was not installed.
This needs: install_mosquitto_client=

But as you’re post install, you can just run the EmonScripts/install/ script directly after updating that setting. Or run the commands directly:

sudo apt-get install -y libmosquitto-dev
git clone
cd Mosquitto-PHP/
sudo make install
PHP_VER=$(php -v | head -n 1 | cut -d " " -f 2 | cut -f1-2 -d"." )
printf "" | sudo tee /etc/php/$PHP_VER/mods-available/mosquitto.ini 1>&2
sudo phpenmod mosquitto

From EmonScripts/install/ at master · openenergymonitor/EmonScripts · GitHub

Thank you very much. That did it.
Now I see it working and what it does, I think I’ll create a quick alternative in a language I’m familiar with so I’m not tied to the emon topic and don’t need to use an intermediary like Node Red that seems popular.

1 Like