wifi_softap_set_dhcps_lease函数错误
wifi_softap_set_dhcps_lease函数错误
Postby zhongjru » Tue Oct 27, 2015 12:47 am
设置softAP模式,启动DHCP服务错误(wifi_softap_set_dhcps_lease函数返回false),代码如下:
int ap_setup(void)
{
struct ip_info info;
struct softap_config config;
struct dhcps_lease dhcp_lease;
if (!wifi_set_opmode_current(SOFTAP_MODE)) return -1; //Set softAP mode
strcpy(config.ssid, "configmode");
strcpy(config.password, "12345678");
config.ssid_len=strlen(config.ssid);
config.channel=11;
config.authmode=AUTH_WPA2_PSK;
config.ssid_hidden=0;
config.max_connection=4; //max 4
config.beacon_interval=100;
if (!wifi_softap_set_config_current(&config)) return -2;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
if (!wifi_set_ip_info(SOFTAP_IF, &info)) return -4;
const char* start_ip = "192.168.1.2";
const char* end_ip = "192.168.1.102";
dhcp_lease.start_ip.addr = ipaddr_addr(start_ip);
dhcp_lease.end_ip.addr = ipaddr_addr(end_ip);
if (!wifi_softap_set_dhcps_lease(&dhcp_lease)) os_printf("wifi_softap_set_dhcps_lease fail\n"); //return -3;
if (!wifi_softap_dhcps_start()) return -5;
wifi_status_led_install(13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); //GPIO13 is status of WIFI
return 0; //success
}
忽略错误继续运行,功能无误,原因?
int ap_setup(void)
{
struct ip_info info;
struct softap_config config;
struct dhcps_lease dhcp_lease;
if (!wifi_set_opmode_current(SOFTAP_MODE)) return -1; //Set softAP mode
strcpy(config.ssid, "configmode");
strcpy(config.password, "12345678");
config.ssid_len=strlen(config.ssid);
config.channel=11;
config.authmode=AUTH_WPA2_PSK;
config.ssid_hidden=0;
config.max_connection=4; //max 4
config.beacon_interval=100;
if (!wifi_softap_set_config_current(&config)) return -2;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
if (!wifi_set_ip_info(SOFTAP_IF, &info)) return -4;
const char* start_ip = "192.168.1.2";
const char* end_ip = "192.168.1.102";
dhcp_lease.start_ip.addr = ipaddr_addr(start_ip);
dhcp_lease.end_ip.addr = ipaddr_addr(end_ip);
if (!wifi_softap_set_dhcps_lease(&dhcp_lease)) os_printf("wifi_softap_set_dhcps_lease fail\n"); //return -3;
if (!wifi_softap_dhcps_start()) return -5;
wifi_status_led_install(13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); //GPIO13 is status of WIFI
return 0; //success
}
忽略错误继续运行,功能无误,原因?
Re: wifi_softap_set_dhcps_lease函数错误
Postby zhongjru » Tue Oct 27, 2015 8:30 pm
start,in uart0
wifi_softap_set_dhcps_lease fail
system meminfo:
data : 0x3ffe8000 ~ 0x3ffe8378, len: 888
rodata: 0x3ffe8378 ~ 0x3ffe85a8, len: 560
bss : 0x3ffe85a8 ~ 0x3ffef010, len: 27240
heap : 0x3ffef010 ~ 0x3fffc000, len: 53232
mode : softAP(1a:fe:34:a2:8b:95)
add if1
dhcp server start:(ip:192.168.1.1,mask:255.255.255.0,gw:192.168.1.1)
bcn 100
LED flush,in uart0
LED flush,in uart0
LED flush,in uart0
主函数:
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
int i;
wifi_set_opmode(SOFTAP_MODE); //Set softAP mode
// Initialize the GPIO subsystem.
gpio_init();
uart_init(115200, 115200);
uart0_sendStr("system start,in uart0\r\n");
uart1_sendStr_no_wait("system start,in uart1\r\n");
if ((i=ap_setup())) os_printf("start AP mode fail,error code %d\n", i);
os_printf("system meminfo:\n");
system_print_meminfo();
//Set GPIO2 to output mode
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
//Set GPIO12 to output mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO12);
//Set GPIO2 low
// gpio_output_set(0, BIT2, BIT2, 0);
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
//&some_timer is the pointer
//1000 is the fire time in ms
//0 for once and 1 for repeating
os_timer_arm(&some_timer, 1000, 1);
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
wifi_softap_set_dhcps_lease fail
system meminfo:
data : 0x3ffe8000 ~ 0x3ffe8378, len: 888
rodata: 0x3ffe8378 ~ 0x3ffe85a8, len: 560
bss : 0x3ffe85a8 ~ 0x3ffef010, len: 27240
heap : 0x3ffef010 ~ 0x3fffc000, len: 53232
mode : softAP(1a:fe:34:a2:8b:95)
add if1
dhcp server start:(ip:192.168.1.1,mask:255.255.255.0,gw:192.168.1.1)
bcn 100
LED flush,in uart0
LED flush,in uart0
LED flush,in uart0
主函数:
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
int i;
wifi_set_opmode(SOFTAP_MODE); //Set softAP mode
// Initialize the GPIO subsystem.
gpio_init();
uart_init(115200, 115200);
uart0_sendStr("system start,in uart0\r\n");
uart1_sendStr_no_wait("system start,in uart1\r\n");
if ((i=ap_setup())) os_printf("start AP mode fail,error code %d\n", i);
os_printf("system meminfo:\n");
system_print_meminfo();
//Set GPIO2 to output mode
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
//Set GPIO12 to output mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO12);
//Set GPIO2 low
// gpio_output_set(0, BIT2, BIT2, 0);
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
//&some_timer is the pointer
//1000 is the fire time in ms
//0 for once and 1 for repeating
os_timer_arm(&some_timer, 1000, 1);
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Re: wifi_softap_set_dhcps_lease函数错误
Postby zhongjru » Wed Oct 28, 2015 8:05 pm
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "mem.h"
#include "uart.h"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void user_procTask(os_event_t *events);
static volatile os_timer_t some_timer;
int get_stations(void);
void some_timerfunc(void *arg)
{
//Do blinky stuff
if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT13)
{
//Set GPIO2 to LOW
// gpio_output_set(0, BIT2, BIT2, 0);
GPIO_OUTPUT_SET(12, 0);
}
else
{
//Set GPIO2 to HIGH
// gpio_output_set(BIT2, 0, BIT2, 0);
GPIO_OUTPUT_SET(12, 1);
}
get_stations();
os_printf("LED flush,in task\n");
}
//Do nothing function
static void ICACHE_FLASH_ATTR
user_procTask(os_event_t *events)
{
os_delay_us(10);
}
//return : 0-success,other-fail
int ap_setup(void)
{
struct ip_info info;
struct softap_config config;
struct dhcps_lease dhcp_lease;
if (!wifi_set_opmode_current(SOFTAP_MODE)) return -1; //Set softAP mode
os_memcpy(config.ssid, "configmode", 10);
os_memcpy(config.password, "12345678", 8);
config.ssid_len=os_strlen(config.ssid);
config.channel=11;
config.authmode=AUTH_WPA2_PSK;
config.ssid_hidden=0;
config.max_connection=4; //max 4
config.beacon_interval=100;
if (!wifi_softap_set_config_current(&config)) return -2;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
if (!wifi_set_ip_info(SOFTAP_IF, &info)) return -4;
const char* start_ip = "192.168.1.2";
const char* end_ip = "192.168.1.102";
dhcp_lease.start_ip.addr = ipaddr_addr(start_ip);
dhcp_lease.end_ip.addr = ipaddr_addr(end_ip);
if (!wifi_softap_set_dhcps_lease(&dhcp_lease)) os_printf("wifi_softap_set_dhcps_lease fail\n"); //return -3;
if (!wifi_softap_dhcps_start()) return -5;
wifi_status_led_install(13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); //GPIO13 is status of WIFI
return 0; //success
}
//get station info in AP mode
//return stations
int get_stations(void)
{
int i=0;
struct station_info * station = wifi_softap_get_station_info();
struct station_info * next_station;
while(station)
{
os_printf("bssid : %02x:%02x:%02x:%02x:%02x:%02x, ip : %d.%d.%d.%d\n", MAC2STR(station->bssid), IP2STR(&station->ip));
next_station = STAILQ_NEXT(station, next);
os_free(station); // Free it directly
station = next_station;
i++;
}
return i;
}
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
int i;
wifi_set_opmode(SOFTAP_MODE); //Set softAP mode
// Initialize the GPIO subsystem.
gpio_init();
uart_init(115200, 115200);
uart0_sendStr("system start,in uart0\r\n");
uart1_sendStr_no_wait("system start,in uart1\r\n");
if ((i=ap_setup())) os_printf("start AP mode fail,error code %d\n", i);
os_printf("chip id 0x%x\n", system_get_chip_id() );
os_printf("CPU frequency %dMHz\n", system_get_cpu_freq() );
os_printf("flash id 0x%x, flash map %d\n", spi_flash_get_id(), system_get_flash_size_map());
os_delay_us(50000); //30ms,wait print finish
// os_printf("power valtage is %d/1024V, system meminfo:\n", system_get_vdd33() );
system_print_meminfo();
//Set GPIO2 to output mode
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
//Set GPIO12 to output mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO12);
//Set GPIO2 low
// gpio_output_set(0, BIT2, BIT2, 0);
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
//&some_timer is the pointer
//1000 is the fire time in ms
//0 for once and 1 for repeating
os_timer_arm(&some_timer, 1000, 1);
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "mem.h"
#include "uart.h"
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void user_procTask(os_event_t *events);
static volatile os_timer_t some_timer;
int get_stations(void);
void some_timerfunc(void *arg)
{
//Do blinky stuff
if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT13)
{
//Set GPIO2 to LOW
// gpio_output_set(0, BIT2, BIT2, 0);
GPIO_OUTPUT_SET(12, 0);
}
else
{
//Set GPIO2 to HIGH
// gpio_output_set(BIT2, 0, BIT2, 0);
GPIO_OUTPUT_SET(12, 1);
}
get_stations();
os_printf("LED flush,in task\n");
}
//Do nothing function
static void ICACHE_FLASH_ATTR
user_procTask(os_event_t *events)
{
os_delay_us(10);
}
//return : 0-success,other-fail
int ap_setup(void)
{
struct ip_info info;
struct softap_config config;
struct dhcps_lease dhcp_lease;
if (!wifi_set_opmode_current(SOFTAP_MODE)) return -1; //Set softAP mode
os_memcpy(config.ssid, "configmode", 10);
os_memcpy(config.password, "12345678", 8);
config.ssid_len=os_strlen(config.ssid);
config.channel=11;
config.authmode=AUTH_WPA2_PSK;
config.ssid_hidden=0;
config.max_connection=4; //max 4
config.beacon_interval=100;
if (!wifi_softap_set_config_current(&config)) return -2;
wifi_softap_dhcps_stop();
IP4_ADDR(&info.ip, 192, 168, 1, 1);
IP4_ADDR(&info.gw, 192, 168, 1, 1);
IP4_ADDR(&info.netmask, 255, 255, 255, 0);
if (!wifi_set_ip_info(SOFTAP_IF, &info)) return -4;
const char* start_ip = "192.168.1.2";
const char* end_ip = "192.168.1.102";
dhcp_lease.start_ip.addr = ipaddr_addr(start_ip);
dhcp_lease.end_ip.addr = ipaddr_addr(end_ip);
if (!wifi_softap_set_dhcps_lease(&dhcp_lease)) os_printf("wifi_softap_set_dhcps_lease fail\n"); //return -3;
if (!wifi_softap_dhcps_start()) return -5;
wifi_status_led_install(13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13); //GPIO13 is status of WIFI
return 0; //success
}
//get station info in AP mode
//return stations
int get_stations(void)
{
int i=0;
struct station_info * station = wifi_softap_get_station_info();
struct station_info * next_station;
while(station)
{
os_printf("bssid : %02x:%02x:%02x:%02x:%02x:%02x, ip : %d.%d.%d.%d\n", MAC2STR(station->bssid), IP2STR(&station->ip));
next_station = STAILQ_NEXT(station, next);
os_free(station); // Free it directly
station = next_station;
i++;
}
return i;
}
//Init function
void ICACHE_FLASH_ATTR
user_init()
{
int i;
wifi_set_opmode(SOFTAP_MODE); //Set softAP mode
// Initialize the GPIO subsystem.
gpio_init();
uart_init(115200, 115200);
uart0_sendStr("system start,in uart0\r\n");
uart1_sendStr_no_wait("system start,in uart1\r\n");
if ((i=ap_setup())) os_printf("start AP mode fail,error code %d\n", i);
os_printf("chip id 0x%x\n", system_get_chip_id() );
os_printf("CPU frequency %dMHz\n", system_get_cpu_freq() );
os_printf("flash id 0x%x, flash map %d\n", spi_flash_get_id(), system_get_flash_size_map());
os_delay_us(50000); //30ms,wait print finish
// os_printf("power valtage is %d/1024V, system meminfo:\n", system_get_vdd33() );
system_print_meminfo();
//Set GPIO2 to output mode
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
//Set GPIO12 to output mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO12);
//Set GPIO2 low
// gpio_output_set(0, BIT2, BIT2, 0);
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
//&some_timer is the pointer
//1000 is the fire time in ms
//0 for once and 1 for repeating
os_timer_arm(&some_timer, 1000, 1);
//Start os task
system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Re: wifi_softap_set_dhcps_lease函数错误
Postby ESP_Faye » Fri Oct 30, 2015 3:47 pm
您好,
我试了您的代码,因为没有 gpio.h ,测试时将 GPIO 和 UART 部分去掉了。
测试未能复现到您的问题。
附件为我编译生成的 bin 文件,麻烦使用测试,看是否有问题?
我试了您的代码,因为没有 gpio.h ,测试时将 GPIO 和 UART 部分去掉了。
测试未能复现到您的问题。
附件为我编译生成的 bin 文件,麻烦使用测试,看是否有问题?
- Attachments
-
- test_bin.zip
- (156.49 KiB) Downloaded 579 times
Who is online
Users browsing this forum: No registered users and 83 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.