I first implemented this tiny project with an Arduino Nano and a 3.3v<->5v 'adapter'.
This way I know a set of working AT+commands to accomplish my goal.
I only need a PWM-port, and the ESP8266 should have that, rendering the Arduino redundant, so I thought I'd just 'port' these AT+commands over.
It compiles with the official SDK in the official VM, and flashing works via esptool.py on the VM's host machine:
# Flashing
./esptool.py --port /dev/tty.SLAB_USBtoUART write_flash 0x00000 bin/eagle.app.v6.flash.bin
./esptool.py --port /dev/tty.SLAB_USBtoUART write_flash 0x40000 bin/eagle.app.v6.irom0text.bin
// ARDUINO pseudocode without send, receive() and delay(x000). Only AT
// ESP8266 Wifi stuff
AT+CWJAP=\"The Promised LAN\",\"1234567890\"
AT+CIPMUX=1
AT+CIPSTART=4,\"TCP\",\"192.168.178.29\",5000
// do sending and receiving etc pp
AT+CIPCLOSE=4
AT+CWQAP
// ESP8266 AT-example with extensions from at_{ip,wifi,}Cmd.c
1 #include "ets_sys.h"
2 #include "driver/uart.h"
3 #include "osapi.h"
4 #include "at.h"
5
6 #define sleepms(x) os_delay_us(x*1000);
7
8 extern uint8_t at_wifiMode;
9
10 void user_init(void)
11 {
12
13 uart_init(BIT_RATE_115200, BIT_RATE_115200);
14 sleepms(3000);
15 uart0_sendStr("\r\nsetting wifi mode to stationary\r\n");
16 sleepms(3000);
17 at_init();
18
19 //{"+CWMODE", 7, at_testCmdCwmode, at_queryCmdCwmode, at_setupCmdCwmode, NULL},
20 uart0_sendStr("\r\nset cwmode\r\n");
21 char cwmode[] = "=1\r\n";
22 at_setupCmdCwmode(0, cwmode);
23
24 sleepms(3000);
25 //{"+CWJAP", 6, NULL, at_queryCmdCwjap, at_setupCmdCwjap, NULL},
26 uart0_sendStr("\r\njoin ap\r\n");
27 char cwjap[] = "=\"The Promised LAN\",\"1234567890\"\r\n";
28 at_setupCmdCwjap(5, cwjap);
29
30 sleepms(3000);
31 //{"+CIPMUX", 7, NULL, at_queryCmdCipmux, at_setupCmdCipmux, NULL},
32 uart0_sendStr("\r\nset cipmux\r\n");
33 char cipmux[] = "=1\r\n";
34 at_setupCmdCipmux(0, cipmux);
35
36 sleepms(3000);
37 //{"+CIPSTART", 9, at_testCmdCipstart, NULL, at_setupCmdCipstart, NULL},
38 uart0_sendStr("\r\ncipstart to server\r\n");
39 char cipstart[] = "=4,\"TCP\",\"192.168.178.29\",5000\r\n";
40 at_setupCmdCipstart(0, cipstart);
41
42 sleepms(3000);
43 //{"+CIPCLOSE", 9, at_testCmdCipclose, NULL, at_setupCmdCipclose, at_exeCmdCipclose},
44 uart0_sendStr("\r\ncipclose\r\n");
45 char cipclose[] = "=4\r\n";
46 at_exeCmdCipclose(0, cipclose);
47
48 sleepms(3000);
49 //{"+CWQAP", 6, at_testCmdCwqap, NULL, NULL, at_exeCmdCwqap},
50 //at_exeCmdCwqap(0);
51
52 sleepms(3000);
53 //
54 }
Lets get the the problem! It hangs in line 28.
setting wifi mode to stationary
set cwmode
OK
join ap
The Promised LAN1234567890
# nothing else
I think it freezes somewhere in at_wifiCmd::at_setupCmdCwjap(uint8_t id, char *pPara).
Somewhere after line 380.
350 /**
351 * @brief Setup commad of join to wifi ap.
352 * @param id: commad id number
353 * @param pPara: AT input param
354 * @retval None
355 */
356 void ICACHE_FLASH_ATTR
357 at_setupCmdCwjap(uint8_t id, char *pPara)
358 {
359 char temp[64];
360 struct station_config stationConf;
361
362 int8_t len;
363
364 if (at_wifiMode == SOFTAP_MODE)
365 {
366 at_backError;
367 return;
368 }
369 pPara++;
370 len = at_dataStrCpy(&stationConf.ssid, pPara, 32);
371 uart0_sendStr(stationConf.ssid);
372 if(len != -1)
373 {
374 pPara += (len+3);
375 len = at_dataStrCpy(&stationConf.password, pPara, 64);
376 }
377 uart0_sendStr(stationConf.password); // THIS WAS STILL PRINTED TO UART
378 if(len != -1)
379 {
380 wifi_station_disconnect();
381 mdState = m_wdact;
382 ETS_UART_INTR_DISABLE();
383 wifi_station_set_config(&stationConf);
384 ETS_UART_INTR_ENABLE();
385 wifi_station_connect();
386 // if(1)
387 // {
388 // mdState = m_wact;
389 // }
390 // os_sprintf(temp,"%s:%s,%s\r\n",
391 // at_fun[id].at_cmdName,
392 // stationConf.ssid,
393 // stationConf.password);
394 // uart0_sendStr(temp);
395 os_timer_disarm(&at_japDelayChack);
396 os_timer_setfn(&at_japDelayChack, (os_timer_func_t *)at_japChack, NULL);
397 os_timer_arm(&at_japDelayChack, 3000, 0);
398 specialAtState = FALSE;
399 }
400 else
401 {
402 at_backError;
403 }
404 }
Does anybody know what's going on here to cause the 'AT+CWJAP' to freeze? Setting the mode to 2 gets answered with OK.
edit october 28 22:04:
more details: wifi_station_disconnect() and wifi_station_connect() are blocking calls and nothing goes on. This seems to be a dead end. Is there anywhere a piece of code which explains the whole process a bit better maybe?