Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MQTT connection to HomeAssistant not working
#1
Hi,

I've received my vAir Monitor today Smile .

Connecting with the Chrome app worked flawlessly. Setting up the Wifi connection too - I can ping the vAir from both my PC and the system that is running HomeAssistant.

I've used the chrome app to setup the MQTT connection to HomeAssistant (v 0.36). I'm using the MQTT broker that is embedded into HA with the default config:
Code:
Setting     Value
Host             <ip>
Port             1883
Protocol     3.1.1
User             homeassistant
Password     <none>
Websocket port     8080

I configured the following sensors in HA:

Code:
sensor:
  - platform: mqtt
    state_topic: "air/temperature"
    name: 'Temp'
    unit_of_measurement: '°C'

Using a MQTT app on android, I can connect to the broker. A publish to the topic immediately shows up in the HA user interface. So I'm guessing that broker and HomeAssistant are set up correctly.

Now, when I try to get the vAir device to publish, it runs into an error:
Quote:Searching for v.Air  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . Searching for v.Air Trying : COM6

 .  . [ŽHÍkèD]
[XÀ…]
[ðB(]
[òðû]
[„•…ÁHeap at start: 37392]
 . [vESPrino v1.16 build20170103]

vESPrino found on : COM6
[)
--- Setup PLUGINS ---
Neopixel
DweetIO]
[nop 0
ready >
WebServer
WebSocketServer]
[PowerManager
GPIO
info

vESPrino v1.16 build20170103
IP address: 192.168.178.233
Chip ID: D549B3
ready >
Servo]
[Annemometer]
[crc40prop_list
prop_list
---vESPrinoCFG_start---
cubic.co2.missing=missing
ds18b20.port=missing
rf.CO2=136
rf.PM25=137
rf.PM10=138
rf.TEMP=140
rf.HUM=141
rf.PRES=142
rf.GEN=143
send.interval=120
temp.adjustment=-0.4
wifi.staticip=192.168.178.233
wifi.gateway=192.168.178.1
wifi.subnet=255.255.255.0
wifi.dns1=192.168.178.1
wifi.ssid=<myssid>
wifi.p1=<the password>
mqtt.server=<home-assistant-host-name>
mqtt.port=1883
mqtt_msg_arr0=air/temp:%TEMP%
oh.cfg={"ohHost":"<home-assistant-host-name>","ohPort":"1883","ohCO2":"","ohTEMP":"air/temp","ohHUM":"","ohPRES":"","ohPM25":"","ohPM10":"","ohLUX":""}
---vESPrinoCFG_end---]
[ready >
TimerManager

--- Setup SENSORS ---
CO2
TEST]
[SI7021
Found SI7021 - Temperature/Humidity Sensor]
[BME280]
[BMP085]
[PM2005
Found PM2005 - Dust / Particle Sensor]
[CDM7160
Found CDM7160 CO2 Sensor
DS18B20
TSL2561]
[BH1750]
[APDS9960]
[--- Setup DESTINATIONS ---
CustomHTTP
SerialDump
MQTT
RFX10]
[Blynk]
[Heap At setup end: 34520
------State changed to: 3
IP address: 192.168.178.233 in 7125 ms
GOT IP
sendNowCond]
[--- DestHanlder: sendValue --- 1
Found SI7021 - Temperature/Humidity Sensor]
[Decimal Separator is: .]
[Raw CO2: 2116]
[CustomHTTPDest::process
SerialDumpDest::process
IP    : 192.168.178.233
CHIPID    : D549B3
RUNTIME    : 7
TEMP    : 23.59
TEMPR    : 23.99
HUM    : 45
PM25    : 11
PM10    : 35
CO2    : 2116
CO2R    : 2116
MQTTDest::process]
[Sending via MQTT: <home-assistant-host-name>,1883]
[Connecting to server :vESPrino,,]
[Could not connect to MQTT server. Will retry on next iteration
ready >]
(if removed hostnames and passwords here. They show up correct in the log)


--> No connection. This will remain the same for all further updates.


