自己修改的esp8266固件的只能smartconfig一次

pass1876
Posts: 1
Joined: Mon Feb 13, 2017 4:02 pm

自己修改的esp8266固件的只能smartconfig一次

Postby pass1876 » Mon Feb 13, 2017 4:20 pm

使用官方例程中关于SmartConfig的代码,每次上电都要配置,不能保存,自己修改了一下。结果只能保存一个路由器,更换路由器后不能smartconfig成功。

void ICACHE_FLASH_ATTR wifi_event_handler_cb(System_Event_t * event)
{
uint8 loop = 0;
static uint8 status = EVENT_MAX;
if(event == NULL) {
return;
}
switch(event->event) {
case EVENT_SOFTAPMODE_STACONNECTED:
os_printf("EVENT_SOFTAPMODE_STACONNECTED\r\n"); // station connected
break;
case EVENT_SOFTAPMODE_STADISCONNECTED:
os_printf("EVENT_SOFTAPMODE_STADISCONNECTED\r\n"); // station disconnected
break;
default:
break;
}
}

void ICACHE_FLASH_ATTR
smartconfig_done(sc_status status, void *pdata)
{
switch(status) {
case SC_STATUS_WAIT:
os_printf("SC_STATUS_WAIT\n");
break;
case SC_STATUS_FIND_CHANNEL:
os_printf("SC_STATUS_FIND_CHANNEL\n");
break;
case SC_STATUS_GETTING_SSID_PSWD:
os_printf("SC_STATUS_GETTING_SSID_PSWD\n");
sc_type *type = pdata;
break;
case SC_STATUS_LINK:
os_printf("SC_STATUS_LINK\n");
wifi_station_disconnect();
wifi_station_connect();
struct station_config *sta_conf = pdata;
os_memcpy(s_staconf.ssid,(*sta_conf).ssid,os_strlen((*sta_conf).ssid));
wifi_station_set_config(&s_staconf);
break;
case SC_STATUS_LINK_OVER:
os_printf("SC_STATUS_LINK_OVER\n");
uint8 phone_ip[4] = {0};
os_memcpy(phone_ip, (uint8*)pdata, 4);
os_printf("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]);
smartconfig_stop();

break;

}

}

/******************************************************************************
* FunctionName : scan_done
* Description : scan done callback
* Parameters : arg: contain the aps information;
status: scan over status
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
scan_done(void *arg, STATUS status)
{
uint8 ssid[33];
char temp[128];

if (status == OK)
{
struct bss_info *bss_link = (struct bss_info *)arg;
bss_link = bss_link->next.stqe_next;//ignore the first one , it's invalid.

while (bss_link != NULL)
{
os_memset(ssid, 0, 33);
if (os_strlen(bss_link->ssid) <= 32)
{
os_memcpy(ssid, bss_link->ssid, os_strlen(bss_link->ssid));
}
else
{
os_memcpy(ssid, bss_link->ssid, 32);
}
os_printf("(%d,\"%s\",%d,\""MACSTR"\",%d)\r\n",
bss_link->authmode, ssid, bss_link->rssi,
MAC2STR(bss_link->bssid),bss_link->channel);
bss_link = bss_link->next.stqe_next;
}
}
else
{
os_printf("scan fail !!!\r\n");
}

}

void ICACHE_FLASH_ATTR
user_scan(void)
{
struct scan_config config;
os_memset(&config, 0, sizeof(config));
config.ssid = s_staconf.ssid;
wifi_station_scan(&config,scan_done);
}


void user_init(void)
{
uart_init(115200);
wifi_set_opmode(STATION_MODE);
wifi_station_get_config_default(&s_staconf);
if(os_strlen(s_staconf.ssid) != 0)
{
os_printf("user_scan\r\n");
system_init_done_cb(user_scan);
}
else
{
os_printf("smart_cfg\r\n");
smartconfig_set_type(SC_TYPE_ESPTOUCH); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
smartconfig_start(smartconfig_done);

//wifi_station_set_config(&s_staconf);
}
wifi_set_event_handler_cb(wifi_event_handler_cb); // monitor wifi state
system_os_task(trans_task, TRANS_TASK_PROI, trans_Queue, TRANS_QUEUE_LEN); // create a task that processes transparently transmitting data

// create tcp server
pTcpServer = (struct espconn *)os_zalloc((uint32)sizeof(struct espconn));

if (pTcpServer == NULL)
{
os_printf("TcpServer Failure\r\n");
return;
}

pTcpServer->type = ESPCONN_TCP;
pTcpServer->state = ESPCONN_NONE;
pTcpServer->proto.tcp = (esp_tcp *)os_zalloc((uint32)sizeof(esp_tcp));
pTcpServer->proto.tcp->local_port = 12000; // server port
espconn_regist_connectcb(pTcpServer, trans_server_listen);
espconn_accept(pTcpServer);
espconn_regist_time(pTcpServer, 180, 0);

os_timer_disarm(&trans_interval_timer);
os_timer_setfn(&trans_interval_timer, (os_timer_func_t *)transmit_data, NULL);

}

Her Majesty
Posts: 102
Joined: Mon Oct 27, 2014 11:09 am

Re: 自己修改的esp8266固件的只能smartconfig一次

Postby Her Majesty » Sun Mar 19, 2017 1:55 pm

更换路由器之后,会去 smartconfig 吗?

Code: Select all

wifi_station_get_config_default(&s_staconf);
if(os_strlen(s_staconf.ssid) != 0)
{
os_printf("user_scan\r\n");   
system_init_done_cb(user_scan);
}

成功连接过路由器之后,这个 if 条件应该会始终成立吧,是不是每次都走 user_scan 了

Who is online

Users browsing this forum: Bing [Bot] and 2 guests