sumnerboy12 / mqtt-gpio-monitor

Python script for sending/receiving commands to/from GPIO pins via MQTT messages
46 stars 23 forks source link

ERROR Error connecting to localhost:1833: [Errno 97] Address family not supported by protocol #3

Closed bgewehr closed 9 years ago

bgewehr commented 9 years ago

Hi Sumnerboy,

i am trying to use your code for my idea of garden water management with a pi and some stuff like magnetic valves and flow meters connected to the gpio.

That error message appears in the logfile and doesn't mean anything to me, can you tell something about it?

2015-06-04 21:41:07,980 INFO Starting mqtt-gpio-monitor 2015-06-04 21:41:07,983 INFO INFO MODE 2015-06-04 21:41:07,985 DEBUG DEBUG MODE 2015-06-04 21:41:07,987 DEBUG INIFILE = mqtt-gpio-monitor.ini 2015-06-04 21:41:07,989 DEBUG LOGFILE = mqtt-gpio-monitor.log 2015-06-04 21:41:08,007 INFO RPi.GPIO module detected... 2015-06-04 21:41:08,010 DEBUG Monitoring pins [21, 22, 23, 24] 2015-06-04 21:41:08,021 DEBUG Initialising GPIO input pin 21... 2015-06-04 21:41:08,025 DEBUG Initialising GPIO input pin 22... 2015-06-04 21:41:08,028 DEBUG Initialising GPIO input pin 23... 2015-06-04 21:41:08,030 DEBUG Initialising GPIO input pin 24... 2015-06-04 21:41:08,032 DEBUG Connecting to localhost:1833... 2015-06-04 21:41:08,072 ERROR Error connecting to localhost:1833: [Errno 97] Address family not supported by protocol

Thank you very much!

sumnerboy12 commented 9 years ago

Is your MQTT broker running on the Pi?

bgewehr commented 9 years ago

yes, i have a valid connection to mosquitto from fhem and the service is running on the pi.

sumnerboy12 commented 9 years ago

Can you try using 127.0.0.1 as the host address instead of localhost?

On 5/06/2015 8:43 a.m., Bernd Gewehr wrote:

yes, i have a valid connection to mosquitto from fhem and the service is running on the pi.

— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/3#issuecomment-109044044.

bgewehr commented 9 years ago

2015-06-04 22:44:43,059 ERROR Error connecting to 127.0.0.1:1833: [Errno 111] Connection refused

sumnerboy12 commented 9 years ago

Can you connect using mosquitto_sub with the same connection properties?

Do you have authentication enabled/TLS?

On 5/06/2015 8:45 a.m., Bernd Gewehr wrote:

2015-06-04 22:44:43,059 ERROR Error connecting to 127.0.0.1:1833: [Errno 111] Connection refused

— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/3#issuecomment-109044505.

bgewehr commented 9 years ago

no auth is enabled as far as i know. Sorry, don't know what mosquitto_sub is.

sumnerboy12 commented 9 years ago

It is the mosquitto subscription client - very useful for debugging these sorts of things. Google around and give it a try. Will hopefully shed some light as to why you cannot connect. I don't think this is anything to do with mqtt-gpio-monitor but I could be wrong!

On 5/06/2015 8:49 a.m., Bernd Gewehr wrote:

no auth is enabled as far as i know. Sorry, don't know what mosquitto_sub is.

— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/3#issuecomment-109045502.

bgewehr commented 9 years ago

i'll try that. Thank you!

bgewehr commented 9 years ago

pi@raspberrypi /usr/local/mqtt-gpio-monitor $ mosquitto_sub -d -h localhost -p 1883 -t Gartenwasser/IO/+ Received CONNACK Received SUBACK Subscribed (mid: 1): 0 is that good?

sumnerboy12 commented 9 years ago

Yep - that looks ok I think. I am not sure I ever tried running my MQTT broker on the same Pi. Can you try using tcp://127.0.0.1 as the host address?

bgewehr commented 9 years ago

Now not better: 2015-06-05 09:17:25,950 ERROR Error connecting to tcp://127.0.0.1:1833: [Errno -2] Name or service not known

bgewehr commented 9 years ago

Maybe the idea is to place mosquitto on the other pi where fhem is running?