HomeAssistant shows an error in the log:
Quote:17-01-21 20:36:04 homeassistant.core: Error doing job: Fatal read error on socket transport Traceback (most recent call last): File "/usr/lib/python3.4/asyncio/selector_events.py", line 582, in _read_ready data = self._sock.recv(self.max_size) TimeoutError: [Errno 110] Connection timed out 17-01-21 20:36:25 hbmqtt.broker: [MQTT-3.1.0-1] (client @=192.168.178.233:15679): Can't read first packet an CONNECT: [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp" 17-01-21 20:38:53 hbmqtt.broker: [MQTT-3.1.0-1] (client @=192.168.178.233:10227): Can't read first packet an CONNECT: [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp"

HomeAssistant is using HBMQTT, which is a "MQTT 3.1.1 compliant broker implementation".

Any ideas? Did anyone get the vAir monitor working with HomeAssistant?
Reply
#2
perhaps there is trouble between the MQTT client that i am using and the MQTT Server
what i found is this one
https://github.com/home-assistant/home-a...issues/854

can you check if you can really make the broker use 3.1.1. and see if it will work then.
Reply
#3
I have setup another MQTT broker, this time Mosquitto and configured it to accept any incoming connection.

I have successfully established connections explicitly using both version 3.1 and version 3.1.1 with both a self written python script and the java based MQTT client MQTT.fx, (and multiple android apps). I can publish messages from any client and will see it immediately in the other clients. I also montior the log file of Mosquitto and can see the connections and message exchange there also. In summary, I'm pretty sure that my MQTT setup is correct and functional and that clients can connect using both protocol versions.

Unfortunately, still no luck with the vAir. I can see no connection attempt of the vAir in the Mosquitto log files.

Here is another log output:

[quote]

Searching for v.Air . . . . . . . . . . . . . . . . . . . Searching for v.Air Trying : COM7

[5]
. . [?HÌkèDXà?]
[ðb(?ðø]
[???ÁHeap at start: 37392]
. [vESPrino v1.16 build20170103]

vESPrino found on : COM7
[IP address: 192.168.178.233
Chip ID: D549B3
ready >
Waiting for auto-connect]
[Found i2c bus on SDA:SCL = D5Big Grin1 (14:5)]
[I2C Bus on SDA:SCA (14:5)
--- Setup PLUGINS ---
Neopixel
crc40prop_list
prop_list]
[---vESPrinoCFG_start---
temp.adjustment=-0.4
cubic.co2.missing=missing
ds18b20.port=missing
rf.CO2=136
rf.PM25=137
rf.PM10=138
rf.TEMP=140
rf.HUM=141
rf.PRES=142
rf.GEN=143
send.interval=120
wifi.staticip=192.168.178.233
wifi.gateway=192.168.178.1
wifi.subnet=255.255.255.0
wifi.dns1=192.168.178.1
wifi.ssid=[hidden]
wifi.p1=[hidden]
mqtt.server=<hostname of my public mqtt broker>
mqtt.port=31883
mqtt.client=vair
mqtt.user=vair
mqtt.pass=vair123
mqtt_msg_arr0=vair/temp:%TEMP%
mqtt_msg_arr1=test/test:hello from vair
mqtt_msg_arr2=test:air is %CO2%
custom_url_arr0=http://192.168.178.47:8000/service?co2=%CO2%
custom_url_arr1=http://192.168.178.47:8000/service?hum=%HUM%
custom_url_arr2=http://192.168.178.47:8000/service?temp=%TEMP%
custom_url_arr3=http://192.168.178.47:8000/service?pres=%PRES%
custom_url_arr4=http://192.168.178.47:8000/service?pm25=%PM25%
custom_url_arr5=http://192.168.178.47:8000/service?pm10=%PM10%]
[---vESPrinoCFG_end---
ready >
DweetIO]
[crc61nop 0
nop 0
ready >
WebServer]
[WebSocketServer]
[PowerManager
GPIO]
[Servo]
[Annemometer]
[TimerManager

--- Setup SENSORS ---
CO2
TEST]
[SI7021
Found SI7021 - Temperature/Humidity Sensor]
[BME280]
[BMP085]
[PM2005
Found PM2005 - Dust / Particle Sensor]
[50,16,7,4,1,68,0,7C,
CDM7160
Found CDM7160 CO2 Sensor
DS18B20
TSL2561]
[BH1750]
[APDS9960]
[--- Setup DESTINATIONS ---
CustomHTTP
SerialDump
MQTT
RFX10]
[Blynk]
[Heap At setup end: 34520]
[------State changed to: 3
IP address: 192.168.178.233 in 8094 ms
GOT IP
sendNowCond]
[--- DestHanlder: sendValue --- 1
Found SI7021 - Temperature/Humidity Sensor]
[Decimal Separator is: .]
[Raw CO2: 1814]
[CustomHTTPDest::process]
[Calling HTTP: [http://192.168.178.47:8000/service?co2=1814]]
[Response Code: 404
CLOSED
Response Code: 404]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 1979]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2053]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2049]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 1
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2028]
[CustomHTTPDest::process]
[Calling HTTP: [http://192.168.178.47:8000/service?co2=2024]
Response Code: 404
CLOSED
Response Code: 404]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2016]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2014]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2012]
[ready >]
[crc71nop
ready >]
[crc00mqtt_msg_clean
mqtt_msg_clean]
[ready >]
[crc01mqtt_setup "<hostname of my public mqtt broker>","31883","vair","vair","vair123"
mqtt_setup "<hostname of my public mqtt broker>","31883","vair","vair","vair123"]
[MQTT Configuration Stored
<hostname of my public mqtt broker>,31883,vair,vair,vair123
DONE
ready >]
[crc0Dmqtt_msg_add "0"vair/temp:%TEMP%
mqtt_msg_add "0"vair/temp:%TEMP%
Mqtt line:vair/temp:%TEMP%]
[ready >]
[crc0Cmqtt_msg_add "1"vair/co2:%CO2%
mqtt_msg_add "1"vair/co2:%CO2%
Mqtt line:vair/co2:%CO2%]
[ready >]
[crc0Emqtt_msg_add "2"jochen/test:hallo vom vair
mqtt_msg_add "2"jochen/test:hallo vom vair
Mqtt line:jochen/test:hallo vom vair]
[ready >]
[crc40mqtt_msg_add "3"test:air is %CO2%
mqtt_msg_add "3"test:air is %CO2%
Mqtt line:test:air is %CO2%]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 1
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 2010]
[CustomHTTPDest::process]
[Calling HTTP: [http://192.168.178.47:8000/service?co2=2022]
Response Code: 404
CLOSED
Response Code: 404]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 1996]
[ready >]
[sendNowCond]
[--- DestHanlder: sendValue --- 0
Found SI7021 - Temperature/Humidity Sensor]
[Raw CO2: 1995]
[ready >]

