Static IP in v3.x

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 493
Joined: Mon May 12, 2008 10:55 am

Static IP in v3.x

Post by SeeCwriter » Fri Oct 22, 2021 1:27 pm

My NANO & MOD54415 apps allow a user to switch between DHCP or Static IP. Back in the v2.x days, I did this:

Code: Select all

void init_ethernet()
{
  if ( use_dhcp )
    {
    InitializeStack();
    EnableDHCP(true);
    }
    else InitializeStack( SS->ip_addr, SS->ip_mask, SS->ip_gateway, SS->ip_dns);
}

void EnableDHCP( bool enable, int wait_seconds )
  {
  static int ethernet = GetFirstInterface();
  static DhcpObject *dhcp_client = new DhcpObject( ethernet );

  if ( enable ) dhcp_client->StartDHCP();
  else          dhcp_client->StopDHCP();

  if ( enable )
    {
    if ( wait_seconds )
      OSSemPend( &dhcp_client->NotifySem, (WORD) (wait_seconds * TICKS_PER_SECOND) );   
    if ( dog ) watchdog.Spawn();
    }
  else  // Go To Static IP.
    {
    InterfaceBlock *ib = GetInterFaceBlock( CONFIG_IF_ID_ETHERNET );
    if ( SS->ip_address ) ib->netIP     = SS->ip_address;
    if ( SS->ip_mask    ) ib->netIpMask = SS->ip_mask;
    if ( SS->ip_gateway ) ib->netIpGate = SS->ip_gateway;
    if ( SS->ip_dns     ) ib->netDNS    = SS->ip_dns;
    }
  }
For v3.x, does this still work and do I still need to use WaitForActiveNetwork()?

User avatar
TomNB
Posts: 435
Joined: Tue May 10, 2016 8:22 am

Re: Static IP in v3.x

Post by TomNB » Fri Oct 22, 2021 2:51 pm

Hello,

Part of the 3.x objectives is to be able to configure from any operating system, pc, mobile device or tablet. So the configuration is much more flexible, but different than 2.x. Here is a link to the docs: https://www.netburner.com/NBDocs/Develo ... ation.html

For an example, take a look at: \nburn\examples\Configuration\Application\SystemParams\ModifyEthernet. The configuration is a JSON object, so it can also be uploaded or download to a device.

SeeCwriter
Posts: 493
Joined: Mon May 12, 2008 10:55 am

Re: Static IP in v3.x

Post by SeeCwriter » Mon Nov 15, 2021 9:42 am

For changing Ethernet modes, the options are displayed as words, such as "DHCP, DHCP w Fallback, Static". To change the mode, do I enter the words or an array index number? For example, if I wanted "DHCP w Fallback", do I enter 1 (counting from zero), or "DHCP w Fallback"? And once entered, does the module need to reboot to make the change active?

SeeCwriter
Posts: 493
Joined: Mon May 12, 2008 10:55 am

Re: Static IP in v3.x

Post by SeeCwriter » Mon Nov 15, 2021 2:15 pm

I'm trying implement this new way of configuring the network, but it doesn't seem to persist through a power-cycle. I'm not using the discovery webpage to change the configuration, because that is not the method most of our customers will use. I have a command to instruct the module to use either DHCP or Static IP. A new module defaults to DHCP.
When a command to change to Static is received, the following function is called:

Code: Select all

void UpdateEnetMode( bool dhcp )
  {
  config_chooser confChooser = ifBlock->ip4.mode;
  NBString confName;
  char newVal[20];
  confChooser.GetNameValue( confName );
  iprintf( "%s current value: %s\r\n", confName.c_str(), NBString( confChooser ).c_str() );
  if ( dhcp ) strcpy( newVal, "DHCP"   );
  else        strcpy( newVal, "Static" );
  if ( strcmp( newVal, NBString( confChooser ).c_str() ) == 0 ) return;
  confChooser = newVal; 
  SaveConfigToStorage();
  WaitForActiveNetwork();
  }
  
I'm not sure if WaitForActiveNetworks needs to be called each time the network configuration is changed, but it doesn't seem to matter if it's used or not.