bgewehr commented 9 years ago

Not really: 2015-06-05 09:22:59,190 ERROR Error connecting to fhem:1833: [Errno 111] Connection refused pi@

bgewehr commented 9 years ago

I can connect to test.mosquitto.org without errors. Damned!

bgewehr commented 9 years ago

I used the Debian package for mosquitto, it tells to be V 0.15-2. Is this the right one?

bgewehr commented 9 years ago

Now installed latest stable version 1.4.2 from mosquitto.org. No change. May it be a problem of which user it is mosquitto runs on?

bgewehr commented 9 years ago

Now look at this: @raspberrypi ~/mqtt-gpio-monitor $ sudo mosquitto 1433490835: mosquitto version 1.4.2 (build date Mon, 18 May 2015 15:25:19 +0100) starting 1433490835: Using default config. 1433490835: Opening ipv4 listen socket on port 1883. 1433490835: Opening ipv6 listen socket on port 1883. 1433490835: Warning: Address family not supported by protocol

Turns out to be a mosquitto issue so if you have any suggestions you're welcome but otherwise we better close here!

bgewehr commented 9 years ago

On the other hand fhem connects without problems: 1433490884: New connection from 192.168.178.48 on port 1883. 1433490884: New client connected from 192.168.178.48 as NetMQTTpm11731 (c1, k60).

bgewehr commented 9 years ago

Maybe an IPV6 issue?

sumnerboy12 commented 9 years ago

Sorry Bernd, been out all evening and just returned home. Can you post your mosquitto config file?

On 05/06/2015 8:22 p.m., Bernd Gewehr wrote:

Maybe an IPV6 issue?

— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/3#issuecomment-109201266.

bgewehr commented 9 years ago

oot@raspberrypi:/etc/mosquitto# cat mosquitto.conf

Place your local configuration in /etc/mosquitto/conf.d/

#

A full description of the configuration file is at

/usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d root@raspberrypi:/etc/mosquitto#

bgewehr commented 9 years ago

conf.d is empty, just a readme in there!

bgewehr commented 9 years ago

I wonder why nobody else has reported this issue because i used a clean actual raspian and just put those few packages onto it. Schould be pretty new and clean...

bgewehr commented 9 years ago

Missing dependencies? How could i investigate?

sumnerboy12 commented 9 years ago

Try adding

# Security
allow_anonymous true

# Default listener
listener 1883
protocol mqtt

and restarting mosquitto

bgewehr commented 9 years ago

Sorry, no change: 2015-06-06 20:36:33,044 INFO Starting mqtt-gpio-monitor 2015-06-06 20:36:33,049 INFO INFO MODE 2015-06-06 20:36:33,051 DEBUG DEBUG MODE 2015-06-06 20:36:33,053 DEBUG INIFILE = mqtt-gpio-monitor.ini 2015-06-06 20:36:33,055 DEBUG LOGFILE = mqtt-gpio-monitor.log 2015-06-06 20:36:33,073 INFO RPi.GPIO module detected... 2015-06-06 20:36:33,076 DEBUG Monitoring pins [21, 22, 23, 24] 2015-06-06 20:36:33,088 DEBUG Initialising GPIO input pin 21... 2015-06-06 20:36:33,091 DEBUG Initialising GPIO input pin 22... 2015-06-06 20:36:33,093 DEBUG Initialising GPIO input pin 23... 2015-06-06 20:36:33,096 DEBUG Initialising GPIO input pin 24... 2015-06-06 20:36:33,099 DEBUG Connecting to 127.0.0.1:1833... 2015-06-06 20:36:33,104 ERROR Error connecting to 127.0.0.1:1833: [Errno 111] Connection refused

bgewehr commented 9 years ago

What about using the ipv6 loopback address?

bgewehr commented 9 years ago

