[SOLVED] ESP8266MQTTClientGateway problem



  • The ESP8266 gateway does not connect to the Mosquitto server (on a RPi). The broker is up and running, all other type of clients can connect and pub/sub messages and the ESP8266 is up and running on the network. Here are a few lines from the log:

    AtxGùHøÙ¬D:läÿ0;255;3;0;9;Starting gateway (RNNGE-, 2.0.0-beta)
    0;255;3;0;9;Radio init successful.
    scandone
    state: 0 -> 2 (b0)
    .state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 4
    pm open phy_2,type:2 0 0
    cnt

    connected with XXXXX, channel 6
    ip:192.168.1.22,mask:255.255.255.0,gw:192.168.1.1
    .IP: 192.168.1.22
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;read and forward: 54-22-8 s=1,c=1,t=17,pt=5,l=4,sg=0
    0;255;3;0;9;send: 54-0-52-8 s=1,c=1,t=17,pt=5,l=4,sg=0,st=fail:2168321
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;read: 22-22-0 s=4,c=1,t=0,pt=7,l=5,sg=0:-18.5
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;read: 56-22-0 s=1,c=1,t=0,pt=7,l=5,sg=0:0.7
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;read: 22-22-0 s=1,c=1,t=17,pt=5,l=4,sg=0:4929
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;Attempting MQTT connection...

    Adding some debugging to the Mosquitto end shows this:

    Jan 24 19:54:42 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:54:42 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:54:58 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:54:58 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:54:58 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:55:13 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:55:13 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:55:13 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:55:28 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:55:28 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:55:28 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:55:43 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:55:43 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:55:43 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:55:58 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:55:58 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:55:58 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.
    Jan 24 19:56:13 RPi5 mosquitto[3016]: New connection from 192.168.1.22.
    Jan 24 19:56:13 RPi5 mosquitto[3016]: Invalid protocol "MQTT" in CONNECT from 192.168.1.22.
    Jan 24 19:56:13 RPi5 mosquitto[3016]: Socket read error on client (null), disconnecting.

    The code for the gateway (including all libraries) was downloaded yesterday from the development branch and the broker is the latest version from the Mosquitto wheezy repository.
    Seems to be something basic in the connect procedure.
    Any ideas Anyone??



  • Mosquitto uses an old version of the MQTT protocoll which is causing the error. So you need to tell the MQTT implementation to use the old version. I'm not sure if this is the intended way to fix it with MySensors, but for the used libary you have to go to drivers\pubsubclient\src\PubSubClient.h. Somewhere around line 20 there is a
    //#define MQTT_VERSION MQTT_VERSION_3_1
    #define MQTT_VERSION MQTT_VERSION_3_1_1
    By swapping it to:
    #define MQTT_VERSION MQTT_VERSION_3_1
    //#define MQTT_VERSION MQTT_VERSION_3_1_1
    you should be able to use your Mosquitto version.



  • Thanks for the answer. When tracing the error also I found these settings and have already tried this change but without any success. I may have forgotten to save the change or something else so will try it again.

    I know that mosquitto as well as the ESP8266 is working OK because I tested another sketch (https://gist.github.com/igrr/7f7e7973366fc01d6393) also based on the pubsub client and this works perfectly.

    Btw, in case of interest for anyone, when compiling for a DHCP IP-address there are compiling errors for missing gateway and subnet addresses. Not any problem but assume it should be corrected to some future release.

    Will post any progress, have reinstalled Raspbian based on Jessie- version because this was on the schedule anyhow.



  • Now the RPi based on a new install of Raspbian Jessie, OpenHab 1.8.0 and Mosquitto is up and running and the ESP8266 MQTT client does connect without any problems. I have not changed anything in the code but Mosquitto is now based on the RPi repository for Jessie and not the mosquito_wheezy one. That seems to have fixed it so those versions are likely different but I have not put any time into checking this.


Log in to reply
 

Suggested Topics

  • 2
  • 3
  • 2
  • 2
  • 2
  • 2
  • 2
  • 9

4
Online

11.4k
Users

11.1k
Topics

112.7k
Posts