Sockets with APSTA mode

rsimpsonbusa
Posts: 126
Joined: Tue May 17, 2016 8:12 pm

Sockets with APSTA mode

Postby rsimpsonbusa » Fri Oct 26, 2018 10:28 pm

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

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Sockets with APSTA mode

Postby fly135 » Fri Oct 26, 2018 10:52 pm

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

rsimpsonbusa
Posts: 126
Joined: Tue May 17, 2016 8:12 pm

Re: Sockets with APSTA mode

Postby rsimpsonbusa » Sat Oct 27, 2018 12:27 am

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

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

Re: Sockets with APSTA mode

Postby WiFive » Sat Oct 27, 2018 1:32 am

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

rsimpsonbusa
Posts: 126
Joined: Tue May 17, 2016 8:12 pm

Re: Sockets with APSTA mode

Postby rsimpsonbusa » Sun Oct 28, 2018 3:43 am

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

Who is online

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