When the above function completes, the module is in Static mode, and I can communicate with it using the Static address. When it reboots, the module goes back to DHCP mode.
Interestingly, the static IP address is saved and persists through a power-cycle. I can see it in the discovery configuration webpage.
So changed the mode to Static IP through the discovery configuration webpage and it persists through a power-cycle. Then I changed it back to DHCP through the configuration webpage and rebooted. The module is still using the Static address, the discovery webpage reports that the module is using the DHCP address, and I've clicked on the "Refresh" button several times. But clicking on the "ConfigPage" link does nothing. I can no longer get to the configuration page. I've rebooted several times, closed the discovery webpage and reopened it in a new tab. No change. Eventually I get error message "This page isn't working."

The module is a NANO with v3.3.4 tools.

User avatar
TomNB
Posts: 435
Joined: Tue May 10, 2016 8:22 am

Re: Static IP in v3.x

Post by TomNB » Mon Nov 15, 2021 4:29 pm

The application you are working on may be trapping, and the device is in the alternate boot monitor, so it won't show up in discover. Can you see the device if you run IPSetup?

Regarding the settings not being saved after reboot, I ran the example that I think you took that function from, \nburn\examples\Configuration\Application\SystemParams\ModifyEthernet, and its working for me. Can you build and load that example and see if it works for you?

Note: If your alternate monitor meets the version minimum here: https://www.netburner.com/NBDocs/Develo ... totoc_md30, then you can update the module with a 3.x application directly. If not, then you will first need to load the update app, C:\nburn\platform\NANO54415\original\NANO54415-3p0-Update_APP.s19. If you have an older nano you can update the monitor to be 3.x compliant by opening a support ticket.

SeeCwriter
Posts: 493
Joined: Mon May 12, 2008 10:55 am

Re: Static IP in v3.x

Post by SeeCwriter » Tue Nov 16, 2021 7:58 am

No, the app is not trapping and is not in the boot monitor. I have MTTTY connected to uart0, which would show the trap info. Plus I can communicate with the module via TCP with my Windows utility. But the module is using the Static IP address even though it was set to DHCP using the configuration page of the discovery webpage. Also I can no longer communicate with it via the discovery webpage. This morning, the discover webpage does not show the module. Yesterday it showed the module but displayed the DHCP IP address even though that address was not working.
The function I listed is from the ModifyEthernet example program. I took function UpdateConfigChooser, commenting out the part of entering a new mode choice from a terminal. Otherwise it's the same as the example.

It seems that the only way to recover from this is to reload the update app and start fresh.

This NANO is a brand new module.

SeeCwriter
Posts: 493
Joined: Mon May 12, 2008 10:55 am

Re: Static IP in v3.x

Post by SeeCwriter » Tue Nov 16, 2021 8:24 am

Reloading NANO54415-3p0-Update_APP.s19 did nothing to improve the situation. When the module boots up, this is the terminal output:
-------------------------------------------
Waiting 2sec to start 'A' to abort

Primary network interface configured for Static
IP =10.250.5.230
Mask =0.0.0.0
Gate =0.0.0.0
Dns1 =0.0.0.0
Dns2 =0.0.0.0
MAC Address = 00:03:f4:0e:e9:c1
Type "A" to abort boot

Application: 3p0-Update
NNDK Revision: Rel_3.0.0_dev
---------------------------------------

Notice that it reports that the module is in Static IP mode, and it is using the Static IP address I had set. The discovery webpage still doesn't find the module.

User avatar
TomNB
Posts: 435
Joined: Tue May 10, 2016 8:22 am

Re: Static IP in v3.x

Post by TomNB » Tue Nov 16, 2021 10:04 am

Hello,

There are a couple of issues here:
- A network mask is required.
- If your using discover.netburner.com, both the gateway and dns are required, as well as a way for the device to connect to the Internet.
- If you configure the mask, the localdiscover utility should work.

There seems to be a lot going on here. Please open a support ticket so we can arrange a meeting to see exactly what is happening.

User avatar
TomNB
Posts: 435
Joined: Tue May 10, 2016 8:22 am

Re: Static IP in v3.x

Post by TomNB » Tue Nov 16, 2021 10:17 am

In that ticket we will also get your nano updated so the alt mon can download .bin files directly.

Post Reply