1/ Where can I set my own mosquitto broker informations (IP, user, password) in emoncms ?
2/ I understood that sensors shall publish on topics “emon/nodexxx/poweryyy” ( ex emon/kitchen/fridge ?) but what about the expected content format/unit ?
posted as the payload to topic emon/weather would load 2 values. As there is a time element (UNIX time in seconds), it will load that input with that timestamp.
Thank you !
I found it and update with my data as following:
//3 #### MQTT
// The 'subscriber' topic format is rx/* - where * is the emoncms input node number.
// The 'publisher' topic format is user selectable from the 'Publish to MQTT' input process, for example power/solar
$mqtt_enabled = true; // Activate MQTT by changing to true
$mqtt_server = array( 'host' => '192.168.1.180',
'port' => 1883,
'user' => 'mqtt',
'password' => 'my_password',
'basetopic'=> 'emon',
'client_id' => 'emoncms'
);
my mqtt broker is on 192.168.1.180, user mqtt and password set.
I was expecting to see a connexion from ‘emoncms’ or 192.168.1.152 (my test server where emoncms is currently setup), but I seen none of those in mosquitto logs.
Have you created that user/password pair on that broker? If not, and if any other connections you make to it are anonymous, just leave user & password as a blank string.
Hi!
Yes, I use this mqtt broker for a while now ( some Tasmota devices and my own weather station ).
I have disabled anonymous connexion and use only one user ‘mqtt’ + password (no SSL, it’s only on my LAN).
I rebooted the emoncms device after changing settings (I was not sure how to restart/load new settings).
Ok I found several issues
mosquitto-client was not installed…now it’s installed.
I subscribed with the command line to ‘#’ so I can see all topics.
It works fine.
I was able to see the connexion from 192.168.1.152 in mosquitto (due to mosquitto_sub).
I reboot again, but no connexion from emoncms.
I though it was maybe missing some dependancies in emoncms and I found this page:
An other hit!
My emoncms is installed in /var/www/html
I corrected the link but there seems to be some path hardcoded to /var/www/emoncms… Inside the mqtt files.
I will check a bit more, maybe re install will be necessary.
Btw, I run 9.9.9, I expect not too old (download recently)
Hi !
The point is that I installed emoncms in /var/www/html
I followed the howto, but I come to this directory, I figured out that /var/www was not the right place for my setup, this directory is not visible using http from my laptop.
Would it work with a link the other way ? I mean: ln -s /var/www/html/emoncms /var/www/emoncms ?
Maybe, I can’t remember; apache is a bit strict about following symlinks so depending on how yours is configured and exactly what paths are followed you may or may not trip up over something. I can’t be bothered to work it out - it’s simpler just to try it
But even easier would probably be to just move your install
mv /var/www/html/emoncms /var/www
and then install the same link that Paul showed you. That way you end up with a common situation that will be easier next time you have a problem (if you do!)
May 23 12:03:16 gunther systemd[1]: emoncms_mqtt.service: Service hold-off time over, scheduling restart.
May 23 12:03:16 gunther systemd[1]: emoncms_mqtt.service: Scheduled restart job, restart counter is at 856.
May 23 12:03:16 gunther systemd[1]: Stopped Emoncms emoncms_mqtt script.
May 23 12:03:16 gunther systemd[1]: Started Emoncms emoncms_mqtt script.
May 23 12:03:16 gunther emoncms_mqtt[31043]: PHP Fatal error: Uncaught Error: Class 'Mosquitto\Client' not found in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:113
May 23 12:03:16 gunther emoncms_mqtt[31043]: Stack trace:
May 23 12:03:16 gunther emoncms_mqtt[31043]: #0 {main}
May 23 12:03:16 gunther emoncms_mqtt[31043]: thrown in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 113
May 23 12:03:16 gunther emoncms_mqtt[31043]: Fatal error: Uncaught Error: Class 'Mosquitto\Client' not found in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php:113
May 23 12:03:16 gunther emoncms_mqtt[31043]: Stack trace:
May 23 12:03:16 gunther emoncms_mqtt[31043]: #0 {main}
May 23 12:03:16 gunther emoncms_mqtt[31043]: thrown in /var/www/emoncms/scripts/services/emoncms_mqtt/emoncms_mqtt.php on line 113
May 23 12:03:16 gunther systemd[1]: emoncms_mqtt.service: Main process exited, code=exited, status=255/n/a
May 23 12:03:16 gunther systemd[1]: emoncms_mqtt.service: Failed with result 'exit-code'.
line 113 of the php file is: $mqtt_client = new Mosquitto\Client($mqtt_server['client_id'],true);
Yes I assume it’s to create the mqtt client.
but does not work. Maybe the php mosquitto addon is not correctly installed, but I followed the howto.
Only changed 7.0 to 7.2 here:
/etc/php/7.0/mods-available/mosquitto.ini
(I dont have 7.0 directory)
I try to find a short php test of mosquitto module
edit:
hmm I guess it’s an issue with php mosquitto module
and got this error in apache log: [Thu May 23 12:34:14.899863 2019] [php7:error] [pid 19351] [client 192.168.1.14:44826] PHP Fatal error: Uncaught Error: Class 'Mosquitto\\Client' not found in /var/www/html/test2.php:3\nStack trace:\n#0 {main}\n thrown in /var/www/html/test2.php on line 3
edit2: short code to test the module:
<?php
if (!extension_loaded('Mosquitto-php')) {
echo "Mosquitto not loaded";
} else {
echo "Mosquitto loaded";
}
?>
shows Mosquitto not loaded on my side.
I will dig on this