listening server

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: listening server

Postby kolban » Tue Mar 13, 2018 3:46 pm

When your target ESP32 is being an access point, maybe try connecting to it from an Android (assuming your phone is Android) TCP client such as this one:

https://play.google.com/store/apps/deta ... ools&hl=en

(or similar).

You should be able to connect your phone to the ESP32 access point network and then attempt a TCP connection. This will give us a new data point.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: listening server

Postby kolban » Tue Mar 13, 2018 3:48 pm

Another thought ... when your ESP32 is being an access point and you connect to it from your PC, paste your complete serial output log including the connection from the PC. Make sure that your ESP32 is configured at logging level "verbose".
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: listening server

Postby kbaud1 » Tue Mar 13, 2018 4:36 pm

Of course I am using android :roll: Downloaded the tcp tools (nice app) and it connected fine while esp was in client mode (softAP). error in server mode is "connection error:control port or ip address".

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: listening server

Postby kbaud1 » Tue Mar 13, 2018 4:51 pm

serial logs of connections (or attempts) with PC...

AP and beServer = 1 (softAP acting as listening server)

Code: Select all

$ make monitor
MONITOR
--- idf_monitor on com10 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4480
ho 0 tail 12 room 4
load:0x40078000,len:0
load:0x40078000,len:12988
entry 0x40078d14
I (217) cpu_start: Pro cpu up.
I  (217) cpu_start: Starting app cpu, entry point is 0x40080f34
0x40080f34: call_start_cpu1 at C:/msys32/home/Peter/esp/esp-idf/components/esp32/cpu_start.c:215

I (0) cpu_start: App cpu up.
I (220) heap_init: Initializing. RAM available for dynamic allocation:
D (227) heap_init: New heap initialised at 0x3ffae6e0
I (232) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
D (238) heap_init: New heap initialised at 0x3ffb8e70
I (243) heap_init: At 3FFB8E70 len 00027190 (156 KiB): DRAM
I (249) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (255) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
D (262) heap_init: New heap initialised at 0x400907ec
I (267) heap_init: At 400907EC len 0000F814 (62 KiB): IRAM
I (273) cpu_start: Pro cpu start user code
D (285) clk: RTC_SLOW_CLK calibration value: 3503142
V (71) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (71) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xE
D (76) intr_alloc: Connected src 46 to int 2 (cpu 0)
V (81) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (87) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xC0E
D (95) intr_alloc: Connected src 57 to int 3 (cpu 0)
V (100) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (106) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0x40E
D (115) intr_alloc: CConnected src 24 to int 9 (cpu 0)
I (120) cpu_start: Starting scheduler on PRO CPU.
V (0) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): checking args
V (0) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): Args okay. Resulting flags 0x40E
D (10) intr_alloc: Connected src 25 to int 2 (cpu 1)
I (10) cpu_start: Starting scheduler on APP CPU.
D (170) heap_init: New heap initialised at 0x3ffe0440
D (170) heap_init: New heap  initialised at 0x3ffe4350
V (180) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (180) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xE
D (180) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (200) nvs: nvs_flash_init_custom partition=nvs start=9 count=6
D (230) nvs: nvs_open_from_partition misc 1
D (230) nvs: nvs_get_str_or_blob log
I (230) wifi: wifi firmware version: 275023b
I (230) wifi: config NVS flash: enabled
I (230) wifi: config nano formating: disabled
I (240) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (240) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
D (250) nvs: nnvs_open_from_partition nvs.net80211 1
D (260) nvs: nvs_get opmode 1
D (260) nvs: nvs_get_str_or_blob sta.ssid
D (270) nvs: nvs_get_str_or_blob sta.mac
D (270) nvs: nvs_get sta.authmode 1
D (270) nvs: nvs_get_str_or_blob sta.pswd
D (280) nvs: nvs_get_str_or_blob sta.pmk
D (280) nvs: nvs_get sta.chan 1
D (290) nvs: nvs_get auto.conn 1
D (290) nvs: nvs_get bssid.set 1
D (290) nvs: nvs_get_str_or_blob sta.bssid
D (300) nvs: nvs_get sta.phym 1
D (300) nvs: nvs_get sta.phybw 1
D (300) nvs: nvs_get_str_or_blob sta.apsw
D (310) nvs: nvs_get_str_or_blob sta.apinfo
D (310) nvs: nvs_get sta.scan_method 1
D (310) nvs: nvs_get sta.sort_method 1
D (320) nvs: nvs_get sta.minrssi 1
D (320) nvs: nvs_get sta.minauth 1
D (330) nvs: nvs_get_str_or_blob ap.ssid
D (330) nvs: nvs_get_str_or_blob ap.mac
D (330) nvs: nvs_get_str_or_blob ap.passwd
D (340) nvs: nvs_get_str_or_blob ap.pmk
D (340) nvs: nvs_get ap.chan 1
D (340) nvs: nvs_get ap.authmode 11
D (350) nvs: nvs_get ap.hidden 1
D (350) nvs: nvs_get ap.max.conn 1
D (350) nvs: nvs_get bcn.interval 2
D (360) nvs: nvs_get ap.phym 1
D (360) nvs: nvs_get ap.phybw 1
D (360) nvs: nvs_get ap.sndchan 1
D (370) nvs: nvs_set_blob sta.mac 6
D (370) nvs: nvs_set_blob ap.mac 6
I (380) wifi: Init dynamic tx buffer num: 32
I (380) wifi: Init data frame dynamic rx buffer num: 32
I (380) wifi: Init management frame dynamic rx buffer num: 32
I (390) wifi: wifi driver task: 3ffc04bc, prio:23, stack:4096
I (390) wifi: Init static rx buffer num: 10
I (400) wifi: Init dynamic rx buffer num: 32
I (400) wifi: wifi power manager task: 0x3ffc50fc prio: 21 stack: 2560
I (410) >: Setting WiFi mode to Soft-AP
D (410) RTC_MODULE: Wi-Fi takes adc2 lock.
D (420) phy_init: loading PHY init data from application binary
D (420) nvs: nvs_open_from_partition phy 0
D (430) nvs: nvs_get cal_version 4
V (430) phy_init: phy_get_rf_cal_version: 366

D (440) nvs: nvs_get_str_or_blob cal_mac
D (440) nvs: nvs_get_str_or_blob cal_data
D (450) nvs: nvs_close 3
V (450) phy_init: register_chipv7_phy, init_data=0x3f410008, cal_data=0x3ffc5320, mode=0
I (480) phy: phy_version: 366.0, ba9923d, Oct 31 2017, 18:06:17, 0, 0
I (480) wifi: mode : softAP (30:ae:a4:0e:13:cd)
D (480) event: SYSTEM_EVENT_AP_START
V (480) event: enter default callback
D (480) tcpip_adapter: check: local, if=1 fn=0x40119b00
0x40119b00: tcpip_adapter_start_api at C:/msys32/home/Peter/esp/esp-idf/components/tcpip_adapter/tcpip_adapter_lwip.c:10
65


D (490) tcpip_adapter: dhcp server start:(ip: 192.168.4.1, mask: 255.255.255.0, gw: 192.168.4.1)
D (500) tcpip_adapter: call api in lwip: ret=0x0, give sem
D (500) tcpip_adapter: check: remote, if=1 fn=0x40119b00
0x40119b00: tcpip_adapter_start_api at C:/msys32/home/Peter/esp/esp-idf/components/tcpip_adapter/tcpip_adapter_lwip.c:10
65


V (510) event: exit default callback
I (510) >: Soft-AP started
I (4590) wifi: n:1 1, o:1 0, ap:1 1, sta:255 255, prof:1
I (4590) wifi: station: (redacted) join, AID=1, n, 40U
D (4590) event: SYSTEM_EVENT_AP_STACONNECTED, mac:(re-redacted), aid:1
I (4590) >: station connected to this soft-AP: ThePartyHouse
I (4600) >: Initializing server to listen for connections...
E (4610) >: socket: 4096 Success
E (4610) >: bind: 0 Success
E (4610) >: listen: 0 Success
I (4620) >: Server listening on port 7777...

AP = 1 and beServer = 0 (softAP acting as client)

Code: Select all

$ make monitor
MONITOR
--- idf_monitor on com10 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:4480
ho 0 tail 12 room 4
load:0x40078000,len:0
load:0x40078000,len:12988
entry 0x40078d14
I (217) cpu_start: Pro cpu up.
I (217) cpu_start: Starting app cpu, entry point is 0x40080f34
0x40080f34: call_start_cpu1 at C:/msys32/home/Peter/esp/esp-idf/components/esp32/cpu_start.c:215

