ETS-PoliTO/esp32-sniffer

ESP_ERR_WIFI_MODE reboot loop

dmqgit opened this issue · 7 comments

Hi,

thanks for your code. Looks promising :)

Unfortunately I face a problem:

I (3271) ETS: [WI-FI] Connected
I (3361) ETS: [SPIFFS] Partition size: total: 896321, used: 502
I (3361) ETS: Connecting to WiFi and getting time over NTP.
I (3371) ETS: Waiting for system time to be set... (1/15)
I (5371) ETS: TIME INFO: The Greenwich date/time is: Fri Jan 18 19:55:20 2019
I (5381) ETS: File /spiffs/probreq.log initialized
I (5381) ETS: File /spiffs/probreq2.log initialized
I (5381) ETS: [!] Starting sniffing task...
I (5381) ETS: [!] Starting Wi-Fi task...
I (5381) ETS: [SNIFFER] Sniffer task created
I (5391) ETS: [SNIFFER] Starting sniffing mode...
I (5401) ETS: [WIFI] Wi-Fi task created
I (5401) ETS: [MQTT] Connecting to mqtt://X.X.X:X:1883
I (5411) ETS: [SNIFFER] Started. Sniffing on channel 11
I (5411) ETS: [WI-FI] Disconnected
SP_ERROR_CHECK failed: esp_err_t 0x3005 (ESP_ERR_WIFI_MODE) at 0x4008bf74
0x4008bf74: _esp_error_check_failed at /home/x/esp/esp-idf/components/esp32/panic.c:712

Does anyone has an idea?

Thanks in advance

J4NN0 commented

Hi,

Did you change something on the code? I tested It right now and I did not notice any kind of this error. It seems like you have modified the Wi-Fi configuration.

In the startup the Wi-Fi connection is successful but then, when the SNIFFER thread starts, it raises up the error. Moreover, the error is raised up by the ESP_ERROR_CHECK(). So, I suggest you to try to remove in the Wi-Fi handler the ESP_ERROR CHECK function in the SYSTEM_EVENT_STA_DISCONNECTED case. But it's not the good way, but let's try it.

Make sure to configure the Wi-Fi in WIFI_MODE_APSTA. If not when you start the sniffer mode the Wi-Fi will disconnect from the network.

Hi,

thanks for your answer + help.

I did not change anything in the code. I changed the Wifi configuration (standard changes) and mqtt configuration (topic and connection type: tcp/1883).

I commented out in "main/main.c"

// ESP_ERROR_CHECK(esp_wifi_connect());

After that:

make clean && make all && make flash

In menuconfig I selected verbose=1.

Here is the output of the make monitor session:

I (400) ETS: Waiting for connection to the WiFi network...
I (400) ETS: [WI-FI] Connecting to SSID
I (3270) event: sta ip: NNN.NN.NN.146, mask: 255.255.255.0, gw: NN.NN.NN.254
I (3270) ETS: [WI-FI] Connected
I (3270) ETS: MAC Address: 80:7d:3a:NN:NN:c0
I (3270) ETS: IP Address:  NN.NN.NN.146
I (3280) ETS: Subnet mask: 255.255.255.0
I (3280) ETS: Gateway:     NN.NN.NN.254
I (3290) ETS: Free memory: 234720 bytes
I (3290) ETS: IDF version: v3.3-beta1-223-ga62cbfe-dirty
[---] Malnati please give us 9 points [---]
I (3390) ETS: [SPIFFS] Partition size: total: 896321, used: 502
I (3390) ETS: Connecting to WiFi and getting time over NTP.
I (3400) ETS: Waiting for system time to be set... (1/15)
I (5400) ETS: TIME INFO: The Greenwich date/time is: Mon Jan 21 18:53:04 2019
I (5400) ETS: File /spiffs/probreq.log initialized
I (5400) ETS: File /spiffs/probreq2.log initialized
I (5400) ETS: [!] Starting sniffing task...
I (5410) ETS: [!] Starting Wi-Fi task...
I (5410) ETS: [SNIFFER] Sniffer task created
I (5420) ETS: [WIFI] Wi-Fi task created
I (5420) ETS: [MQTT] Connecting to mqtt://NN.NN.NN.55:1883
I (5430) ETS: [SNIFFER] Starting sniffing mode...
I (5430) wifi: set country: cc=CN schan=1 nchan=13 policy=0

I (5440) wifi: state: run -> init (0)
I (5440) wifi: pm stop, total sleep time: 2182625 us / 3152319 us

