Anyone get static IP assignment working for wifi?

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

Anyone get static IP assignment working for wifi?

Postby fly135 » Fri Apr 13, 2018 6:20 pm

I've put the following code in project and it shows the correct IP assigned. But I can't get DNS to work. I don't think the address I assign in dns_setserver is the problem as I also tried Google's 8.8.8.8.

Code: Select all

  tcpip_adapter_ip_info_t ip_info;
  ip_addr_t addr;
  
  addr.type = IPADDR_TYPE_V4;
  addr.u_addr.ip4.addr = htonl(0xC0A80101);
  dns_setserver(1, (const ip_addr_t *)&addr);

  int ret = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
  printf("stop dhcp ret = %d\n",ret);
  memset(&ip_info, 0, sizeof(ip_info));
  IP4_ADDR(&ip_info.ip, 192, 168, 3, 2);
  IP4_ADDR(&ip_info.gw, 192, 168, 3, 1);
  IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
  ret = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
  printf("fixex ip ret = %d\n",ret);

chegewara
Posts: 2362
Joined: Wed Jun 14, 2017 9:00 pm

Re: Anyone get static IP assignment working for wifi?

Postby chegewara » Fri Apr 13, 2018 7:30 pm

With this library ive been able to assign static PI. Esp was accessed from LAN but dont remember if it could access internet.
https://github.com/nkolban/esp32-snippe ... g/bootwifi

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Anyone get static IP assignment working for wifi?

Postby kolban » Fri Apr 13, 2018 9:44 pm

Here is a fragment of notes that I made in my ESP32 book of notes:
On the Internet, server machines can be found by their Domain Name Service (DNS) names. This is the service that resolves a human readable representation of a machine such as "google.com" into the necessary IP address value (eg. 216.58.217.206). In order for this transformation to happen, the ESP32 needs to know the IP address of one or more DNS servers that it will then use to perform the name to IP address mapping. If we are using DHCP then nothing else need be done as the DHCP server automatically provides the DNS server addresses. However, if we should not be using DHCP (for example we are using static IP addresses), then we need to instruct the ESP32 of the locations of the DNS servers manually. We can do this using dns_setserver() function. This takes an IP address as input along with which of the two possible DNS servers to use. The ESP32 is configured to know the identity of up to two external name servers. The reason for two is that if an attempt to reach the first one fails, we will utilize the second one. We can retrieve our current DNS server identities using dns_getserver().

Google publicly makes available two name servers with the addresses of 8.8.8.8 and 8.8.4.4.
Once we have define the name servers, we can look up the address of a host name using the gethostbyname() function.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: Anyone get static IP assignment working for wifi?

Postby Vader_Mester » Sat Apr 14, 2018 6:13 pm

fly135 wrote:I've put the following code in project and it shows the correct IP assigned. But I can't get DNS to work. I don't think the address I assign in dns_setserver is the problem as I also tried Google's 8.8.8.8.

Code: Select all

  tcpip_adapter_ip_info_t ip_info;
  ip_addr_t addr;
  
  addr.type = IPADDR_TYPE_V4;
  addr.u_addr.ip4.addr = htonl(0xC0A80101);
  dns_setserver(1, (const ip_addr_t *)&addr);

  int ret = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
  printf("stop dhcp ret = %d\n",ret);
  memset(&ip_info, 0, sizeof(ip_info));
  IP4_ADDR(&ip_info.ip, 192, 168, 3, 2);
  IP4_ADDR(&ip_info.gw, 192, 168, 3, 1);
  IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
  ret = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
  printf("fixex ip ret = %d\n",ret);
Instead of static IP on your ESP, try to reserve an IP on your router based on MAC address of the ESP.
The router will use DHCP in this case so everything should work, and the router will assign the static IP to the device.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}


eshkrab
Posts: 6
Joined: Thu Apr 05, 2018 1:38 am

Re: Anyone get static IP assignment working for wifi?

Postby eshkrab » Sat Apr 14, 2018 11:58 pm

I made this component https://github.com/eshkrab/esp32_tcpip for the TCP/IP stack, so in make menuconfig you can chose whether you want Ethernet or Wifi and DHCP or static IP. All you have to do after those settings is include "tcpip.h" and call tcpip_driver_init() before doing any internet tasks. Hope this is useful to someone!

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

Re: Anyone get static IP assignment working for wifi?

Postby fly135 » Sun Apr 15, 2018 3:40 pm

Thanks for the responses. Looks like I have a couple of things I can try. The wifi router I'm testing with is pretty old and basic. Fixing the IP based on MAC was the first thing I looked for in the settings and it doesn't seem to have that ability.

John A

User avatar
Vader_Mester
Posts: 300
Joined: Tue Dec 05, 2017 8:28 pm
Location: Hungary
Contact:

Re: Anyone get static IP assignment working for wifi?

Postby Vader_Mester » Tue Apr 17, 2018 7:24 am

So you have a state of the art Wifi enabled Microcontroller, spend 10s of $s on development hardware, but have an old router?
That's not gonna work.

Well, I suggest you grab a new router for the following 5 reasons:
- Security
- Security
- Security
- Compatibility
- Nive UI and settings

Wifi standards have gone through a lot of upgrades since the old days, so it's advised not to use an outdated router to make sure that it has an up-to-date firmware and functions. You will have an easier job doing development for Wifi with a better router.

You can buy a new TP-Link router for veeeeery cheap (costs as much as an ESP devboard). You'll be very happy in the end.

I have a 4 year old TP-link, it was just $20 then. I think it's a TL-WR720N. It's a great little router with all the required magic inside. It also supports DDNS natively and port forwarding. It has only 2 LAN ports and 1 WAN, but never had any problems with it.

Code: Select all

task_t coffeeTask()
{
	while(atWork){
		if(!xStreamBufferIsEmpty(mug)){
			coffeeDrink(mug);
		} else {
			xTaskCreate(sBrew, "brew", 9000, &mug, 1, NULL);
			xSemaphoreTake(sCoffeeRdy, portMAX_DELAY);
		}
	}
	vTaskDelete(NULL);
}

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

Re: Anyone get static IP assignment working for wifi?

Postby fly135 » Tue Apr 17, 2018 2:30 pm

Good point about using an old router. This is just the test station router that I have attached to a switch with port mirroring so I can snoop the packets. I can connect to a much newer router that I use for my main wireless access in the house for further testing. It really didn't occur to me that there would be any difference.

John A

User avatar
hassan789
Posts: 156
Joined: Thu Jun 29, 2017 2:15 am

Re: Anyone get static IP assignment working for wifi?

Postby hassan789 » Tue Apr 17, 2018 5:51 pm

yes, i got it to work.. you need to add this

Code: Select all

  ip_addr_t d; 
  d.type = IPADDR_TYPE_V4; 
  d.u_addr.ip4.addr = 0x08080808; //8.8.8.8 dns
  dns_setserver(0, &d); 

Who is online

Users browsing this forum: No registered users and 83 guests