I (0) cpu_start: App cpu up.
I (220) heap_init: Initializing. RAM available for dynamic allocation:
D (227) heap_init: New heap initialised at 0x3ffae6e0
I (232) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
D (238) heap_init: New heap initialised at 0x3ffb8e80
I (243) heap_init: At 3FFB8E80 len 00027180 (156 KiB): DRAM
I (249) heap_init: At 3FFEE0440 len 00003BC0 (14 KiB): D/IRAM
I (256) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
D (262) heap_init: New heap initialised at 0x400907ec
I (267) heap_init: At 400907EC len 0000F814 (62 KiB): IRAM
I (273) cpu_start: Pro cpu start user code
D (285) clk: RTC_SLOW_CLK calibration value: 3518310
V (71) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (71) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xE
D (76) intr_alloc: Connected src 46 to int 2 (cpu 0)
V (81) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (87) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xC0E
D (95) intr_alloc: Connected src 57 to int 3 (cpu 0)
V (101) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (107) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0x40E
D (115) intr_alloc: Connected src 24 to int 9 (cpu 0)
I (120) cpu_start: Starting scheduler on PRO CPU.
V (0) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): checking args
V (0) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): Args okay. Resulting flags 0x40E
D (10) intr_alloc: Connected src 25 to int 2 (cpu 1)
I (10) cpu_start: Starting scheduler on APP CPU.
D (170) heap_init: New heap initialised at 0x3ffe0440
D (170) heap_init: New heap initialised at 0x3ffe4350
V (180) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): checking args
V (180) intr_alloc: esp_intr_alloc_intrstatus (cpu 0): Args okay. Resulting flags 0xE
D (180) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (200) nvs: nvs_flash_init_custom partition=nvs start=9 count=6
D (230) nvs: nvs_open_from_partition misc 1
D (230) nvs: nvs_get_str_or_blob log
I (230) wifi: wifi firmware version: 275023b
I (230) wifi: config NVS flash: enabled
I (230) wifi: config nano formating: disabled
I (240) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (240) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
D (250) nvs: nvs_open_from_partition nvs.net80211 1
D (260) nvs: nvs_get opmode 1
D (260) nvs: nvs_get_str_or_blob sta.ssid
D (270) nvs: nvs_get_str_or_blob sta.mac
D (270) nvs: nvs_get sta.authmode 1
D (270) nvs: nvs_get_str_or_blob sta.pswd
D (280) nvs: nvs_get_str_or_blob sta.pmk
D (280) nvs: nvs_get sta.chan 1
D (290) nvs: nvs_get auto.conn 1
D (290) nvs: nvs_get bssid.set 1
D (290) nvs: nvs_get_str_or_blob sta.bssid
D (300) nvs: nvs_get sta.phym 1
D (300) nvs: nvs_get sta.phybw 1
D (300) nvs: nvs_get_str_or_blob sta.apsw
D (310) nvs: nvs_get_str_or_blob sta.apinfo
D (310) nvs: nvs_get sta.scan_method 1
D (310) nvs: nvs_get sta.sort_method 1
D (320) nvs: nvs_get sta.minrssi 1
D (320) nvs: nvs_get sta.minauth 1
D (330) nvs: nvs_get_str_or_blob ap.ssid
D (330) nvs: nvs_get_str_or_blob ap.mac
D (330) nvs: nvs_get_str_or_blob ap.passwd
D (340) nvs: nvs_get_str_or_blob ap.pmk
D (340) nvs: nvs_get ap.chan 1
D (340) nvs: nvs_get ap.authmode 1
D (350) nvs: nvs_get ap.hidden 1
D (350) nvs: nvs_get ap.max.conn 1
D (350) nvs: nvs_get bcn.interval 2
D (360) nvs: nvs_get ap.phym 1
D (360) nvs: nvs_get ap.phybw 1
D (360) nvs: nvs_get ap.sndchan 1
D (370) nvs: nvs_set_blob sta.mac 6
D (370) nvs: nvs_set_blob ap.mac 6
I (380) wifi: Init dynamic tx buffer num: 32
I (380) wifi: Init data frame dynamic rx buffer num: 32
I (380) wifi: Init management frame dynamic rx buffer num: 32
I (390) wifi: wifi driver task: 3ffc04cc, prio:23, stack:4096
I (390) wifi: Init  static rx buffer num: 10
I (400) wifi: Init dynamic rx buffer num: 32
I (400) wifi: wifi power manager task: 0x3ffc510c prio: 21 stack: 2560
I (410) >: Setting WiFi mode to Soft-AP
D (410) RTC_MODULE: Wi-Fi takes adc2 lock.
D (420) phy_init: loading PHY init data from application binary
D (420) nvs: nvs_open_from_partition phy 0
D (430) nvs: nvs_get cal_version 4
V (430) phy_init: phy_get_rf_cal_version: 366

