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?

Thanks.

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/mosquitto.sh script directly after updating that setting. Or run the commands directly:

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

From EmonScripts/install/mosquitto.sh 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.
Onwards!

1 Like