完善资料让更多小伙伴认识你,还能领取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: %s\n", 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" ??? } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
2135个成员聚集在这个小组
加入小组我的项目我做主,使用GN+Ninja来完成构建系统(VSCode开发RT106X)
37376 浏览 0 评论
NXP IMX8应用处理器快速入门必备:技巧、使用、设计指南
6775 浏览 1 评论
7793 浏览 1 评论
7642 浏览 0 评论
NXP i.MX6UL开发板(linux系统烧录+规格+硬件+模块移植)使用手册
5071 浏览 0 评论
1556浏览 2评论
关于NINA-W132 Wi-Fi模块SPI通信遇到的疑问求解
1207浏览 2评论
如何在MPC PowerPC MCU上首次刷写后禁用BDM?
749浏览 1评论
将HFREFR和LFREFR寄存器值设置为错误的值来将故障注入CMU,但CMU_ISR值始终为零,为什么?
735浏览 1评论
将SPSDK for FRDM-MCX-W71 SDK与VS一起安装时出现hidapi构建错误怎么解决?
677浏览 1评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 19:52 , Processed in 0.931622 second(s), Total 70, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
358