D (440) nvs: nvs_get_str_or_blob cal_mac
D (440) nvs: nvs_get_str_or_blob cal_data
D (450) nvs: nvs_close 3
V (450) phy_init: register_chipv7_phy, init_data=0x3f40f848, cal_data=0x3ffc5330, mode=0
I (480) phy: phy_version: 366.0, ba9923d, Oct 31 2017, 18:06:17, 0, 0
I (480) wifi: mode : softAP (30:ae:a4:0e:13:cd)
D (480) event: SYSTEM_EVENT_AP_START
V (480) event: enter default callback
D (480) tcpip_adapter: check: local, if=1 fn=0x4011a224
0x4011a224: tcpip_adapter_start_api at C:/msys32/home/Peter/esp/esp-idf/components/tcpip_adapter/tcpip_adapter_lwip.c:10
65


D (490) tcpip_adapter: dhcp server start:(ip: 192.168.4.1, mask: 255.255.255.0, gw: 192.168.4.1)
D (500) tcpip_adapter: call api in lwip: ret=0x0, give sem
D (500) tcpip_adapter: check: remote, if=1 fn=0x4011a224
0x4011a224: tcpip_adapter_start_api at C:/msys32/home/Peter/esp/esp-idf/components/tcpip_adapter/tcpip_adapter_lwip.c:10
65


V (510) event: exit default callback
I (510) >: Soft-AP started
I (2840) wifi: n:1 1, o:1 0, ap:1 1, sta:255 255, prof:1
I (2840) wifi: station: (redacted) join, AID=1, n, 40U
D (2840) event: SYSTEM_EVENT_AP_STACONNECTED, mac:(redacted), aid:1
I (2850) >: station connected to this soft-AP: ThePartyHouse
I (2860) >: DNS lookup succeeded. IP=192.168.4.2
I (2860) >: ... allocated socket

I (5420) >: ... connected
I (5420) >: ... socket send success
message from server1I (5430) >: ... done reading from socket. Last read return=20 errno=0

I (5440) >: ... socket send success
message from server1I (5440) >: ... done reading from socket. Last read return=20 errno=0

I (5450) >: ... socket send success
message from server1I (7340) >: ... done reading from socket. Last read  return=20 errno=0

I (7340) >: ... socket send success
message from server1I (7340) >: ... done reading from socket. Last read return=20 errno=0

....

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: listening server

Postby kbaud1 » Sat Mar 17, 2018 11:34 pm

I have tried other code examples with the same result. also updated the IDF to latest. installed wireshark. here's what happens once the client and listener find each other:

688 103.012844 192.168.0.34 192.168.0.52 TCP 60 7777 → 52319 [RST, ACK] Seq=1 Ack=1 Win=5744 Len=0
689 103.514148 192.168.0.52 192.168.0.34 TCP 66 [TCP Retransmission] 52319 → 7777 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1

Not sure what is causing TCP retransmissions?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: listening server

Postby kolban » Sun Mar 18, 2018 3:44 am

I read through your code and "think" I have found the answer. In your code you define:

Code: Select all

#define PORT "7777"


// Bind our server socket to a port.
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(PORT);
int rc  = bind(sock, (struct sockaddr *)&serverAddress, sizeof(serverAddress));
The htons() function expects as input a C "short" data type (16 bits) and converts it to a network endian version. However, what is being passed to it is the address of a string (a pointer to "7777").

Trying changing your code from

Code: Select all

#define PORT "7777"
to

Code: Select all

#define PORT 7777
and if this works ... send me a virtual coffee.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: listening server

Postby kbaud1 » Sun Mar 18, 2018 11:16 pm

That did it! Thank you Kolban!

Not familiar with "virtual coffee". How about paypal instead?

Peter

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: listening server

Postby kolban » Mon Mar 19, 2018 2:51 am

Peter,
I'm delighted that worked. The "virtual coffee" was my attempt at humor (sorry). Assisting folks with ESP32 is all part of the service. Ive been the beneficiary as many times as not. If you get the chance, pay it forward with what ever you learn in what ever area you can be of help.

Neil
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: listening server

Postby WiFive » Mon Mar 19, 2018 4:25 am

Or just buy his book

kbaud1
Posts: 71
Joined: Wed Jan 17, 2018 11:55 pm

Re: listening server

Postby kbaud1 » Mon Mar 19, 2018 2:10 pm

Already bought the book (see first post in this thread). It is helpful.

Who is online

Users browsing this forum: Bing [Bot] and 87 guests