esp8266 gateway doesn't connect to mqtt broker
-
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?
-
@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.
-
This post is deleted!
-
@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.
-
https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful
-
@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?
-
@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.
-
This post is deleted!