6

I have been chasing a problem with seemingly-random and infrequent disconnects due to "Socket error on client" between my ESP8266 client (PubSubClient 2.6.0) and my Mosquitto broker on Raspberry Pi (mosquitto 1.4.10).

I have been reviewing the various log files and debug statements to try and figure out what is going on. While following the log file (tail -f /var/log/mosquitto/mosquitto.log), I noticed that PINGREQ and PINGRESP record pairs are not populated at the same time, even though their timestamps are identical. PINGRESP does not show up until the next PINGREQ is received. Is this normal behaviour?

An example is provided in the screenshot below. The orange row showed up first. The blue rows were added together in the log file 15 seconds later, even though they do not have the same timestamp. In fact, the PINGRESP timestamp is identical (1516832931) to the PINGREQ above (in orange).

I would expect PINGRESP to follow almost immediately behind PINGREQ (i.e .the timestamps make sense). I just want to make sure that is actually happening given the several seconds lag I observe in tail. I think this is important because I assume the disconnects are from a keepalive violation, with my keepalive timeout at 15s.

enter image description here

8
  • 2
    What does wireshark say?
    – hardillb
    Jan 25, 2018 at 6:46
  • 4
    @hardillb - thanks, I'll need to look into this. I've used Wireshark on my PC before, but in this case I need to analyze traffic between a Raspberry Pi and an ESP8266. I guess this means I would need to install it on the Pi?
    – Roberto
    Jan 25, 2018 at 7:29
  • 1
    Or on somewhere on the same network
    – hardillb
    Jan 25, 2018 at 8:33
  • From reading Wireshark documentation, my understanding is that my Windows (Ethernet) PC cannot capture traffic involving the ESP8266 (Wi-Fi). So I installed Wireshark on a Windows laptop, but now I am having trouble getting its WLAN into "Monitor" mode. I gather enabling this mode is sometimes problematic in Windows. I was hoping to avoid adding Wireshark to the Pi (just seems like it would bloat the little device), but I may go that route now. Anyways, still working on it...
    – Roberto
    Jan 25, 2018 at 17:33
  • Use tshark on the pi, you can read the file in wireshark on windows afterwards
    – hardillb
    Jan 25, 2018 at 18:34

1 Answer 1

6

It seems the "lag" observation is just a side-effect of the logging process, and not a real delay in the data flow.

Following the suggestion of @hardillb, I installed tshark on the Raspberry Pi. By observing the request and response packets between the Pi (192.168.0.104) and the ESP8266 (192.168.0.117), I can see that they are within fractions of a second (i.e. there is no 15 second delay responding from the MQTT broker).

tshark capture

steps taken:

sudo apt-get install tshark
cd /home/pi
sudo nano espcapture.pcap
sudo chown root:root espcapture.pcap (because tshark runs as root)
sudo tshark -i wlan0 -w /home/pi/espcapture.pcap
<wait 2 min>
CTRL+C

I then transferred the resulting espcapture.pcap file to my PC, and opened it in Wireshark for analysis / filtering.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.