Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static ip set in wifi- station mode in esp32 (IDFGH-3274) #5266

Closed
sowmimalu opened this issue May 11, 2020 · 4 comments
Closed

static ip set in wifi- station mode in esp32 (IDFGH-3274) #5266

sowmimalu opened this issue May 11, 2020 · 4 comments

Comments

@sowmimalu
Copy link

hai ,
In my application i need to connect with the static IP given.
i can able to connect when used
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
it can able get ip with dynamic and connect with wifi
then i tried with static,
tcpip_adapter_init();
tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); // Don't run a DHCP client
tcpip_adapter_ip_info_t ip_info;
ip_info.ip.addr = ipaddr_addr("192.168.43.3");
ip_info.gw.addr = ipaddr_addr("192.168.43.1");
ip_info.netmask.addr = ipaddr_addr("255.255.255.0");
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
printf("IP Address: %s\n", ip4addr_ntoa(&ip_info.ip));
printf("Subnet mask: %s\n", ip4addr_ntoa(&ip_info.netmask));
printf("Gateway: %s\n", ip4addr_ntoa(&ip_info.gw));
ESP_ERROR_CHECK(tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA));

but always i am getting invalid static ip ...

could you please tell me on how to fix the static ip and to connect with wifi??

@github-actions github-actions bot changed the title static ip set in wifi- station mode in esp32 static ip set in wifi- station mode in esp32 (IDFGH-3274) May 11, 2020
@david-cermak
Copy link
Collaborator

Hi @sowmimalu

No need to start the DHCP client after setting the address.

tcpip_adapter_set_ip_info(WIFI_IF_STA, &ip);

This should be enough to setup static IP address, after that an IP event should be received (depending on your event registration, e.g. ip_sta_got_ip_handler() if you register that function for the IP_EVENT base with the IP_EVENT_STA_GOT_IP event id)

@sowmimalu
Copy link
Author

tried now its working...thank you

@AxelLin
Copy link
Contributor

AxelLin commented Aug 3, 2020

This should be closed. @Alvin1Zhang

@Alvin1Zhang
Copy link
Collaborator

Thanks for the notes @AxelLin . @sowmimalu Glad that it is working, feel free to reopen if the issue still happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants