Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. esp8266 gateway doesn't connect to mqtt broker

esp8266 gateway doesn't connect to mqtt broker

Scheduled Pinned Locked Moved Troubleshooting
8 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tsunami
    wrote on last edited by
    #1

    Hi, I'm using ESP8266 mqtt client gateway to connect to my controller and I use cloud mqtt service. controller has connected to the broker but esp8266 doesn't connect. even it doesn't connect to the wifi and it was a access point and I've followed a topic to add a code for turn off access point. this is my code for gateway:

    #define MY_DEBUG
    
    // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
    #define MY_BAUD_RATE 9600
    
    // Enables and select radio type (if attached)
    #define MY_RADIO_NRF24
    
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires username/password
    #define MY_MQTT_USER "***********"
    #define MY_MQTT_PASSWORD "**************"
    
    // Set WIFI SSID and password
    #define MY_ESP8266_SSID "*****************"
    #define MY_ESP8266_PASSWORD "******************"
    
    // Set the hostname for the WiFi Client. This is the hostname
    // it will pass to the DHCP server if not static.
    // #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,178,87
    
    // If using static ip you can define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    
    //MQTT broker if using URL instead of ip address.
    #define MY_CONTROLLER_URL_ADDRESS "m21.cloudmqtt.com"
    
    // The MQTT broker port to to open
    #define MY_PORT 11262
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    void setup()
    {
        // Setup locally attached sensors
    }
    
    void presentation()
    {
        // Present locally attached sensors here
    }
    
    void loop()
    {
        // Send locally attached sensors data here
    }```
    
    

    and I get this in serial:

    scandone
    state: 0 -> 2 (b0)
    state: 2 -> 3 (0)
    state: 3 -> 5 (10)
    add 0
    aid 4
    cnt 
    271 TSM:FAIL:DIS
    289 TSF:TDI:TSL
    
    connected with Shatel, channel 1
    dhcp client start...
    ip:192.168.1.6,mask:255.255.255.0,gw:192.168.1.1
    pm open,type:2 0
    10306 TSM:FAIL:RE-INIT
    10330 TSM:INIT
    10351 !TSM:INIT:TSP FAIL
    10377 TSM:FAIL:CNT=2
    10399 TSM:FAIL:DIS
    10419 TSF:TDI:TSL
    

    anyone knows how to fix it?

    mfalkviddM 1 Reply Last reply
    0
    • T tsunami

      Hi, I'm using ESP8266 mqtt client gateway to connect to my controller and I use cloud mqtt service. controller has connected to the broker but esp8266 doesn't connect. even it doesn't connect to the wifi and it was a access point and I've followed a topic to add a code for turn off access point. this is my code for gateway:

      #define MY_DEBUG
      
      // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
      #define MY_BAUD_RATE 9600
      
      // Enables and select radio type (if attached)
      #define MY_RADIO_NRF24
      
      
      #define MY_GATEWAY_MQTT_CLIENT
      #define MY_GATEWAY_ESP8266
      
      // Set this node's subscribe and publish topic prefix
      #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
      #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
      
      // Set MQTT client id
      #define MY_MQTT_CLIENT_ID "mysensors-1"
      
      // Enable these if your MQTT broker requires username/password
      #define MY_MQTT_USER "***********"
      #define MY_MQTT_PASSWORD "**************"
      
      // Set WIFI SSID and password
      #define MY_ESP8266_SSID "*****************"
      #define MY_ESP8266_PASSWORD "******************"
      
      // Set the hostname for the WiFi Client. This is the hostname
      // it will pass to the DHCP server if not static.
      // #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
      
      // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
      #define MY_IP_ADDRESS 192,168,178,87
      
      // If using static ip you can define Gateway and Subnet address as well
      #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
      #define MY_IP_SUBNET_ADDRESS 255,255,255,0
      
      
      //MQTT broker if using URL instead of ip address.
      #define MY_CONTROLLER_URL_ADDRESS "m21.cloudmqtt.com"
      
      // The MQTT broker port to to open
      #define MY_PORT 11262
      
      #include <ESP8266WiFi.h>
      #include <MySensors.h>
      
      void setup()
      {
          // Setup locally attached sensors
      }
      
      void presentation()
      {
          // Present locally attached sensors here
      }
      
      void loop()
      {
          // Send locally attached sensors data here
      }```
      
      

      and I get this in serial:

      scandone
      state: 0 -> 2 (b0)
      state: 2 -> 3 (0)
      state: 3 -> 5 (10)
      add 0
      aid 4
      cnt 
      271 TSM:FAIL:DIS
      289 TSF:TDI:TSL
      
      connected with Shatel, channel 1
      dhcp client start...
      ip:192.168.1.6,mask:255.255.255.0,gw:192.168.1.1
      pm open,type:2 0
      10306 TSM:FAIL:RE-INIT
      10330 TSM:INIT
      10351 !TSM:INIT:TSP FAIL
      10377 TSM:FAIL:CNT=2
      10399 TSM:FAIL:DIS
      10419 TSF:TDI:TSL
      

      anyone knows how to fix it?

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @tsunami see if removing

      #define MY_PORT 11262
      helps. I think this define is only meant to be used when not using MY_CONTROLLER_URL_ADDRESS (but I am not entirely sure).

      If that doesn't help, take a look at https://github.com/mysensors/MySensors/issues/926
      It seems like the ESP8266 gateway will be unable to use DNS when using static IP configuration. In my experimental branch I have added DNS support, but it is not reliable and needs more work. You could try to use an IP address instead of m21.cloudmqtt.com - not sure if it helps but it could be worth trying.

      T 2 Replies Last reply
      0
      • mfalkviddM mfalkvidd

        @tsunami see if removing

        #define MY_PORT 11262
        helps. I think this define is only meant to be used when not using MY_CONTROLLER_URL_ADDRESS (but I am not entirely sure).

        If that doesn't help, take a look at https://github.com/mysensors/MySensors/issues/926
        It seems like the ESP8266 gateway will be unable to use DNS when using static IP configuration. In my experimental branch I have added DNS support, but it is not reliable and needs more work. You could try to use an IP address instead of m21.cloudmqtt.com - not sure if it helps but it could be worth trying.

        T Offline
        T Offline
        tsunami
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mfalkviddM mfalkvidd

          @tsunami see if removing

          #define MY_PORT 11262
          helps. I think this define is only meant to be used when not using MY_CONTROLLER_URL_ADDRESS (but I am not entirely sure).

          If that doesn't help, take a look at https://github.com/mysensors/MySensors/issues/926
          It seems like the ESP8266 gateway will be unable to use DNS when using static IP configuration. In my experimental branch I have added DNS support, but it is not reliable and needs more work. You could try to use an IP address instead of m21.cloudmqtt.com - not sure if it helps but it could be worth trying.

          T Offline
          T Offline
          tsunami
          wrote on last edited by tsunami
          #4

          @mfalkvidd said in esp8266 gateway doesn't connect to mqtt broker:

          @tsunami see if removing

          #define MY_PORT 11262
          helps. I think this define is only meant to be used when not using MY_CONTROLLER_URL_ADDRESS (but I am not entirely sure).

          If that doesn't help, take a look at https://github.com/mysensors/MySensors/issues/926
          It seems like the ESP8266 gateway will be unable to use DNS when using static IP configuration. In my experimental branch I have added DNS support, but it is not reliable and needs more work. You could try to use an IP address instead of m21.cloudmqtt.com - not sure if it helps but it could be worth trying.

          thanks alot everything works good now and gatewat has connected to the mqtt broker. but i can't connect it to the domiticz. domoticz topics are: domoticz/in/mymqtt
          but for gateway is different and i can't change for domoticz.

          1 Reply Last reply
          0
          • mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by
            #5

            https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful

            T 1 Reply Last reply
            0
            • mfalkviddM mfalkvidd

              https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful

              T Offline
              T Offline
              tsunami
              wrote on last edited by
              #6

              @mfalkvidd said in esp8266 gateway doesn't connect to mqtt broker:

              https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful

              thank you I've done it and works great. but I found it if node is offline and I put switch on or off in controller it works but when node get connect to the controller it doesn't update switch state. how to fix it?

              mfalkviddM 1 Reply Last reply
              0
              • T tsunami

                @mfalkvidd said in esp8266 gateway doesn't connect to mqtt broker:

                https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful

                thank you I've done it and works great. but I found it if node is offline and I put switch on or off in controller it works but when node get connect to the controller it doesn't update switch state. how to fix it?

                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #7

                @tsunami program the sketch to fetch status at boot. See the first example at https://www.mysensors.org/build/dimmer for how it can be done.

                T 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  @tsunami program the sketch to fetch status at boot. See the first example at https://www.mysensors.org/build/dimmer for how it can be done.

                  T Offline
                  T Offline
                  tsunami
                  wrote on last edited by tsunami
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  28

                  Online

                  11.7k

                  Users

                  11.2k

                  Topics

                  113.1k

                  Posts


                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • MySensors
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular