Sonoff flashed with tasmota cannot connect to mqtt on hass.io

Hi All,

First time user and poster - so be patient

I installed hass.io on pi - all good
installed mqtt from add on store - default config
here is the log

starting version 3.2.2
1522372274: mosquitto version 1.4.12 (build date 2017-06-01 13:03:48+0000) starting
1522372274: Config loaded from /etc/mosquitto.conf.
1522372274: Opening ipv4 listen socket on port 1883.
1522372274: Opening ipv6 listen socket on port 1883.
1522372274: Warning: Mosquitto should not be run as root/administrator.
1522372275: New connection from 10.1.1.66 on port 1883.
1522372276: Socket error on client <unknown>, disconnecting.
1522372276: New connection from 10.1.1.66 on port 1883.
1522372276: New client connected from 10.1.1.66 as 7b6160a9-7a91-40a7-95a9-cdc13fd43bcb (c1, k60).
1522374075: Saving in-memory database to /data/mosquitto.db.

10.1.1.66 is my pi’s ip address ( made static on router)

in config file i have

mqtt:
#  broker: core-mosquitto
  broker: 10.1.1.66

I have tried both core-mosquitto and ip address - same results

should work right … ?

arduino code for flashing tasmota onto sonoff

 #define MQTT_HOST            "10.1.1.66"          // [MqttHost]
  #define MQTT_PORT            1883                 // [MqttPort] MQTT port (10123 on CloudMQTT)
  #define MQTT_USER            ""                   // [MqttUser] Optional user
  #define MQTT_PASS            ""                   // [MqttPassword] Optional password
#endif

and output from serial port after flash

00:00:00 Project sonoff Sonoff (Topic sonoff, Fallback DVES_A356EA, GroupTopic sonoffs) Version 5.12.0i-2_4_1
00:00:00 WIF: Connecting to AP1 SuperHouse in mode 11N as sonoff-5866...
02:08:06 WIF: Connected
02:08:06 DNS: Initialized
02:08:06 HTP: Web server active on sonoff-5866.local with IP address 10.1.2.212
02:08:06 MQT: Attempting connection...
02:08:11 MQT: Connect failed to 10.1.1.66:1883, rc -2. Retry in 10 sec
02:08:22 MQT: Attempting connection...
02:08:27 MQT: Connect failed to 10.1.1.66:1883, rc -2. Retry in 10 sec
02:08:38 MQT: Attempting connection...

and so it goes on …

side mention - i also CANNOT access the sonoff webserver on its ip address - i can see it attached to the network from the router … but thats another topic ,

seeking any advice please as Ive been at this for a week now and ready to pack it in …
cheers

Do you have your Sonoff defined in your config file? Here’s an example from my config file.

light:
- platform: mqtt
  name: "Name of Light"
  state_topic: "stat/mqtt_topic_for_light/POWER" #Define mqtt_topic_for_light under the configuration menu in the sonoff
  command_topic: "cmnd/mqtt_topic_for_light/POWER"
  availability_topic: "tele/mqtt_topic_for_light/LWT"
  retain: false
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"

I have the “standard” config as copied from drzzz youtube vid

looks like this

switch:
  - platform: mqtt
    name: "Study Light"
    command_topic: "cmnd/sonoff/power"
    state_topic: "stat/sonoff/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

but - just to try that as well

I copied your code - mine looks like this

light:
- platform: mqtt
  name: "Study Light"
  state_topic: "stat/sonoff/POWER" 
  command_topic: "cmnd/sonoff/POWER"
  availability_topic: "tele/sonoff/LWT"
  retain: false
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"

re-flashed the sonoff
unfortunately - no go

00:00:00 Project sonoff Sonoff (Topic sonoff, Fallback DVES_A356EA, GroupTopic sonoffs) Version 5.12.0i-2_4_1
00:00:00 WIF: Connecting to AP1 SuperHouse in mode 11N as sonoff-5866...
05:45:23 WIF: Connected
05:45:23 DNS: Initialized
05:45:23 HTP: Web server active on sonoff-5866.local with IP address 10.1.2.212
05:45:24 MQT: Attempting connection...
05:45:29 MQT: Connect failed to 10.1.1.66:1883, rc -2. Retry in 10 sec
05:45:40 MQT: Attempting connection...
05:45:45 MQT: Connect failed to 10.1.1.66:1883, rc -2. Retry in 10 sec

Not an expert in network/IP stuff, but your Pi (10.1.1.66) and Sonoff (10.1.2.212) are not on the same subnet, can your router(s) handle that? Especially, you mentioned you can’t access sonoff webserver on 10.1.2.212, if it’s me, I would trouble-shooting that first.

mmm possible - i have no idea too … these ip address’s were assigned automagically ?
I only dedicated the pi’s address as best practice … where the sonoff is getting the address from - i have no idea
but thanks - something to look into …

