phpmqtt_input is not connecting to broker

Shouldn't i see a subscription to "emon/rx" in my broker when i start the mqtt_input service?

I can confirm that the mosquitto_sub and mosquitto_pub clients are working.
Also Mosquitto-PHP is working because example code is working if i run it in my workstation browser.
I can see everything in my broker message log.

There are no errors in the webserver, php or mqtt_input logs.

glyn.hudson's picture

Re: phpmqtt_input is not connecting to broker

If you're running the latest 'emon-pi' emonhub it postes to both  emonhub/ and emon/ topics.

See: https://github.com/emoncms/emoncms/blob/master/docs/RaspberryPi/MQTT.md

emonhub/rx topic is used for the emonPi LCD service. The emon/ topic (no rx) is used for mqtt_input. The topic name and MQTT server details need ot be set in emoncms settings.php:

https://github.com/emoncms/emoncms/blob/master/default.emonpi.settings.p...

Could you paste the output of mosquitto_sub on '#'  (all topics)

You should see in emoncms log:

2016-02-26 01:16:49.331|WARN|phpmqtt_input.php|Connecting to MQTT server: Connection Accepted.: code: 0
2016-02-26 01:16:49.332|WARN|phpmqtt_input.php|Subscribed to topic: emon/#

MrGlasspoole's picture

Re: phpmqtt_input is not connecting to broker

I'm not using emonhub.

All I see is:
2016-02-28 02:23:13.973|WARN|phpmqtt_input.php|Starting MQTT Input script

But when is that logged? What triggers this warning?
Because "systemctl restart mqtt_input.service" does not show this again in the log.

Also there is nothing in mqtt_input.log
What are the file permissions, owner and group for that file?

~# mosquitto_pub -h 192.168.0.12 -t "emon/10/power" -m "12345"
shows up in my broker:
Client mosqpub/10298-PROTEUS-I sent a message to topic "emon/10/power": "12345" (QoS: 0, retained: false)

Also the php testfile shows up:
Client mosq/ba?2ECrDTpvpFp^6Qe sent a message to topic "/hello": "Hello from PHP at 2016-02-28 01:37:04" (QoS: 1, retained: false)
 

 

glyn.hudson's picture

Re: phpmqtt_input is not connecting to broker

You could try letting the log level in emoncms to info to get more log messages.

Also you could try running the input script directly by cd'ing into the scrips folder then running with

php phpmqtt_input.php

MrGlasspoole's picture

Re: phpmqtt_input is not connecting to broker

Already tried that. Also found the old mqtt_input_publisher.php and phpMQTT.php and copied them to another directory on my server and can also with tem confirm that Mosquitto-PHP is working (broker logs it).

But there must be something wrong with emoncms.log.
In phpmqtt_input.php i can see i should have a "Starting MQTT Input script" every time i start the mqtt_input.service.

I deleted mqtt_input.service and did:
touch /var/log/emoncms.log
chmod 666 /var/log/emoncms.log

The log stays empty.
I tried:
chown root:root /var/log/emoncms.log
chown root:www-data /var/log/emoncms.log
chown www-data:root /var/log/emoncms.log
chown www-data:www-data /var/log/emoncms.log
 

fcattaneo's picture

Re: phpmqtt_input is not connecting to broker

Also I had some problem with my emoncms stand alone ( no emonhub) to see as input the topic published in my mqtt network.
 ( mosquitto broker and some sensor working with mqtt and esp8266 )

 

After some test i fix the problem changing the basetopic in the file /var/www/emoncms/phpmqtt_input.php

The default is

'basetopic' => "nodes"

and is necessary all publischer send messages according to  this basetopic.

 

Ciao,

Fabrizio

 

 

MrGlasspoole's picture

Re: phpmqtt_input is not connecting to broker

You mean in settings.php?
phpmqtt_input.php is pulling it from the settings.php
And in settings.php i have 'basetopic'=> 'emon'

But the thing is that my log stays empty and i guess i have to fix that first.
I changed in settings.php to: $log_filename = dirname(__FILE__).'/' . 'emoncms.log';

That creates a emoncms.log with www-data:www-data
and i can see the path is right in Administration above the logging window:
View last entries on the logfile: /var/www/proteus-iv/stats/emoncms.log

Also tried 777 on that file.
 

 

MrGlasspoole's picture

Re: phpmqtt_input is not connecting to broker

After playing around with settings in the phpmqtt_input.php and loading the phpmqtt_input.php in the browser i got the subscription in my broker.
Also sending something with MQTT.fx shows up on inputs in Emoncms.

So i checked the daemon.log and first thing was that mqtt_input says it can not connect to the DB.
I did set username and password to my root user of MySQL for testing.
The error disappears but still the daemon does not subscribe.

A "systemctl restart mqtt_input.service" gives me:

mqtt_input[700]: Stopping Daemon for the emoncms MQTT script: start-stop-daemon: warning: failed to kill 626: No such process
mqtt_input[700]: 1 pids were not killed
mqtt_input[700]: No process in pidfile '/var/run/mqtt_input.pid' found running; none killed.
systemd[1]: mqtt_input.service: control process exited, code=exited status=1
systemd[1]: Unit mqtt_input.service entered failed state.
mqtt_input[703]: Starting Daemon for the emoncms MQTT script: mqtt_input.

EDIT
It's driving me crazy. Now magically the emoncms.log works.
The daemon does not work. Excluding the "phpmqtt_input.lock" check in phpmqtt_input.php and calling the file in my browser really shows up in the log:
Connecting to MQTT server: Connection Accepted.: code: 0
Subscribed to topic: emon/#

But you do not have a disconnected warning and there should be some lastWill or retained message implemented.

Hm, how to get the daemon running?

 

MrGlasspoole's picture

Re: phpmqtt_input is not connecting to broker

No idea why i can't start the daemon or how find out where the problem is?

manicmoddin's picture

Re: phpmqtt_input is not connecting to broker

Hi,

Out of curiosity, where is the installation of emoncms located.

Ages go I installed to /var/www/html/emoncms, which breaks everytime there is an update as they expect it to be pointing at /var/www/emoncms.

When I was having the new version od emonhub, I had to change the mqtt_input daemon that is within the scripts folder to point at the correct address (or symbolic link emoncms -> html/emoncms in the /var/www folder).

Hope this gets you going.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.