gpufler
gpufler

Registered on 1年前

Answers
2
Article
0
Follower
0

Hi xiangxistu,

thank you for help, this done a trick, and work like charm.
Here is a test code if someone need it:


int dhcpDown(void) {

    struct netdev *netdev = RT_NULL;
    ip_addr_t dns_addr;

    netdev = netdev_get_by_name("e0");
    if (netdev == RT_NULL) {
        rt_kprintf("bad network interface device name(e0).\n");
    }

    netdev_dhcp_enabled(netdev, RT_FALSE);

    inet_aton("192.168.1.10", &dns_addr);
    if (netdev_set_dns_server(netdev, 0, &dns_addr) == RT_EOK) {
        rt_kprintf("set network interface device(%s) dns server #%d: %s\n", "e0", 0, "192.168.1.10");
    }
    inet_aton("192.168.1.251", &dns_addr);
    netdev_set_ipaddr(netdev, &dns_addr);

}

int dhcpUp(void) {
    struct netdev *netdev = RT_NULL;

    netdev = netdev_get_by_name("e0");
    if (netdev == RT_NULL) {
        rt_kprintf("bad network interface device name(e0).\n");
    }

    netdev_dhcp_enabled(netdev, RT_TRUE);
}


MSH_CMD_EXPORT(dhcpDown,  disable DHCP and set static IP);
MSH_CMD_EXPORT(dhcpUp,  enable DHCP);

Thank you again.

Ok, while we are here, I got another one question :)

I'm using CH32V307, and he does not have dedicated pins for network LED's. I try to find out in board files and low level functions to assign and enable this LEDs to have visual representation of network activity. Without RT Thread, I use WCHNET library and there is Ethernet_LED_LINKSET and Ethernet_LED_DATASET and this done a trick. This is lib external functions, but I can not find anything like this in RT.

Any idea how to do that?

THX
Goran

Hi,

thank you for answer. Yes, I look into this direction, and I found ifconfig source. And, yes, I create test console command to try to change IP, but, I'm doing something wrong. I can't find command to turn DHCP off.
Here is my RT network config
rtconfig.PNG

and here is test code. If I turn off DHCP in configuration, code work like expected, but if I turn it on, I can't find a way to switch it off.


int test(void) {

    struct netdev *netdev = RT_NULL;
    ip_addr_t dns_addr;

    netdev = netdev_get_by_name("e0");
    if (netdev == RT_NULL) {
        rt_kprintf("bad network interface device name(e0).\n");
    }

    inet_aton("192.168.1.10", &dns_addr);
    if (netdev_set_dns_server(netdev, 0, &dns_addr) == RT_EOK) {
        rt_kprintf("set network interface device(%s) dns server #%d: %s\n", "e0", 0, "192.168.1.10");
    }

    inet_aton("192.168.1.251", &dns_addr);
    netdev_set_ipaddr(netdev, &dns_addr);

}

THX
Goran

Create
Post