i have 6 sonoff flashed with tasmota have not miss a beat
got 2 more on way am going to do hole house

running hass.io

in my config file i have

mqtt:
  broker: localhost
  #discovery: true
  #discovery_prefix: homeassistant

my Switches look like this

    entity_id: GarageLight
    name: "Garage Light"
    state_topic: "stat/SONOFF5/POWER"
    command_topic: "cmnd/SONOFF5/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: true

the router only set my has.io to the same ip address
hope this helps

Your pi/MQTT broker need to be on the same subnet as your sonoff

The IP address for the Sonoff was supplied by the DHCP server in your router. 10.1.2.222.
Your router is probably 10.1.2.1 and all the other dynamically assigned address will be in the 10.1.2.xxx address space.
You have assigned a 10.1.1.xxx address to the Pi. This is in in a different subnet for a home router and won’t be reachable. The default configuration for a home router is 256 addresses - the netmask will be 255.255.255.0

Check your other devices on your network, they should all have a 10.1.2.xxx address. Change the Pi address to one in the same space and all will work.
It’s a good idea to check the address range the router’s DHCP server will give out and chose one outside that range, or reserve the Pi’s address in the router.

from your responses - i think i know what "caused the issue …

when loading hass.io … i put in wifi that connect to primary wifi … its address is 10.1.1.1
i created a secondary wifi connection - it seems to connect through 10.1.2.1 and i connected the sonoff via this wifi setting - hence it got the 10.1.2.222 address …

all good and well … so what i have done is - remove the secondary wifi login
re image the pi - its still on the 10.1.1.1 network
and tried to flash the sonoff with just the primary wifi settings , but now the xxx thing wont connect
the wifi is available … i can log into it from laptop and phone , but sonoff is now giving me

00:00:00 CFG: Use defaults
00:00:00 Project sonoff1 Sonoff (Topic sonoff1, Fallback DVES_A356EA, GroupTopic sonoffs) Version 5.12.0i-2_4_1
00:00:00 WIF: Connecting to AP1 thisisnotthewifiyouarelookingfor in mode 11N as sonoff1-5866...
00:00:20 WIF: Connect failed with AP timeout
00:00:20 WIF: Connecting to AP2 thisisnotthewifiyouarelookingfor in mode 11N as sonoff1-5866...
00:00:40 WIF: Connect failed with AP timeout
00:00:40 WIF: WifiManager active for 3 minutes
00:00:41 HTP: Web server active on sonoff1-5866 with IP address 192.168.4.1

i also can not access the 192.168.4.1 address … sigh

In order to help you I need a bit more information.
What is the make and model of your router?
Where did you get the 10.1.1.1 address from?
What computer do you have ( windows, Mac or Linux )?

Have you tried typing http//:192.168.4.1 Into the address bar on your browser?

im getting there slowly …

I reset my router
re-imaged the pi
i have re-installed mqtt - its now running on 10.1.1.1.178 and mqqt broker points to this ip as well

i have reflashed sonoff
its still not connecting directly to the wifi ( the one the pi is running on … )

00:00:00 Project sonoff1 Sonoff (Topic sonoff1, Fallback DVES_A356EA, GroupTopic sonoffs) Version 5.12.0i-2_4_1
00:00:00 WIF: Connecting to AP2 thisisnotthewifiyouarelookingfor in mode 11N as sonoff1-5866...
00:00:20 WIF: Connect failed with AP timeout
00:00:20 WIF: Connecting to AP1 thisisnotthewifiyouarelookingfor in mode 11N as sonoff1-5866...
00:00:40 WIF: Connect failed with AP timeout
00:00:40 WIF: WifiManager active for 3 minutes
00:00:41 HTP: Web server active on sonoff1-5866 with IP address 192.168.4.1
00:02:00 RSL: tele/sonoff1/UPTIME = {"Time":"1970-01-01T00:02:00","Uptime":"0T00:02:00"}
00:05:01 RSL: tele/sonoff1/STATE = {"Time":"1970-01-01T00:05:01","Uptime":"0T00:05:00","Vcc":4.466,"POWER":"OFF","Wifi":{"AP":1,"SSId":"thisisnotthewifiyouarelookingfor","RSSI":100,"APMac":"FF:FF:FF:FF:FF:FF"}}
00:06:20 WIF: Hostname %s-%04d, SSId1 thisisnotthewifiyouarelookingfor, Password1 xxxxxxxx, SSId2 thisisnotthewifiyouarelookingfor, Password2 xxxxxxxxx
00:06:21 APP: Restarting 

but - for the first time i can see the device on my network when it starts the webserver
i connect to device
then i can connect to ip 194.168.4.1
this is what i get

i have to connect to device first before i see the above , ie - i cant see it if i type 192.168.4.1 on my nornal wifi session

to answer questions
I have standard iinet nbn router ( australia)
Product Vendor - Technicolor
Product Name - MediaAccess TGiiNet-1

