Liveware problem connecting to an AP in C.
Posted: Wed Apr 22, 2015 12:49 pm
Hello and thank you all for this wonderful community.
I have been trying to make some code for connecting to an AP. The initial plan was, connect to a configured network, if not create a SoftAP, and present a configuration page.
This went well, until I realised that my code for connecting to the AP did not work. When I use my code for, it fails when I call "wifi_station_connect", then the autoconnect feature connects without complaining.
The full code is at github https://github.com/deadbok/WIFISwitch, but I have tried putting everything in user_init() without success. If I turn off autoconnect, the code newer connects.
user_main.c:
output:
i am pretty certain, that there's something obvious I'm am missing, and I think code, much like this worked when I started. I hope somebody can tell me what I am doing wrong.
Thank you
/Martin
I have been trying to make some code for connecting to an AP. The initial plan was, connect to a configured network, if not create a SoftAP, and present a configuration page.
This went well, until I realised that my code for connecting to the AP did not work. When I use my code for, it fails when I call "wifi_station_connect", then the autoconnect feature connects without complaining.
The full code is at github https://github.com/deadbok/WIFISwitch, but I have tried putting everything in user_init() without success. If I turn off autoconnect, the code newer connects.
user_main.c:
Code: Select all
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
os_event_t user_procTaskQueue[user_procTaskQueueLen];
static void wifi_status(os_event_t *events);
static volatile os_timer_t some_timer;
void some_timerfunc(void *arg)
{
os_printf("Connections status: %d\n", wifi_station_get_connect_status());
}
/* Main entry point.
*/
void ICACHE_FLASH_ATTR user_init()
{
unsigned char connection_status;
struct station_config station_conf = { "default", "password", 0, "000000"};
wifi_set_opmode(STATION_MODE);
//Turn on auto connect.
wifi_station_set_auto_connect(true);
// Set baud rate of debug port
uart_div_modify(0,UART_CLK_FREQ / 115200);
os_delay_us(1000);
//Print banner
os_printf("\nWIFISwitch version %s.\n", STRING_VERSION);
system_print_meminfo();
os_printf("Free heap %u\n", system_get_free_heap_size());
os_printf("\n\n\n\n");
//Disarm timer
os_timer_disarm(&some_timer);
//Setup timer
os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
//Arm the timer
os_timer_arm(&some_timer, 500, 1);
if (!wifi_station_set_config(&station_conf))
{
os_printf("Failed to set station configuration.\n");
}
if (!wifi_station_connect())
{
os_printf("Main: Failed to connect to AP.\n");
}
}
output:
Code: Select all
WIFISwitch version 0.0.1.
data : 0x3ffe8000 ~ 0x3ffe89f8, len: 2552
rodata: 0x3ffe8a00 ~ 0x3ffe8f2c, len: 1324
bss : 0x3ffe8f30 ~ 0x3fff1970, len: 35392
heap : 0x3fff1970 ~ 0x3fffc000, len: 42640
Free heap 42368
Main: Failed to connect to AP.
mode : sta(18:fe:34:9f:85:1e)
add if0
scandone
Connections status: 1
Connections status: 1
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
connected with default, channel 1
dhcp client start...
Connections status: 1
Connections status: 1
Connections status: 1
Connections status: 1
Connections status: 1
ip:192.168.0.30,mask:255.255.255.0,gw:192.168.0.1
Connections status: 5
i am pretty certain, that there's something obvious I'm am missing, and I think code, much like this worked when I started. I hope somebody can tell me what I am doing wrong.
Thank you
/Martin