Static IP address in STA mode

Hi,

We don’t want to set up static IP address from Router side.
With AmebaD standard SDK, is it possible to force request static IP address from Ameba side to Router in STA mode ?

Regards,

do you need a static IP or dynamic one?

@xidameng
Thank you for your reply.

We need static IP address.

We don’t want to set up static IP address from Router side.

What I mean on above is, normally if we need static IP address we have to set up from Router side.
Is it possible to force request by from Ameba side without any Router set up ?

Regards,

You might want to try using WiFI::config to set a local IP address. This would probably require that the DHCP server on the router is disabled, otherwise the router might assign a different IP address, which would mean that all other devices connected to the same router would need to have their IP addresses set correctly to avoid conflicting IPs.

@wyy
Thank you for reply.
Do you mean that I have to config from Wi-Fi Router side right ? We cannot force it from Ameba side right ?

Regards,

@ruanjanc
You have to configure the router to allow for devices to define their own IP addresses, before you can define it in Ameba.
Otherwise, most routers are configured to use DHCP by default, in which the router is in charge of allocating IP addresses.

My suggestion is that if you only have one device out of many that needs a fixed IP address, it is easier to configure the router to link a specific IP address to the device’s MAC address.

1 Like
You have to configure the router to allow for devices to define their own IP addresses, before you can define it in Ameba.
Otherwise, most routers are configured to use DHCP by default, in which the router is in charge of allocating IP addresses.

Understood, may I know with AmebaD standard SDK how I can define IP in Ameba ?

My suggestion is that if you only have one device out of many that needs a fixed IP address, it is easier to configure the router to link a specific IP address to the device’s MAC address.
This is the solution that we did, but requirement is don’t want Router side to link a specific IP via MAC address.

Regards,

@wyy
More information, Router side already reserve IP range for Ameba devices.
So, with AmebaD standard SDK how I can define IP in Ameba ?

Regards,

@ruanjanc

You can set IP addresses in \project\realtek_amebaD_va0_example\inc\inc_hp\main.h, and when configuring LwIP, call LwIP_UseStaticIP instead of LwIP_DHCP

1 Like

@wyy
Thank you for quick reply, I will try it.

Best regards,

I too need my product to be able to use either DHCP or static IP.
With the aid of the answers above, I have modified the code in component/common/example/wlan_fast_connect/example_wlan_fast_connect.c as follows (cgm are my initials making it easy to find stuff I’ve done):
if(ret == RTW_SUCCESS){
#ifdef CGM_STATIC_IP
extern unsigned char cgm_dhcp_mode;
struct netif * pnetif = &xnetif[0];
if (cgm_dhcp_mode == 2){
printf(“Start Static IP”);
LwIP_UseStaticIP(pnetif);
}
else
#endif
{
printf(“Start DHCP wlan_fast_connect”);
LwIP_DHCP(0, DHCP_START);
}
}
This works OK in that if I have cgm_dhcp_mode set to 1, DHCP runs, and if I have it set to 2, the board comes up with a static IP as expected.
However, if the board is configured to use DHCP, but is then brought up on a network which has no DHCP server, the initialisation hangs for 60 seconds, meaning wifi_interactive does not get to start, meaning that I can’t then correct the board configuration - and if I type a command to the UART, the board crashes (presumably because the enhanced commands have not been stitched in to the table).
Is there a cleaner way to do this, ideally in such a way that the interactive usage can start before the DHCP has timed out?

I can see a few choices:

  • Disable fast connect in platform_opts.h and always use manual connection, then use AT command to configure DHCP before connecting to a network
  • Change the code to always use a fixed static IP when connecting, then enable DHCP by AT command if network supports it
  • Run the DHCP client in a separate RTOS thread after connecting to WiFi

Thanks for those suggestions. I’ll have a tinker. I am trying to keep my changes to the SDK-supplied files to a minimum, and I’ll report back how I get on!