eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.8k stars 2.36k forks source link

1552419065: Socket error on client NAME, disconnecting. #1197

Open freekvh opened 5 years ago

freekvh commented 5 years ago

I noticed some Issues with a similar topic yet I feel mine is a bit different. I use Mosquitto on hass.io, this is what my log looks like (on repeat):


1552419184: New connection from 192.168.1.3 on port 1883.
1552419184: |-- mosquitto_auth_unpwd_check(freek-mqtt)
1552419184: |-- ** checking backend http
1552419184: |-- url=http://127.0.0.1:8080/login
1552419184: |-- data=username=freek-mqtt&password=Sneek676&topic=&acc=-1&clientid=
[INFO] found freek-mqtt on local database
1552419186: |-- getuser(freek-mqtt) AUTHENTICATED=1 by http
1552419186: New client connected from 192.168.1.3 as slimme_meter (c1, k30, u'freek-mqtt').
1552419186: |-- mosquitto_auth_acl_check(..., client id not available, freek-mqtt, home/smart_meter/huidig_verbruik, MOSQ_ACL_WRITE)
1552419186: |-- aclcheck(freek-mqtt, home/smart_meter/huidig_verbruik, 2) CACHEDAUTH: 0
1552419186: |-- mosquitto_auth_acl_check(..., client id not available, freek-mqtt, home/smart_meter/energie_geleverd, MOSQ_ACL_WRITE)
1552419186: |-- aclcheck(freek-mqtt, home/smart_meter/energie_geleverd, 2) CACHEDAUTH: 0
1552419186: |-- mosquitto_auth_acl_check(..., client id not available, freek-mqtt, home/smart_meter/gasmeterstand, MOSQ_ACL_WRITE)
1552419186: |-- aclcheck(freek-mqtt, home/smart_meter/gasmeterstand, 2) CACHEDAUTH: 0
1552419186: Socket error on client slimme_meter, disconnecting.

This is the code I use to connect:

#!/usr/bin/python3
"""
A script to read the slimme meter and send out the results via mqtt.
"""

import serial
import sys
import paho.mqtt.client as mqtt

# Dictionary of the data we need
code2value = {'1-0:1.8.1'  : 'laag_tarief_meter_geleverd',
              '1-0:1.8.2'  : 'hoog_tarief_meter_geleverd',
              '1-0:1.7.0'  : 'huidig_verbruik',
              '0-1:24.2.1' : 'gasmeterstand'}

# Configure the parameters needed to read the port
ser = serial.Serial()
ser.baudrate = 115200
ser.port="/dev/ttyUSB0"

# Open the connection
ser.open()

# Initiate mqtt connection
broker_address="rpi2.hmrt.nl" # Set the mqtt broker address
client = mqtt.Client(client_id="slimme_meter") #create new instance
client.username_pw_set('freek-mqtt', password='Sneek676')
client.connect(broker_address, keepalive=30) #connect to broker

# Capture one full telegram, terminate at the first "!"
telegram = []
line = ''
while '!' not in line:
    line = ser.readline().decode('utf-8')
    telegram.append(line)

# Select only the values of interest, add to a new dictionary, we do this because
# we first want to combime hoog and laag tarief before publishing
quantity2value = dict()
for line in telegram:
    for code in code2value:
        if code in line:
            value    = float(line.split('(')[-1].split('*')[0])
            unit     = line.split('(')[-1].split('*')[-1].replace(')','')
            quantity = code2value[code]
            quantity2value[quantity] = value
# Compute the total "energie geleverd"
quantity2value['energie_geleverd'] = quantity2value['laag_tarief_meter_geleverd'] + quantity2value['hoog_tarief_meter_geleverd']

# Define the quantities of interest and publish using mqtt
quantities = ['huidig_verbruik', 'energie_geleverd', 'gasmeterstand']
for quantity in quantities:
    #print(quantity, round(quantity2value[quantity], 3))
    client.publish('home/smart_meter/'+quantity, round(quantity2value[quantity], 3)) #publish
    print(quantity, round(quantity2value[quantity], 3))

I don't understand the issues, I had mqtt working before without authentication but it suddenly stopped working so I went this way. Does anyone understand what happens?

karlp commented 5 years ago

so, you had it working without authentication and then that stopped? Or, I tried adding authentication and now it doens' twork? It presnetly just looks like you have an auth plugin that is refusing you. Whether that was you rgoal or not is beyond me, but it's a config "issue" with your use of that plugin.

freekvh commented 5 years ago

Indeed, mqtt using Mosquitto has been very shacky for me, it worked a couple of times until hass.io updates. But I uninstalled Mosquitto and now use the hass.io build-in mqtt server of hass.io and it works well.

It could indeed be a config issue but then it is strange that it worked every now and then with the same config.

sadamchandra commented 3 weeks ago

the same issue was observed in my setup also i am using mosquitto-1.5.5 getting below log continuously, Socket error on client disconnecting

sadamchandra commented 3 weeks ago

any update on the above issue