Static IP using LWIP

24 Jan 2012

::EDIT:: EUREKA... see last post.

Hi,

I've looked around for hours now, and i give up.

What is the Static IP equivalent of this DHCP command:

NetServer *net = NetServer::ready();

I tried to look in the .h files, and tried this.

NetServer *net = NetServer::create( 
                                    IPv4(192,168,100,31), //IP Address
                                    IPv4(255,255,255,0), //Netmask
                                    IPv4(192,168,100,31) //Gateway
                                  );

But to no avail....

The readback gives an IP of 109.0.0.0

    //Readback of IP
    ipaddr_local = net->getIPAddr();

    lcd.printf("%c%c%c%c%c%cFlytimer ready.", CMD, LCLS, CMD, CurPos, Col1, Row1);    
    lcd.printf("%c%c%c%cIP:  %d.%d.%d.%d", CMD, CurPos, Col1, Row2,ip4_addr1(&ipaddr_local),ip4_addr2(&ipaddr_local),ip4_addr3(&ipaddr_local), ip4_addr4(&ipaddr_local));    

Anyone? Help? <whimpers>

Theo (nl)

15 Jan 2012

Second try... (does not work either), starting to feel stupid by now :P

        struct ip_addr  ipaddr_local;
        struct ip_addr  ipmask_local;
        struct ip_addr  ipgate_local;

        IP4_ADDR(&ipaddr_local, 192,168,100,30); 
        IP4_ADDR(&ipmask_local, 255,255,255,0); 
        IP4_ADDR(&ipgate_local, 192,168,100,1); 
            
        NetServer *net = NetServer::create(ipaddr_local, ipmask_local, ipgate_local);

But to no avail....

The readback still gives a wrong IP of 93.1.0.0

But in nerserver.cpp this shows up:

NetServer::NetServer(struct ip_addr ip, struct ip_addr nm, struct ip_addr gw)

....? am i misinterpreting the ip_addr structure or what ?

<search continues>

18 Jan 2012

<dagnabbit>

... Can't find it on my own. :(

25 Jan 2012

Found it:

I will post a sample project with the complete code.


    lcd.locate(0,1);
    lcd.printf("Initialize NetSrv");    

    NetServer *net = NetServer::create();
    
    //Use DHCP or Static IP?
    if (DHCP == 0) {
    
        lcd.locate(0,1);
        lcd.printf("Setting static IP ");    
        
        IP4_ADDR(&ipaddr_local, l1,l2,l3,l4); 
        IP4_ADDR(&ipmask_local, s1,s2,s3,s4); 
        IP4_ADDR(&ipgate_local, 192,168,100,1); //example: 4 int's  g1,g2,g3,4);
                   
        net->setUseDHCP(0); 
        net->setIPAddr(ipaddr_local); 
        net->setNetmask(ipmask_local); 
        net->setGateway(ipgate_local); 
        net->setHostname("MbedRood");
        net->ready(); //this will print IP

        }
    else {    

        lcd.locate(0,1);
        lcd.printf("Using DHCP        ");    
        
        net->setUseDHCP(1); 
        net->setHostname("MbedRood");
        net->ready(); //this will print IP
        
        }