Page 1 of 1

Sockets with APSTA mode

Posted: Fri Oct 26, 2018 10:28 pm
by rsimpsonbusa
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

Re: Sockets with APSTA mode

Posted: Fri Oct 26, 2018 10:52 pm
by fly135
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.
struct 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.
John A

Re: Sockets with APSTA mode

Posted: Sat Oct 27, 2018 12:27 am
by rsimpsonbusa
Hi John A.

If I start the service as APSTA

Code: Select all

	ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
and DO NOT CALL the STA configuration, it works fine using the Multicast Address.

If I start the STA part

Code: Select all

ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &configap));
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

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;
	          }
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

Re: Sockets with APSTA mode

Posted: Sat Oct 27, 2018 1:32 am
by WiFive
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

Re: Sockets with APSTA mode

Posted: Sun Oct 28, 2018 3:43 am
by rsimpsonbusa
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