Tasmota question: Can I query the IP over MQTT?

I have a Sonoff Basic inside a wall box that is working in Home Assistant as an MQTT switch.
However, it needs some config adjustments, easily done through the console screen. But, I just can’t find the IP of the device. It doesn’t show up in an IP Scan, but I can control it from Home Assistant, so it does have an IP address. (Yes, I did try every IP address that IP Scan identifies as an Expressif device.)

Is there a way to get the IP over MQTT?
My alternative is to open the box, unwire the Sonoff and connect the FTDI adapter, but I would rather do it the easy way.

If you are using mosquitto, and know the device id, you can look in the mosquitto log - that normally gives the ip of connecting devices.

Edit:
If you just power on and off the sonoff, it should log the new connection, so you don’t need to know its device id.

Thanks, I am using Mosquitto on a separate Raspberry Pi. Where would I find the log file? What filename am I looking for?

On raspbian it is at

/var/log/mosquitto/mosquitto.log

You need to use sudo to read it, so

$ sudo tail -f  /var/log/mosquitto/mosquitto.log
1544096908: New client connected from 192.168.0.25 as mysensors-1 (c1, k15).

Thanks, but I am not seeing any IP’s anywhere in the log.

pi@Marvin:/var/log/mosquitto $ sudo tail -f  /var/log/mosquitto/mosquitto.log
1544041700: Client DVES_693697 already connected, closing old connection.
1544041702: Client DVES_66AD29 already connected, closing old connection.
1544041703: Client studiolight already connected, closing old connection.
1544041704: Client DVES_0680D2 already connected, closing old connection.
1544042509: Client DVES_30DE5E already connected, closing old connection.
1544042527: Client DVES_30DE5E already connected, closing old connection.
1544042568: Client DVES_30DE5E already connected, closing old connection.
1544042600: Client DVES_30DE5E already connected, closing old connection.
1544043344: Client temperature01temperature already connected, closing old connection.
1544093048: Client ds18b20x2temperature already connected, closing old connection.

Those are all for re-connections - you shouldn’t be getting so many, but that is another problem.

If you disconnect the mysterious sonoff and wait for a disconnected message before re-connecting, you should see the new client connection.

Alternatively, try grepping the log file

$ sudo grep "New client"  /var/log/mosquitto/mosquitto.log
1543737177: New client connected from 192.168.0.17 as f942fc74-baa3-42d2-8b24-54c18b0c6df7 (c1, k60).
1543745431: New client connected from 192.168.0.9 as 4f530e50-4e21-401f-9f83-6c04cc6e090f (c1, k60).

The log file is pretty short, maybe 100 lines, so it was easy to scan it with cat. No “New Client” connections there. There are a few older log files in .gz format, but I’ve never opened a .gz file in Linux.

I could switch off the circuit breaker to disconnect the device- but that’s in the basement. How long should I wait to see the disconnect in the log file?

You can use zgrep for the .gz files

$ sudo zgrep -i "connected"  /var/log/mosquitto/mosquitto.log.1.gz
1542446407: New client connected from 192.168.0.9 as db8de907-cb85-437c-9993-e54366c97573 (c1, k60).
1542446408: New client connected from 192.168.0.9 as 6ddc1dca-82f7-43b0-94b2-c900af6cabe1 (c1, k60).

It should take about 30s for the client to disconnect - assuming you haven’t changed the default config. But I would hold off using the circuit breaker - I didn’t realize how embedded this was - you should be able to determine what you want from the log files - assuming you know the client id?

I did not know about zgrep, I will look through the older log files.
grep has been very handy, but looking through the older log files for “192.168” didn’t show any new connections.

I am beginning to think it will be easier to just connect the FTDI to the Sonoff again. I am not finding anything in the Mosquitto log files that helps.

Many thanks for your help. All is not lost, since you pointed me to two things I didn’t know before- where are the Mosquitto log files, and zgrep. I’ve added both notes to my Tasmota tips file. (Actually a personal wiki that I use like a lab notebook).

Thanks again,
Steve

You might try restarting your broker - that would cause new connections and would be less drastic that hitting the circuit breaker :grinning:

Good thought- everyone will have to reconnect then…

But, that doesn’t explain why it doesn’t show up on an IP scan.

It should also show up in your router’s dhcp client table.

How many MQTT clients do you have? You can get a list of open TCP connections, which will include the source IP, with the netstat command on your MQTT server. On my machine I can do this:

peter@sara:~$ netstat -natu | grep 1883
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:50868         127.0.0.1:1883          ESTABLISHED
tcp        0      0 10.17.17.118:1883       10.17.17.112:40277      ESTABLISHED
tcp        0      0 127.0.0.1:50119         127.0.0.1:1883          ESTABLISHED
tcp        0      0 127.0.0.1:1883          127.0.0.1:50868         ESTABLISHED
tcp        0      0 10.17.17.118:1883       10.17.17.112:46617      ESTABLISHED
tcp        0      0 127.0.0.1:1883          127.0.0.1:50119         ESTABLISHED
tcp6       0      0 :::1883                 :::*                    LISTEN

I’m only interested in ESTABLISHED connections, and 127.0.0.1 is the localhost address so I can ignore those too. That leaves two connections, with a source address of 10.17.17.112 and a destination of 10.17.17.118 port 1883. That tells me that the only MQTT client I have right now is on 10.17.17.112. In my case, that’s the raspberry pi running lighting in my kitchen.

Alternatively, Tasmota devices have a web interface, right? Rather than just scanning for espressif devices, have you scanned for everything on your local network that has port 80 open?

Have you tried finding it with TasmoAdmin? that should find it

Try the STATUS commands over MQTT to find the IP address:

Good idea, Codec303: I tried that first, but I never got a response (subscribed to stat/mbrlights/#)
Thanks

Thanks, Bluey. I didn’t know this tool existed!

What topic and payload did you send?

try sending

payload: 0
topic: cmnd/mbrlights/STATUS

If that doesn’t work, try 5 as the payload, same topic.

Payload of 5 worked. Exactly what I needed.
Thanks

1 Like