A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By chris
#1994 Hi,

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:

Code: Select all# 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



Code: Select all 
// 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


Code: Select all// 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?
User avatar
By chris
#2066 Hello,

I took inspiration from Sprite_tm. Code now uses callbacks, not that silly direct calling.
Can post it if anybody is interested. (EDIT: attached to this post now)

New problems are all about PWM and servo-control. I wanna use GPIO0 to control a RC servo.
The following code drives the servo to one out of two positions, depending on a variable fetched from a server.

*Starting the ESP8266 with a servo attached prevents it from booting at all.
*If attached later after booting, right after driving to the correct, assigned position, the servo begins drifting annoyingly.

My code base is still the AT-example, so my current suspicion is that something still uses GPIO0 for other work. I cannot find anything though.
It is not the UART1, commenting its initialization did not help the servo drift.

Alternatively a solution against the drift could be pulling the GPIO0 low. Works well with Arduinos. Didnt get it to work with "gpio_output_set (0, GPIO_ID_PIN(0), GPIO_ID_PIN(0), 0);" probably again some other code interfering with the GPIO0's state.

Cheers,
Chris

Code: Select all...
// inspired by the light example in IoT_Demo example
#include "driver/pwm.h"

struct servo_param {
   uint16_t pwm_freq;
   uint8 pwm_duty[PWM_CHANNEL];
   uint8 pad[6-PWM_CHANNEL];
} servo_param;

void user_init(void) {
   uart_init(BIT_RATE_115200, BIT_RATE_115200);

   servo_param.pwm_freq = 50; // my servo's freq
   servo_param.pwm_duty[0] = 19; // trial and error: 90 degrees servo position
   servo_param.pwm_duty[1] = 0;
   servo_param.pwm_duty[2] = 0;
        pwm_init(servo_param.pwm_freq, servo_param.pwm_duty);
}

/*
 * called if a tcp client receives anything (over a mux'ed connection)
 */
void my_receiver(char* pdata, unsigned short len) {
   if (len != 1 || pdata == NULL) {
      // something went wrong, expecting either char '0' or char '1'
   }
   char position = *pdata;
   os_printf("Received position %c\n", position);
   if (position == '0') {
      servo_param.pwm_duty[0] = 23; // somewhere to the left-position
   } else if (position == '1') {
      servo_param.pwm_duty[0] = 12; // somewhere to the right-position
   }
   pwm_set_freq(servo_param.pwm_freq);
   pwm_set_duty(servo_param.pwm_duty[0], 0);

   os_printf("Set PWM %d to freq=%d and duty=%d.", 0, servo_param.pwm_freq, servo_param.pwm_duty[0]);
}

void loop(void) {
....
}


EDIT: attached current code.
You do not have the required permissions to view the files attached to this post.
Last edited by chris on Mon Nov 03, 2014 8:22 am, edited 1 time in total.
User avatar
By mharizanov
#2129
*Starting the ESP8266 with a servo attached prevents it from booting at all.
*If attached later after booting, right after driving to the correct, assigned position, the servo begins drifting annoyingly.


GPIO0 held low (i.e. ground or below 0.7V) will make the module boot in firmware update mode.

I've been experiencing the same with a 3V SSR relay on GPIO2 and not able to find the reason why it won't boot when the relay is connected, works just fine if I connect it after boot.
User avatar
By chris
#2204 Maybe we should try to solder a thin wire to one of the unused GPIOs of the ESP8266 directly? Has there been work done already?
I just found a thread about the ADC. Gotta do more research about this topic.