2015-06-06 20:38:56,913 INFO Starting mqtt-gpio-monitor 2015-06-06 20:38:56,916 INFO INFO MODE 2015-06-06 20:38:56,919 DEBUG DEBUG MODE 2015-06-06 20:38:56,921 DEBUG INIFILE = mqtt-gpio-monitor.ini 2015-06-06 20:38:56,923 DEBUG LOGFILE = mqtt-gpio-monitor.log 2015-06-06 20:38:56,931 INFO RPi.GPIO module detected... 2015-06-06 20:38:56,934 DEBUG Monitoring pins [21, 22, 23, 24] 2015-06-06 20:38:56,946 DEBUG Initialising GPIO input pin 21... 2015-06-06 20:38:56,949 DEBUG Initialising GPIO input pin 22... 2015-06-06 20:38:56,952 DEBUG Initialising GPIO input pin 23... 2015-06-06 20:38:56,954 DEBUG Initialising GPIO input pin 24... 2015-06-06 20:38:56,957 DEBUG Connecting to ::1:1833... 2015-06-06 20:38:56,977 ERROR Error connecting to ::1:1833: [Errno 97] Address family not supported by protocol

bgewehr commented 9 years ago

Not better...

bgewehr commented 9 years ago

Now I have IPv6 successfully enabled. The address family failures are gone but connection refused stays the result!

sumnerboy12 commented 9 years ago

Can you retry mosquitto_sub on the Pi and confirm it is connecting ok and able to receive messages?

Running out of ideas here... On 7/06/2015 8:07 am, "Bernd Gewehr" notifications@github.com wrote:

Now I have IPv6 successfully enabled. The address family failures are gone but connection refused stays the result!

— Reply to this email directly or view it on GitHub https://github.com/sumnerboy12/mqtt-gpio-monitor/issues/3#issuecomment-109644234 .

bgewehr commented 9 years ago

Now no longer: root@raspberrypi:/home/pi/mqtt-gpio-monitor# mosquitto_sub -d -t + Received CONNACK Connection Refused: not authorised

Thank you for your time!

sumnerboy12 commented 9 years ago

Ok - so you seem to have some sort of authentication configured - this is not an issue with mqtt-gpio-monitor but your mosquitto install. Do you definitely have allow_anonymous true in your mosquito.conf? You should focus on getting mosquitto_sub to work with your broker before worrying about mqtt-gpio-monitor.

bgewehr commented 9 years ago

Found that now: 1433622796: New connection from 127.0.0.1 on port 1883. 1433622796: Sending CONNACK to 127.0.0.1 (0, 5) 1433622796: Socket error on client , disconnecting. 1433623179: Saving in-memory database to /tmp/mosquitto.db. 1433624754: New connection from ::1 on port 1883. 1433624754: Sending CONNACK to ::1 (0, 5) 1433624754: Socket error on client , disconnecting. 1433624980: Saving in-memory database to /tmp/mosquitto.db. 1433625008: mosquitto version 1.4.2 terminating 1433625008: mosquitto version 1.4.2 (build date Mon, 18 May 2015 15:25:19 +0100) starting r

bgewehr commented 9 years ago

So the socket seems to be the issue. do you agree?

sumnerboy12 commented 9 years ago

I have never seen a mosquitto broker die like that - must be something to do with your broker install/config - sorry a bit beyond my level of expertise! Might be worth a question in the mosquitto forums?

bgewehr commented 9 years ago

here again my mosquitto.conf: allow_anonymous true autosave_interval 1800 connection_messages true log_dest file /var/log/mosquitto/mosquitto.log log_dest stderr log_dest topic log_type error log_type warning log_type notice log_type information log_type all log_type debug log_timestamp true

message_size_limit 10240

password_file jp.pw

acl_file jp.acl

persistence true persistence_location /tmp/ persistence_file mosquitto.db persistent_client_expiration 1m

pid_file xxxx

retained_persistence true listener 1883 listener 8883 tls_version tlsv1 cafile /etc/mosquitto/ca_certificates/ca.crt certfile /etc/mosquitto/certs/server.crt keyfile /etc/mosquitto/certs/server.key require_certificate false

include_dir /etc/mosquitto/conf.d

I'll go over to the mosquitto mailing list. Thank you again for your help!

egro commented 9 years ago

I am also having this issue. Everything is on the single pi.

knsakib commented 7 years ago

I am also having the same issue. It works for the first time. But afterward, I am this error.

sumnerboy12 commented 7 years ago

This issue has been closed as it is not related to mqqt-gpio-monitor but a broker config/connection issue.