I (5450) wifi: new:<6,0>, old:<6,0>, ap:<6,2>, sta:<6,0>, prof:6
I (5460) wifi: mode : null
I (5460) wifi: ic_enable_sniffer
I (5460) ETS: [SNIFFER] Started. Sniffing on channel 11
I (5460) ETS: [WI-FI] Disconnected
E (5460) MQTT_CLIENT: Error transport connect
I (5480) ETS: [MQTT] Disconnected
E (25480) MQTT_CLIENT: Error transport connect
I (25480) ETS: [MQTT] Disconnected
E (45480) MQTT_CLIENT: Error transport connect
I (45480) ETS: [MQTT] Disconnected
W (61430) ETS: [WI-FI] Impossible send data to mqtt://NN.NN.NN.55. ESP32 is not connected to the broker
W (65470) ETS: [SNIFFER] Initializing file...
I (65470) ETS: File /spiffs/probreq2.log initialized
E (65480) MQTT_CLIENT: Error transport connect
I (65480) ETS: [MQTT] Disconnected
E (85480) MQTT_CLIENT: Error transport connect
I (85480) ETS: [MQTT] Disconnected
E (105480) MQTT_CLIENT: Error transport connect
I (105480) ETS: [MQTT] Disconnected
W (121430) ETS: [WI-FI] Impossible send data to mqtt://NN.NN.NN.55. ESP32 is not connected to the broker
I (125460) event: station ip lost
W (125470) ETS: [SNIFFER] Initializing file...
E (125500) MQTT_CLIENT: Error transport connect
I (125500) ETS: [MQTT] Disconnected
I (125520) ETS: File /spiffs/probreq2.log initialized
E (140520) MQTT_CLIENT: Error transport connect
I (140520) ETS: [MQTT] Disconnected
E (160520) MQTT_CLIENT: Error transport connect
I (160520) ETS: [MQTT] Disconnected
E (180520) MQTT_CLIENT: Error transport connect
I (180520) ETS: [MQTT] Disconnected
W (181430) ETS: [WI-FI] Impossible send data to mqtt://NN.NN.NN.55. ESP32 is not connected to the broker
W (185520) ETS: [SNIFFER] Initializing file...
I (185520) ETS: File /spiffs/probreq2.log initialized

I further did an tcpdump on the AP with:

tcpdump -i INTERFACE -n 'ether host nn:nn:nn:nn:nn:nn'

After the WPA2PSK authentication I see DHCP Request + Reply + NTP request + reply cutted here. After that the initial MQTT:

20:00:51.021763 ARP, Request who-has N.N.N.N.146 tell N.N.N.146, length 28
20:00:51.187644 IP N.N.N.146.51183 > N.N.N.55.1883: Flags [S], seq 6509, win 5744, options [mss 1436], length 0
20:00:51.192293 IP N.N.N.55.1883 > N.N.N.146.51183: Flags [S.], seq 1213070038, ack 6510, win 29200, options [mss 1460], length 0
20:00:52.191798 IP N.N.N.55.1883 > N.N.N.146.51183: Flags [S.], seq 1213070038, ack 6510, win 29200, options [mss 1460], length 0
20:00:54.192715 IP N.N.N.55.1883 > N.N.N.146.51183: Flags [S.], seq 1213070038, ack 6510, win 29200, options [mss 1460], length 0

So here we can see, that the ESP32 sends an initial TCP-SYN packet. The MQTT-Server gives an TCP-SYN+ACK back. But this seems to never arrive at the ESP32. It probably correlates with the debug output event "I (125460) event: station ip lost".

Do you have a clue? Did you try it with another mqtt-software like mosquitto or just with the special mqtt-software per ws?

Which esp32 modules did you test. I have tried the following:

Wemos Lolin 32 with Espressif ESP32-WROOM-32 module
Wemos® TTGO MINI 32 V2.0

But I do not think that this makes a difference.

Thank you very much for your help + project.

dmq

J4NN0 commented

Yes, I tried also with mosquitto and it worked. Just change the configuration (over TCP or over WS).

I think the problem is in Wi-Fi configuration. I can't realize how this is possible:

I (5420) ETS: [WIFI] Wi-Fi task created
I (5420) ETS: [MQTT] Connecting to mqtt://NN.NN.NN.55:1883
I (5430) ETS: [SNIFFER] Starting sniffing mode...
I (5430) wifi: set country: cc=CN schan=1 nchan=13 policy=0
I (5440) wifi: state: run -> init (0)
I (5440) wifi: pm stop, total sleep time: 2182625 us / 3152319 us
I (5450) wifi: new:<6,0>, old:<6,0>, ap:<6,2>, sta:<6,0>, prof:6
I (5460) wifi: mode : null
I (5460) wifi: ic_enable_sniffer
I (5460) ETS: [SNIFFER] Started. Sniffing on channel 11
I (5460) ETS: [WI-FI] Disconnected

In the startup the ESP is able to connect itself to the Wi-Fi, but then when the sniffer thread is created it disconnect itself from the Wi-Fi. So, it's possible that the ESP is not able to create AP and STA at the same time, then when the ESP create the sniffer task and it ables the sniffer mode it crashes.

How can I see the module I'm using? I never check it

Hmm. Yes, I heard of such issues in the past.

Are you using the module from page 7 of your presentation?

https://j4nn0.github.io./doc/ets_presentation.pdf

This should be a nodemcu esp32 with a ESP-Wroom-32 (it is written on the metai plate). Maybe I should try such a module. I try to find one.

J4NN0 commented

Yes, it is.

If it can be useful for you, this is the link where I bought the ESP32. Maybe you can find additional information that could be useful for you.

Let me know.

So, now I tried four different modules with three different module-types:

esp32-wroom-32
esp32-wrover-32
esp32-kit

All have the same problem. Strange. Could it be a timing issue switching between the two threads?

I try to change WIFI_MODE_NULL to WIFI_MODE_APSTA in wifi_siniffer_init() and I have't reboot loop.