[quote]

As you can see, I've tried to set up HTTP requests too.

If entered the following "URLs to invoke":
[code]
http://192.168.178.47:8000/service?co2=%CO2%
http://192.168.178.47:8000/service?hum=%HUM%
http://192.168.178.47:8000/service?temp=%TEMP%
http://192.168.178.47:8000/service?pres=%PRES%
http://192.168.178.47:8000/service?pm25=%PM25%
http://192.168.178.47:8000/service?pm10=%PM10%
[code]

But the log output of the http server shows that only one URL is called:
[code]
C:\Users\user>python -m http.server
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.178.233 - - [23/Jan/2017 22:34:05] code 404, message File not found
192.168.178.233 - - [23/Jan/2017 22:34:05] "GET /service?co2=1988 HTTP/1.1" 404 -
192.168.178.233 - - [23/Jan/2017 22:36:18] code 404, message File not found
192.168.178.233 - - [23/Jan/2017 22:36:18] "GET /service?co2=2004 HTTP/1.1" 404 -
192.168.178.233 - - [23/Jan/2017 22:36:58] code 404, message File not found
192.168.178.233 - - [23/Jan/2017 22:36:58] "GET /service?co2=1960 HTTP/1.1" 404 -
[code]

This is in accordance to the logfile which also only reports CO2 values. and MQTT strings for CO2, even though %TEMP% is configured too as a MQTT message:
[code]
vair/temp:%TEMP%
vair/co2:%CO2%
jochen/test:hallo vom vair
test:air is %CO2%
[code]

So there seem to be two problems:
1) MQTT client does not connect to a MQTT broker
2) Only CO2 sensor values show up in the log file and are send via HTTP GET

I hope you can help with this.
Reply
#4
i checked now, and in fact there are two bugs, one that i fixed in the latest release and the other i didn't notice till now
since the first call returns 404
1. Sending to all the other HTTP locations is not done - this is the bug i need to fix, it should try all of them
2. Sending to the MQTT Destination is also aborted - this is what i fixed in the last release

