0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

W55RP20-EVB-Picoを使ってみよう~C/C++編2~DHCPにしよう

0
Posted at

W55RP20-EVB-Picoを使ってみよう~C/C++編~の続きです。

今回は、DHCPにしてみます。
最初に、examplesdhcp_dns を使用して DHCP をテストしましょう。

https://github.com/WIZnet-ioNIC/WIZnet-PICO-C/tree/main/examples/dhcp_dns
ターゲットとなるDNSが表示されていれば成功です。

DHCP化

次は、固定IPからDHCPに変更してみましょう。
前回も使用した wizchip_http_server.c を使用し、以下を追加します。

wizchip_dhcp_init();
while(1) {
    if (DHCP_IP_LEASED == DHCP_run())
        break;
}

while (1) {
    DHCP_run();
    // Application code can be placed here
}

当然、このまま追加しても動作しない為、調整します。
ヘッダー

/* DHCP */
static void wizchip_dhcp_init(void);
static void wizchip_dhcp_assign(void);
static void wizchip_dhcp_conflict(void);
/* Timer */
static void repeating_timer_callback(void);

Main内

    wizchip_1ms_timer_initialize(repeating_timer_callback);

    network_initialize(g_net_info);
    wizchip_dhcp_init();

    while (1)
    {
        if (DHCP_IP_LEASED == DHCP_run())
            break;
    }
    
    httpServer_init(g_http_send_buf, g_http_recv_buf, HTTP_SOCKET_MAX_NUM, g_http_socket_num_list);

    /* Get network information */
    print_network_information(g_net_info);

    /* Register web page */
    reg_httpServer_webContent("index.html", index_page);

    /* Infinite loop */

    while (1)
    {
        //DHCP_run();
        /* Run HTTP server */
        for (i = 0; i < HTTP_SOCKET_MAX_NUM; i++)
        {
            httpServer_run(i);
        }
    }

関数類は適宜追加します。
コンパイルし書き込むことでDHCPにすることができました。

固定IP&DHCP切替

純粋にDHCP部分をコメントアウトすることでDHCPと固定IPを切り替えるようにしました。
以下を追加することでDHCPが有効になります。
逆にコメントアウトすることで固定IPとなります。

//DHCP
/* 
    wizchip_dhcp_init();

    while (1)
    {
        if (DHCP_IP_LEASED == DHCP_run())
            break;
    }
*/

プログラム

プログラムは以下になります。
https://github.com/taisirou/WIZnet-PICO-C/tree/main

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?