the 10.1.1.1 comes from

running a windows laptop

thanks all for the help so far - im getting there slowly … :slight_smile:

ip for pi and mqtt broker should read " 10.1.1.178 … thanks

Lets see what’s happening on your network.

in the windows search bar type

cmd

in the command prompt window that opens type

ipconfig /all

if you are connected to the router by wifi look for

Wireless LAN adapter WiFi:

in the text and copy the text under that heading to post here.

If you are connected by Ethernet cable, look for:

Ethernet adapter Ethernet:

and do the same.

To copy text from the command prompt window, highlight it and press enter. Paste with ctrl-v as normal.

I’m assuming you did add your wifi SSID and Password to the tasmota firmware before flashing it? Your post suggests you didn’t, and the Sonoff is defaulting to a preset IP address.

If that’s the case I can talk you through adding a suitable IP address to you laptop to allow you to connect to the Tasmota firmware and configure it.

What part of OZ are you in?

#define WIFI_IP_ADDRESS        "0.0.0.0"           // [IpAddress1] Set to 0.0.0.0 for using DHCP or IP address
#define WIFI_GATEWAY           ""                  // [IpAddress2] If not using DHCP set Gateway IP address
#define WIFI_SUBNETMASK        ""                  // [IpAddress3] If not using DHCP set Network mask
#define WIFI_DNS               ""                  // [IpAddress4] If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY)
// #define WIFI_IP_ADDRESS        "10.1.1.81"           // [IpAddress1] Set to 0.0.0.0 for using DHCP or IP address
// #define WIFI_GATEWAY           "10.1.1.1"          // [IpAddress2] If not using DHCP set Gateway IP address
// #define WIFI_SUBNETMASK        "255.255.255.0"     // [IpAddress3] If not using DHCP set Network mask
// #define WIFI_DNS               "10.1.1.1"          // [IpAddress4] If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY)

#define STA_SSID1              "thisisnotthewifiyouarelookingfor"       // [Ssid1] Wifi SSID
#define STA_PASS1              "xxxxx"                             // [Password1] Wifi password
#define STA_SSID2              "thisisnotthewifiyouarelookingfor"       // [Ssid2] Optional alternate AP Wifi SSID
#define STA_PASS2              "xxxxx"                             // [Password2] Optional alternate AP Wifi password
#define WIFI_CONFIG_TOOL       WIFI_MANAGER                             // [WifiConfig] Default tool if wifi fails to connect
                                                                        //   (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT)

I have tried multiple variants of the above … my wifi ip address is 10.1.1.81

what i have just done is enable the second wifi agan
reflashed with that wifi logon
and sure enough … it connects no problem
but i still cant get the main wifi to connect

I am in the ACT …

I’m a bit confused, reading back through your posts

i also can not access the 192.168.4.1 address … sigh

later you wrote

i connect to device
then i can connect to ip 194.168.4.1
this is what i get

and then the image.

Assuming you can connect to IP 194.168.4.1 with a web browser, you need to edit the AP1 SSId to make it YOUR wifi SSId and the AP1 password to be YOUR wifi password and then reboot the Sonoff. It will then connect to your wifi and obtain an address from the router’s DHCP server.

If you can’t connect to the Sonoff IP you will need to either add an extra IP address in the correct subnet to your browser to do the preceding step or recompile and re-flash the Sonoff device after changing the default setting to your wifi settings.
change these

#define STA_SSID1              "thisisnotthewifiyouarelookingfor"       // [Ssid1] Wifi SSID
#define STA_PASS1              "xxxxx"   

after rebuilding everything - i could and still can connect to 192.168.4.1
the wifi i need to connect to is the 'thisisnot… ’ but it isnt connecting
i see the sonoff screen as shown - with ssid as i put it in the tasmota code - and password
I have tried to retype the ssid and password in 192.168.4.1 - bit it still doesnt connect
i know the password is correct …

so to answer

Assuming you can connect to IP 194.168.4.1 with a web browser, you need to edit the AP1 SSId to make it YOUR wifi SSId and the AP1 password to be YOUR wifi password and then reboot the Sonoff. It will then connect to your wifi and obtain an address from the router’s DHCP server.

it doesnt connect … ?? i have laptop - phone - everything wifi on this network but sonoff … nooooooo

If you can’t connect to the Sonoff IP you will need to either add an extra IP address in the correct subnet to your browser to do the preceding step or recompile and re-flash the Sonoff device after changing the default setting to your wifi settings.

what must i change to … the ssid is correct and password - although not xxxxx - is correct

how do i add the extra ip please ?
cheers for your help so far !!

Message me a phone number and I’ll give you a call. It will be easier that way.

success !! for some reason - it doesnt like my wifi name
thisisnotthewifiyouarelookingfor - 32 chars ?
I hard reset router and changed to a shorter name and all works perfectly
thanks all for your help !!