so in general if you remove the http calls (or make the script return 200) - it will go through this and reach teh MQTT part
in MQTT - also - if for some reason sending to one of the topics fails - the others are aborted
Reply
#5
After the firmware upgrade and removing the HTTP requests, my mosquitto MQTT broker now receives data from the vAir device Big Grin

Excellent. Thank you for your help.

I will try again to use the MQTT broker that is integrated into HomeAssistant tonight.


An unrelated feature request:

It is an unusual choice to use GET requests to send data to a HTTP server. POST or PUT would be more appropriate. Could you make this an option?
For example, HomeAssistant only supports POST for HTTP based sensors:
https://home-assistant.io/components/sensor.http/

<-- This would allow an even easier integration into HomeAssistant, without the need for an extra broker that needs to be set up and administered.
Reply
#6
aahh
Itis possible with custonm http requests
But please tell me what is the correct way to integrate with home assistant so that i fix it Smile
Reply
#7
I will send an example later
Reply
#8
Using an HTTP sensor in HomeAssistant is very easy. No configuration necessary in HA at all. The sensor just has to send POST requests to HomeAssistant. They will automatically show up as a sensor, if the correct URL and JSON payload are used.

Here is an example for a temperature sensor, taken from https://home-assistant.io/components/sensor.http/

Code:
$ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \
       -H "Content-Type: application/json" \
       -d '{"state": "20", "attributes": {"unit_of_measurement": "°C", "friendly_name": "Bathroom Temp"}}' \
       http://localhost:8123/api/states/sensor.bathroom_temperature


--> Method must be POST, specific HTTP headers must be included and the payload must be a JSON string that contains the measured value and some static metadata.
Reply
#9
thanks, when i was reading the docs, i found only the MQTT method but not hte HTTP Smile
i will add it.
currently there is no support for arbitrary headers just the content type, i will add also an option to specify generic headers
here is how currently the custom HTTP config has to look like for more details
{"method":"POST","url":"http://things.ubidots.com/api/v1.6/devices/dsds?token=sadssads","ct":"application/json","pay":"{\"sdsd\":%TEMP%}"}
Reply
#10
(01-25-2017, 11:17 AM)admin Wrote: thanks, when i was reading the docs, i found only the MQTT method but not hte HTTP Smile
i will add it.
currently there is no support for arbitrary headers just the content type, i will add also an option to specify generic headers
here is how currently the custom HTTP config has to look like for more details
{"method":"POST","url":"http://things.ubidots.com/api/v1.6/devices/dsds?token=sadssads","ct":"application/json","pay":"{\"sdsd\":%TEMP%}"}

The extra header is only required, if access to HomeAssistant is password protected.

I was trying it out and it immediately worked  Smile

With this http requests, sensor values will immediately show up in HomeAssistant, without any need for a MQTT broker:

Code:
{"method":"POST","url":"http://<home-assistant-host>:8123/api/states/sensor.vair_dust10","ct":"application/json","pay":"{\"state\": \"%PM10%\", \"attributes\": {\"unit_of_measurement\": \"\", \"friendly_name\": \"Staub(10)\"}}"}
{"method":"POST","url":"http://<home-assistant-host>:8123/api/states/sensor.vair_dust25","ct":"application/json","pay":"{\"state\": \"%PM25%\", \"attributes\": {\"unit_of_measurement\": \"\", \"friendly_name\": \"Staub(25)\"}}"}
{"method":"POST","url":"http://<home-assistant-host>:8123/api/states/sensor.vair_co2","ct":"application/json","pay":"{\"state\": \"%CO2%\", \"attributes\": {\"unit_of_measurement\": \"ppm\", \"friendly_name\": \"CO2 Gehalt\"}}"}
{"method":"POST","url":"http://<home-assistant-host>:8123/api/states/sensor.vair_temp","ct":"application/json","pay":"{\"state\": \"%TEMP%\", \"attributes\": {\"unit_of_measurement\": \"C\", \"friendly_name\": \"Temperatur\"}}"}
{"method":"POST","url":"http://<home-assistant-host>:8123/api/states/sensor.vair_humidity","ct":"application/json","pay":"{\"state\": \"%HUM%\", \"attributes\": {\"unit_of_measurement\": \"%\", \"friendly_name\": \"Luftfeuchtigkeit\"}}"}

   
Big Grin

This might be something to add to the documentation.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)