Emoncms_mqtt.php fails after 10 seconds

I’m a bit at loss.
I’ve installed Emoncms on a local Ubuntu 18.04 server.
Redis is up, mqtt up and working, apache also.
I can enter the gui on my local server.
I can add input through url’s and see the inputs. SO all seems fine.
BUT, somehow I failt to get emoncms_mqtt working. It works shortly, and I do get data into inputs through the MQTT broker, but the emoncms_mqtt fails after 10 second running.

If I run the emoncms_mqtt.php script, I can see where it fails, but I don’t get why it fails… (see below).

Anyone an idea what could be at hand?

[email protected]:~# /usr/bin/php /var/www/html/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php
PHP Fatal error:  Uncaught Error: Call to a member function hgetall() on boolean in /var/www/html/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:155
Stack trace:
#0 {main}
  thrown in /var/www/html/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 155

Fatal error: Uncaught Error: Call to a member function hgetall() on boolean in /var/www/html/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:155
Stack trace:
#0 {main}
  thrown in /var/www/html/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 155

Hi, welcome.

This appears to be a Redis issue. There are specific instructions on installing Redis. How did you install the server and the php extension?

I’ve installed redis, and it appears to work (tested). See also below.
I also installed php-redis (sudo apt-get install php-redis).

Any clue what/where to look for?

 redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-04-29 09:26:49 UTC; 38s ago
     Docs: http://redis.io/documentation,
  Process: 442 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 477 (redis-server)
   CGroup: /system.slice/redis-server.service
           └─477 /usr/bin/redis-server

There is a difference between the redis-server and the php extension. That systemctl output is just the server.

[YOUR IP]/emoncms/php-info.php opened in a browser on the same LAN will give you an output of phpinfo and will list the redis extension in use.

Emoncms installs the php extension by pecl to get the right version. There are a number of threads on the community about this.

You need to remove php-redis

sudo apt-get purge php-redis

then follow the instructions here

sudo pecl install redis


I am beginning to wonder if it is because it is trying to access a key that might not exist - I cannot test until tonight what happens. However, I cannot believe that this has not appeared before but…

Once you have installed phpredis by pecl - if the error still exists, add in a ‘publish to mqtt’ element in an input process (do not use ‘emon’ as the base topic) and see if the error goes away.

Thanks for helping me!

I followed your suggestions (purged the ubuntu version, reinstalled redis )

Phpinfo gives this:

Redis Support: enabled
Redis Version: 4.3.0
Available serializers: php, igbinary

Unfortunately, it still fails after about 10 seconds…

So how about the “add in a ‘publish to mqtt’ element in an input process”. I would like to test that, but could you please give a hint of where/how to do that? In Emoncms or CLI, or send a MQTT from another computer?

On the input page, edit the input processing and add a stage ‘publish to mqtt’ - should be reasonably obvious. 2. Log Locally - Guide | OpenEnergyMonitor

I’m not in front of an installation to be able to offer more detailed help right now.

Ah, while looking there I notice that some options are grayed out “(needs REDIS)” behind them.
So I do get the feeling that emoncms is not using REDIS somehow??

Obvious question, but have you enabled it in the settings.php for emoncms?

And now I feel a bit stupid… I had it enabled at first, but that didn’t work… So I disabled it, followed your settings/install advice, but forgot to reenable it.
So now it works! I’m very happy!

Many many thanks! Wonderful to be helped here so quickly and gently!

1 Like