2015年8月21日星期五

ESP8266 Extend AT command set - Part1

I need to try their SDK example first in order to extend the AT command set.

1) Download the required tools
  a) Download the Lubuntu VirtualBox image which is provided by Espressif.
     (Provide compiler tool-chain already)
  b) Download the latest SDK.
  c) Download the FLASH programming tools. (For Windows)

2) According to the readme file, copy the SDK to the share folder.
e.g. Place in D:\Share
After that, setup the share folder path in VirtualBox (D:\Share <-> Share).
VBoxImage default username: esp8266
VBoxImage default password: espressif
{SDK} means ~/Share/esp_iot_sdk_v1.3.0

3) Copy {SDK}/examples/at/  to  {SDK}/app/

4) In {SDK}/app/user/user_main.c
modify to
void ICACHE_FLASH_ATTR
at_testCmdTest(uint8_t id)
{
    uint8 buffer[32] = {0};

    os_sprintf(buffer, "%s\r\n", "my at_testCmdTest");
    at_port_print(buffer);
    at_response_ok();
}

4) cd {SDK}/app/

5) ./gen_misc.sh
Select below options:
boot_v1.2+
user1.bin
spi speed: default
spi mode: default
spi size and map: 1024KB( 512KB+ 512KB)

6) Download the user1.1024.new.?.bin to the FLASH ---> 0x1000


7) Try to run AT+TEST=? in CuteCOM.
it should return my at_testCmdTest.

ESP8266 - A Great Product

In ESP8266 SDK,
Something that interests me:
1) Support RTC.
2) SDK provides several functions to get the time using SNTP protocol.
3) Support SSL (Only allow single client connection only)
The default value of maximum SSL packet size is 2KB.
The maximum size packet can be adjusted.

It is good enough for a single IOT SOC chip (Just HKD 12)...

Then, focus on the SSL, found one more interesting thing...
Someone lists out the object symbols in his blog:)
http://41j.com/blog/2015/01/esp8266-sdk-library-symbols/

Many standardized cryptography algorithms (RSA, SHA1, MD5, AES..) have already provided in the object library files,
but they are not explicitly exposed by the vendor.

In other words, once we disassemble the code,
and trace how the parameters passed in these functions (XTENSA ABI).
Actually, it is not necessary to re-implement the cryptography function (greatly reduce the code size).

ESP8266 Initial Test

The module I use:  ESP-8266 ESP-01

1) Wire Connection
Since the USB to UART TTL module may not provide sufficient power for ESP-01,
use external power supply is recommended.

3.3V <-> ESP8266 VCC
3.3V <-> ESP8266 CH_PD
USB to UART TTL module RX <-> ESP8266 TX
USB to UART TTL module TX <-> ESP8266 RX
GND <-> USB to UART TTL module GND <-> ESP8266 GND

*: GPIO0 should be connected to GND if we want to update the firmware. Reboot is required before update.
For general purpose, GPIO0 can be float.

==========================================

2) Testing

In Linux environment, CuteCOM is recommended for testing the communication.

Below is the setup procedures:

Device: /dev/ttyUSB0
Baud rate: 115200
Data bits: 8
Stop bits: 1
Parity: None
Handshake: uncheck both
linefeed: default should be set to CR LF (sometimes you need to switch to use HEX Input format e.g. send raw byte)

Open the COM port and listen the response.
reboot the ESP-01 module.
It should return [Ready] string.

P.S.:
Please update to the latest firmware before use:
The latest firmware uses 115200, 8N1, AT COMMAND LINE END - CR LF for communication.
Before update the firmware, we need to download the SDK and the FLASH PROGRAMMING TOOLS first.

More details can be found in SDK documentation.



In CuteCOM, enter the following commands.
Input AT
response OK means success.

Input AT+CWMODE=1
For STATION MODE only . (3=STATION MODE+ SOFTAP MODE)

Input AT+CWLAP
List available access point.

============================================

3) NTP Client Implementation

Get current time stamp using NTP

#RESET
AT+RST

#GET FIRMWARE VER
#AT+GMR

#SET TO STATION MODE
AT+CWMODE=1

#LIST AP
AT+CWLAP

#CONNECT ACCESS POINT
AT+CWJAP="SSID","Password"

#MAKE CONNECTION.
#參考自:https://github.com/sandeepmistry ... lient/NTPClient.ino
#Other NTP Server might not work...
AT+CIPSTART="UDP","129.6.15.28",123

#SEND NTP PACKET
AT+CIPSEND=48

IN CuteCOM, change to HEX input.
Input the following:
E30006EC0000000000000000314E31340000000000000000000000000000000000000000000000000000000000000000

It should return 48 bytes packet.