Page 1 of 2
Unable to receive TCPIP-packets with wifi callback function
Posted: Thu Jan 05, 2017 7:47 pm
by Wamor45
Hello,
I wrote a small program which once connected to wifi should receive TCPIP packages.
My program is listed below:
Code: Select all
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_get_mac(WIFI_IF_STA, mac) );
printf("MAC address: " MACSTR "\r\n", MAC2STR(mac));
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
wifi_config_t sta_config = {
.sta = {
.ssid = "my_wifi",
.password = "123456",
.bssid_set = false
}
};
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
ESP_ERROR_CHECK( esp_wifi_internal_reg_rxcb(WIFI_IF_STA, &my_wifi_rxcb) );
ESP_ERROR_CHECK( esp_wifi_start() );
ESP_ERROR_CHECK( esp_wifi_connect() );
When I send some TCP or UDP-packages with another computer on the same network I don't receive any packages in the my_wifi_rxcb call back function. Am I missing some additional initialization or what could be wrong here?
Thank you for your responses,
Wamor
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Thu Jan 05, 2017 10:56 pm
by ESP_Angus
Hi Wamor,
esp_wifi_internal_reg_rxcb is an internal function, so it's used to implement the IP stack (LWIP) that runs on top of the WiFi libraries. It may not be what you want in order to exchange TCP/IP packets with another host on the network.
Can you explain a bit more about what you're trying to do? If you take a look at some of the examples in esp-idf that use TCP/IP (like the 'http_request' example, for example) you'll be able to see the recommended way to work with TCP/IP on ESP32.
Angus
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Jan 06, 2017 3:26 am
by kolban
Howdy @Wamor,
To follow up on what Mr Angus said ... in case it is useful to you ... here is a snippet I use for a TCP/IP TCP socket client:
https://github.com/nkolban/esp32-snippe ... etClient.c
and one for a TCP/IP TCP socket server:
https://github.com/nkolban/esp32-snippe ... t_server.c
The trick (for me) is to invest time studying generic books on the TCP/IP sockets APIs and there are some fine books and resources available on those subjects. ESP32 sockets API seems to be a high fidelity implementation.
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Jan 06, 2017 8:54 pm
by Wamor45
Hello Angus,
What I basically want to do is receiving UDP-packages from a remote computer and send them out as analog values through the DAC of the ESP32. I hope this make sense to you.
Regards,
Wamor
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Jan 06, 2017 8:59 pm
by Wamor45
Hello kolban,
Thank you for your response.
I will get me some good books about TCPIP and sockets.
Regards,
Wamor
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Aug 18, 2017 9:59 am
by zjuliwang
Wamor45 wrote:Hello Angus,
What I basically want to do is receiving UDP-packages from a remote computer and send them out as analog values through the DAC of the ESP32. I hope this make sense to you.
Regards,
Wamor
Hello Angus,nkolban:
How can I get thefeedback (callback function) of tcp's receive or send ?
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Aug 18, 2017 2:34 pm
by kolban
Howdy,
You will want to study the API called "sockets". This is a standard C/C++ API that is used to TCP/UDP programming against the TCP/IP protocol. If you can google using the phrase "sockets tutorial", I think you will be rewarded by a whole host of articles.
I am also a fan of books on a subject and there are a wealth at
Amazon.
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Wed Aug 23, 2017 7:00 am
by zjuliwang
kolban wrote:Howdy,
You will want to study the API called "sockets". This is a standard C/C++ API that is used to TCP/UDP programming against the TCP/IP protocol. If you can google using the phrase "sockets tutorial", I think you will be rewarded by a whole host of articles.
I am also a fan of books on a subject and there are a wealth at
Amazon.
HI kolban:
I have googled the phrase and found the socket API ,they looks nearly the same as ESP32IDF,I don't see any callback function in ESP32IDF,when I used 8266 ,there were many callback functions like sendback_callback(); I think lwip must have the callback function. if not,how can I send or recieve datas one by one continuely?
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Thu Aug 24, 2017 10:04 pm
by kolban
With TCP/IP sockets API there isn't a "callback" event processing system. Instead, most of the sockets API calls are blocking. For example, if you execute recv() to read data, the call will block until data is made available. Now you have choices that involve task processing. You can create a FreeRTOS task for each socket upon which you want to simultaneously listen. An alternative design is to use the TCP/IP select() API call. This will take an array of sockets as input and will block watching them "all" simultaneously. You will unblock when the first of them has data available to be read without blocking.
Re: Unable to receive TCPIP-packets with wifi callback function
Posted: Fri Aug 25, 2017 12:57 am
by tele_player
select() has a timeout argument which can be used to set no block, block until timeout, or block forever.