完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我想生成一个带有 mac 地址的服务器主机名。
什么时候必须调用函数“void set_unique_hostname()”? 代码:全选 void init_my_server() { ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); // Register event handlers to start server when Wi-Fi is connected, // and stop server when disconnection happens. ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, NULL)); // This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. // Read "Establishing Wi-Fi or Ethernet Connection" section in // examples/protocols/README.md for more information about this function. // ESP_ERROR_CHECK(example_connect()); // replace this function with "own implementation". } void set_unique_hostname() { /* typedef enum { ESP_MAC_WIFI_STA, ESP_MAC_WIFI_SOFTAP, ESP_MAC_BT, ESP_MAC_ETH, } esp_mac_type_t; */ uint8_t get_mac[6]; esp_err_t ret = esp_read_mac( get_mac, ESP_MAC_WIFI_STA ); if( ret != ESP_OK ) { printf( "nError Reading Mac Address: %sn", esp_err_to_name(ret) ); return; } char new_hostname[50]; sprintf( new_hostname, "www.%02X:%02X:%02X.domain.local", get_mac[3], get_mac[4], get_mac[5] ); // I believe that in production i would not need to use this function. i need to read the mac address, generate the hostname string, and write it once to flash memory. Maybe a script ????? char old_hostname[50]; esp_netif_get_hostname( , old_hostname ); // How to get "esp_netif_t *esp_netif" ??? // old_hostname must be pointer to pointer argument ??? if ( strncmp( new_hostname, old_hostname, strlen(old_hostname) ) == 0 ) { return; } esp_netif_set_hostname( , new_hostname ); // How to get "esp_netif_t *esp_netif" ??? } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
140 浏览 0 评论
1158 浏览 1 评论
584浏览 6评论
480浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
465浏览 5评论
466浏览 4评论
441浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 06:23 , Processed in 0.831116 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号