Hi everybody.
I have an ESP32 that works as an AP and STA (APSTA mode). I can send UDP messages to specific addresses, say internal AP address like 192.168.4.2, etc and 192.168.100.2 another IP in the wifi network(external AP). Both work well.
The problem is that when I send as MULTICAST message, 232.10.11.12 (as in the Multicast example) it goes to the External AP and I find no way how to control this. How do I set up the Multicast address or the socket to send to the Internal or External AP at my desire?
Any help welcomed.
RSN
Sockets with APSTA mode
Re: Sockets with APSTA mode
Not sure if this will work on LWIP because I haven't tried it. But multicast only goes out one interface. You can try the following to select which network interface you want.
John Astruct in_addr addr;
setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr))
where addr is the local IP address of the outgoing interface you want.
-
- Posts: 126
- Joined: Tue May 17, 2016 8:12 pm
Re: Sockets with APSTA mode
Hi John A.
If I start the service as APSTA and DO NOT CALL the STA configuration, it works fine using the Multicast Address.
If I start the STA part it does not reach the ESP AP stations when setting destination address the selected MULTICAST address, which in the example UDP MULTICAST is 232.10.11.12, and DOES reach the external AP(seen in Wireshark).
As another test, I simultaneously send to the Multicast Address and a local ip address (which defeats the purpose of Multicast by using a specific local address) like 192.168.4.2. It does reach the local ip but not the Multicast. If I do not start the STA the 2 messages are received by the Station(with local ip 192.168.4.2)
BTW, the socket is created as Multicast
As it stands, we could not use a Multicast Address for the ESP32 AP if we also need to access the external world.
Regards.
Robert
If I start the service as APSTA
Code: Select all
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
If I start the STA part
Code: Select all
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &configap));
As another test, I simultaneously send to the Multicast Address and a local ip address (which defeats the purpose of Multicast by using a specific local address) like 192.168.4.2. It does reach the local ip but not the Multicast. If I do not start the STA the 2 messages are received by the Station(with local ip 192.168.4.2)
BTW, the socket is created as Multicast
Code: Select all
sockl = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sockl < 0) {
ESP_LOGE(TAG, "Failed to create socketl. Error %d", errno);
return -1;
}
uint8_t ttl = MULTICAST_TTL;
err=setsockopt(sockl, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(uint8_t));
if (err < 0) {
ESP_LOGE(TAG, "Failed to set IP_MULTICAST_TTL sockel. Error %d", errno);
return;
}
Regards.
Robert
Re: Sockets with APSTA mode
I think you ignored the suggestion. You will have to have 2 multicast sockets, 1 for AP side and 1 for sta side.
https://github.com/espressif/esp-idf/bl ... #L141-L145
https://github.com/espressif/esp-idf/bl ... #L141-L145
-
- Posts: 126
- Joined: Tue May 17, 2016 8:12 pm
Re: Sockets with APSTA mode
Hi John.
This links explains perfectly how to select the Interface and general multicast functionality.
Thanks for your ideas.
Robert
https://www.ibm.com/support/knowledgece ... ticast.htm
This links explains perfectly how to select the Interface and general multicast functionality.
Thanks for your ideas.
Robert
https://www.ibm.com/support/knowledgece ... ticast.htm
Who is online
Users browsing this forum: Bing [Bot] and 123 guests