<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=ESP8266_IoT_Firmware</id>
	<title>ESP8266 IoT Firmware - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://w.electrodragon.com/w/index.php?action=history&amp;feed=atom&amp;title=ESP8266_IoT_Firmware"/>
	<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=ESP8266_IoT_Firmware&amp;action=history"/>
	<updated>2026-06-04T22:04:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.2</generator>
	<entry>
		<id>https://w.electrodragon.com/w/index.php?title=ESP8266_IoT_Firmware&amp;diff=28043&amp;oldid=prev</id>
		<title>Chao at 07:30, 17 September 2020</title>
		<link rel="alternate" type="text/html" href="https://w.electrodragon.com/w/index.php?title=ESP8266_IoT_Firmware&amp;diff=28043&amp;oldid=prev"/>
		<updated>2020-09-17T07:30:47Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The following examples based on IoT demo, another example located in SDK examples subfolder, similar to AT demo, but run in a different/advanced way, and it can cooperate with website, devices/phone app, etc in a better way (curl), without additional MCU control. &amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basic function GPIO(relay) control, PWM control (light), sensor (coming soon), lightweight webserver are set in the demo.&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Customizing the IoT demo code to start the secondary development of your little module!&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
* 12/02 Basic setup, json command usage, code about UART output string, os_timer&lt;br /&gt;
* 01/05 add DHT11 demo code&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
* To use the IoT demo, you must already know how to use Lubuntu environment to compile to the application code, our cygwin environment can not correctly compile for now. Also can successfully flash your module.&lt;br /&gt;
=== Change wired password ===&lt;br /&gt;
* Change the password setup in user_esp_platform.c (comment the line of os_sprintf, and add new one instead)and change password at user_config.h (#define PASSWORD	&amp;quot;v*%W&amp;gt;L&amp;lt;@i&amp;amp;Nxe!&amp;quot;)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#ifdef SOFTAP_ENCRYPT&lt;br /&gt;
struct softap_config config;&lt;br /&gt;
char password[33];&lt;br /&gt;
char macaddr[6];&lt;br /&gt;
&lt;br /&gt;
wifi_softap_get_config(&amp;amp;config);&lt;br /&gt;
wifi_get_macaddr(SOFTAP_IF, macaddr);&lt;br /&gt;
&lt;br /&gt;
os_memset(config.password, 0, sizeof(config.password));&lt;br /&gt;
// os_sprintf(password, MACSTR &amp;quot;_%s&amp;quot;, MAC2STR(macaddr), PASSWORD);&lt;br /&gt;
os_sprintf(password, &amp;quot;%s&amp;quot;, PASSWORD); // or os_sprintf(password, &amp;quot;12345678&amp;quot;); to set it directly to 12345678&lt;br /&gt;
os_memcpy(config.password, password, os_strlen(password));&lt;br /&gt;
config.authmode = AUTH_WPA_WPA2_PSK; // can also set this to AUTH_OPEN or others (OPEN、WPAPSK、WPA2PSK、WPAPSK/WPA2PSK)&lt;br /&gt;
&lt;br /&gt;
wifi_softap_set_config(&amp;amp;config);&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Check ===&lt;br /&gt;
* Default module work at softAP, 192.168.4.1&lt;br /&gt;
* Now you can use curl to set the module (can used by android, python, etc), if you are using curl in windows, you should also notice about '''this issue [[Curl]]'''&lt;br /&gt;
* Check the wifi settings on browser with following URL: http://192.168.4.1/config?command=wifi&lt;br /&gt;
[[File:Iot wifi configure.png|400px]]&lt;br /&gt;
&lt;br /&gt;
=== Curl Command ===&lt;br /&gt;
Tool can find at http://curl.haxx.se/download.html, the word ip should be replaced to 192.168.4.1 which is the wifi IP&lt;br /&gt;
* Check version&lt;br /&gt;
 curl -X GET http://ip/client?command=info&lt;br /&gt;
* Set station mode&lt;br /&gt;
 curl -X POST -H Content-Type:application/json -d '{&amp;quot;Request&amp;quot;:{&amp;quot;Station&amp;quot;:{&amp;quot;Connect_Station&amp;quot;:{&amp;quot;ssid&amp;quot;:&amp;quot;tenda&amp;quot;,&amp;quot;password&amp;quot;:&amp;quot;1234567890&amp;quot;,&amp;quot;token&amp;quot;: &amp;quot;1234567890123456789012345678901234567890&amp;quot;}}}}' http://ip/config?command=wifi&lt;br /&gt;
* Set SoftAP mode&lt;br /&gt;
 curl -X POST -H Content-Type:application/json -d '{&amp;quot;Request&amp;quot;:{&amp;quot;Softap&amp;quot;:{&amp;quot;Connect_Softap&amp;quot;:{&amp;quot;authmode&amp;quot;:&amp;quot;OPEN&amp;quot;,&amp;quot;channel&amp;quot;:6,&amp;quot;ssid&amp;quot;:&amp;quot;ESP_IOT_SOFTAP&amp;quot;,&amp;quot;password&amp;quot;:&amp;quot;&amp;quot;}}}}' http://192.168.4.1/config?command=wifi&lt;br /&gt;
&lt;br /&gt;
=== Find device in Ethernet ===&lt;br /&gt;
* Send the following string by UDP to device 192.168.4.1 at port 1025, will receive [[File:Esp8255 device reply.png|thumbnail]] (care the empty space below, and don't chat with it :) )&lt;br /&gt;
* For the pins set please see on [[wi07c]] page&lt;br /&gt;
 Are You Espressif IOT Smart Device?&lt;br /&gt;
Plug&lt;br /&gt;
 I’m Plug.xx:xx:xx:xx:xx:xxyyy.yyy.yyy.yyy&lt;br /&gt;
Light&lt;br /&gt;
 I’m Light.xx:xx:xx:xx:xx:xxyyy.yyy.yyy.yyy&lt;br /&gt;
Sensor&lt;br /&gt;
 I’m Humiture.xx:xx:xx:xx:xx:xxyyy.yyy.yyy.yyy&lt;br /&gt;
xx:xx:xx:xx:xx:xx is mad addr, and yyy.yyy.yyy.yyy is IP addr&lt;br /&gt;
&lt;br /&gt;
=== Devices ===&lt;br /&gt;
Devices set at user_config.h&lt;br /&gt;
 #if ESP_PLATFORM&lt;br /&gt;
 #define PLUG_DEVICE             0&lt;br /&gt;
 #define LIGHT_DEVICE            0&lt;br /&gt;
 #define SENSOR_DEVICE			1&lt;br /&gt;
&lt;br /&gt;
==== Demo ====&lt;br /&gt;
* We use light a example here, data post via chrome plugin called postman, you can also use curl command line&lt;br /&gt;
* Select Json, URL = http://192.168.4.1/config?command=light, use raw data {&amp;quot;freq&amp;quot;:120,&amp;quot;rgb&amp;quot;:{&amp;quot;red&amp;quot;:111,&amp;quot;green&amp;quot;:222,&amp;quot;blue&amp;quot;:119}}&lt;br /&gt;
* Now you open open the URL directly to see the change&lt;br /&gt;
&amp;lt;gallery&amp;gt;&lt;br /&gt;
File:Json_data_post.png|Post the data&lt;br /&gt;
File:Light_data.png| See the effort&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
* [http://youtu.be/CI6qB1suWj8 A demo video available here.] &lt;br /&gt;
==== Plug ====&lt;br /&gt;
Get plug status&lt;br /&gt;
 curl -X GET http://ip/config?command=switch&lt;br /&gt;
Set plug status&lt;br /&gt;
 curl -X POST -H Content-Type:application/json -d '{&amp;quot;Response&amp;quot;:{&amp;quot;status&amp;quot;:1}}' http://ip/config?command=switch&lt;br /&gt;
&lt;br /&gt;
==== Light ====&lt;br /&gt;
Get status&lt;br /&gt;
 curl -X GET http://ip/config?command=light&lt;br /&gt;
Set status&lt;br /&gt;
 curl -X POST -H Content-Type:application/json -d '{&amp;quot;freq&amp;quot;:100,&amp;quot;rgb&amp;quot;:{&amp;quot;red&amp;quot;:200,&amp;quot;green&amp;quot;:0,&amp;quot;blue&amp;quot;:0}}' http://ip/config?command=light&lt;br /&gt;
Frequency 0-500, RGB in 255 range&lt;br /&gt;
&lt;br /&gt;
==== Sensor N/A yet ====&lt;br /&gt;
NA&lt;br /&gt;
&lt;br /&gt;
== Code Customize ==&lt;br /&gt;
=== Basic Timer and Uart output ===&lt;br /&gt;
The following code will set the module to output text string every one second.&lt;br /&gt;
* Set extra UART string output void in '''uart.c''', this is based on current uart tx output void uart0_tx_buffer(uint8 *buf, uint16 len)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void Uart0_Send_Str(uint8 *buf)&lt;br /&gt;
{&lt;br /&gt;
	while(*buf!='\0'){&lt;br /&gt;
		uart0_tx_buffer(buf, 1);&lt;br /&gt;
		buf++;&lt;br /&gt;
		}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Add header in '''uart.h'''&lt;br /&gt;
 void uart0_send_str(uint8 *buf);&lt;br /&gt;
* Add include in '''main.c'''&lt;br /&gt;
 #include &amp;quot;driver/uart.h&amp;quot; // uart output&lt;br /&gt;
 #include &amp;quot;osapi.h&amp;quot; // timer&lt;br /&gt;
 #include &amp;quot;os_type.h&amp;quot; // timer&lt;br /&gt;
* Also some extra definition at the beginning:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
os_timer_t mytimer;&lt;br /&gt;
&lt;br /&gt;
//void uart0_send_str(uint8 *buf); //not necessary line&lt;br /&gt;
&lt;br /&gt;
Send_str(void) // define timer function&lt;br /&gt;
{&lt;br /&gt;
	uart0_send_str(&amp;quot;\r\n Electrodragon \r\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* in the '''void user_init''' (application entry)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
uart_init(BIT_RATE_115200,BIT_RATE_115200); // start the UART&lt;br /&gt;
&lt;br /&gt;
os_timer_disarm(&amp;amp;mytimer); // dis_arm the timer&lt;br /&gt;
os_timer_setfn(&amp;amp;mytimer, (os_timer_func_t *)Send_str, NULL); // set the timer function, dot get os_timer_func_t to force function convert&lt;br /&gt;
os_timer_arm(&amp;amp;mytimer, 1000, 1); // arm the timer, 1000 repeat, repeat always&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GPIO Control ===&lt;br /&gt;
* Reference code in IoT is user_plug.c&lt;br /&gt;
* GPIO16 will be used alone as gpio16.h&lt;br /&gt;
* Set Pin function PIN_FUNC_SELECT(PIN_NAME, FUNC), pi name refer to eagle_soc.h, func for example FUNC_GPIO13&lt;br /&gt;
* GPIO_OUTPUT_SET(gpio_no, bit_value) set gpio_no output bit_value (more simple than gpio_output_set)&lt;br /&gt;
* Basic example&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void My_LED_Init(void)&lt;br /&gt;
{&lt;br /&gt;
    // config GPIO12 13 14 16 as normal GPIO&lt;br /&gt;
 	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12);&lt;br /&gt;
 	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO15);&lt;br /&gt;
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO13);&lt;br /&gt;
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO14);&lt;br /&gt;
       GPIO_OUTPUT_SET(GPIO_ID_PIN(12), 0);&lt;br /&gt;
	GPIO_OUTPUT_SET(GPIO_ID_PIN(13), 0);// default low&lt;br /&gt;
	GPIO_OUTPUT_SET(GPIO_ID_PIN(14), 0);&lt;br /&gt;
	GPIO_OUTPUT_SET(GPIO_ID_PIN(15), 0);&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ADC (DHT11) ===&lt;br /&gt;
* Demo code for DHT11 can be found at this [https://drive.google.com/folderview?id=0B_ctPy0pJuW6Y3BjWDZCczg4Nm8&amp;amp;usp=sharing link]&lt;br /&gt;
* Add code files to app/user, and replace the code entry file user_main.c, will work&lt;br /&gt;
&lt;br /&gt;
=== PWM control ===&lt;br /&gt;
* pwm_init void (see page 61 at [https://drive.google.com/folderview?id=0B3dUKfqzZnlwUWd4b2dGbTBVZHc&amp;amp;usp=drive_web SDK docs])&lt;br /&gt;
* inlclude header  file /driver/pwm.h in user main.c&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U&lt;br /&gt;
#define PWM_0_OUT_IO_NUM 12&lt;br /&gt;
#define PWM_0_OUT_IO_FUNC  FUNC_GPIO12&lt;br /&gt;
&lt;br /&gt;
#define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U&lt;br /&gt;
#define PWM_1_OUT_IO_NUM 15&lt;br /&gt;
#define PWM_1_OUT_IO_FUNC  FUNC_GPIO15&lt;br /&gt;
&lt;br /&gt;
#define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U&lt;br /&gt;
#define PWM_2_OUT_IO_NUM 13&lt;br /&gt;
#define PWM_2_OUT_IO_FUNC  FUNC_GPIO13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Demo code&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
unit8 PWM_CH[]= (0, 0, 0);&lt;br /&gt;
unit16 freq = 1000;&lt;br /&gt;
&lt;br /&gt;
pwm_init(freq, PWM_CH[]);&lt;br /&gt;
&lt;br /&gt;
while(1)&lt;br /&gt;
{&lt;br /&gt;
pwm_set_duty(PWM_CH[2], 0);&lt;br /&gt;
pwm_start();&lt;br /&gt;
PWM_CH[2]+=1;&lt;br /&gt;
if(PWM_CH[2]&amp;gt;99)&lt;br /&gt;
   PWM_CH[2] =0;&lt;br /&gt;
delay_ms(80);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Hardware can use a 4 pins PWM DIP LEDs from our store&lt;br /&gt;
* Hardware wiring:&lt;br /&gt;
[[File:Esp8266 pwm sch.png|300px]]&lt;br /&gt;
&lt;br /&gt;
== Sample code R1 ==&lt;br /&gt;
The task of this sample code&lt;br /&gt;
* The board ESP-01 must switch to STA (Wi-Fi client) to connect to our AP.  &lt;br /&gt;
* Once the connection to the AP, you must install TCP-connection to the PC and send the test string.  &lt;br /&gt;
* GPIO0 connect button for the closure send a text string.  &lt;br /&gt;
* The procedure of sending repeated every 5 seconds. &lt;br /&gt;
Open the file user \ user_main.c &lt;br /&gt;
The basic procedure, which is performed at the start of the firmware is &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
//Init function &lt;br /&gt;
void ICACHE_FLASH_ATTR&lt;br /&gt;
user_init()&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In the beginning of the file user \ user_main.c add header files: &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;ets_sys.h&amp;quot;&lt;br /&gt;
#include &amp;quot;osapi.h&amp;quot;&lt;br /&gt;
#include &amp;quot;os_type.h&amp;quot;&lt;br /&gt;
#include &amp;quot;user_interface.h&amp;quot;&lt;br /&gt;
#include &amp;quot;driver/uart.h&amp;quot;&lt;br /&gt;
#include &amp;quot;espconn.h&amp;quot;&lt;br /&gt;
#include &amp;quot;mem.h&amp;quot;&lt;br /&gt;
#include &amp;quot;gpio.h&amp;quot;&lt;br /&gt;
#include &amp;quot;user_config.h&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Data files, except user_config.h and driver / uart.h are C: \ Espressif \ ESP8266_SDK \ include \ &lt;br /&gt;
* ets_sys.h - particular IP structure and determination to work with events and timers  &lt;br /&gt;
* osapi.h - timers and some system functions such os_strcat, os_memcpy, os_delay_us etc.  &lt;br /&gt;
* os_type.h - mapinga structures of ets_sys.h  &lt;br /&gt;
* user_interface.h - a lot of support structures and procedures API, in particular for working with wi-fi, procedures system_restart, system_deep_sleep etc.  &lt;br /&gt;
* espconn.h - the main file API with structures and procedures for working with TCP and UDP connections  &lt;br /&gt;
* mem.h - work with memory, os_malloc, os_free etc.  &lt;br /&gt;
* gpio.h - support structures and procedures API to work with GPIO&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
   // Start UART at 115200&lt;br /&gt;
    uart_init(BIT_RATE_115200, BIT_RATE_115200);&lt;br /&gt;
    // Wait for 100 ms.&lt;br /&gt;
    os_delay_us(100);&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    // Display the string at the beginning of uart run. See definition in PLATFORM_DEBUG user_config.h&lt;br /&gt;
    uart0_sendStr(&amp;quot;ESP8266 platform starting...\r\n&amp;quot;);&lt;br /&gt;
    #endif&lt;br /&gt;
    // Structure with information about the configuration of STA (in client mode AP)&lt;br /&gt;
    struct station_config stationConfig;&lt;br /&gt;
    char info[150];&lt;br /&gt;
    // Check if the board was not in client mode AP, then translate it in this mode&lt;br /&gt;
    // In the SDK version 0.9.2 below after wifi_set_opmode had to do system_restart&lt;br /&gt;
    if(wifi_get_opmode() != STATION_MODE)&lt;br /&gt;
    {&lt;br /&gt;
        #ifdef PLATFORM_DEBUG&lt;br /&gt;
        uart0_sendStr(&amp;quot;ESP8266 not in STATION mode, restarting in STATION mode...\r\n&amp;quot;);&lt;br /&gt;
        #endif&lt;br /&gt;
        wifi_set_opmode(STATION_MODE);&lt;br /&gt;
    }&lt;br /&gt;
// If the card mode STA, then set the configuration, the name of AP, password, see User_config.h&lt;br /&gt;
// Optional read the MAC address of our card mode AP, see. Wifi_get_macaddr (SOFTAP_IF, macaddr)&lt;br /&gt;
// In the STA in charge will be a different MAC address as the client, but we have to address yourself to read that she had if she had acted as an access point&lt;br /&gt;
    if(wifi_get_opmode() == STATION_MODE)&lt;br /&gt;
    {&lt;br /&gt;
        wifi_station_get_config(&amp;amp;stationConfig);&lt;br /&gt;
        os_memset(stationConfig.ssid, 0, sizeof(stationConfig.ssid));&lt;br /&gt;
        os_memset(stationConfig.password, 0, sizeof(stationConfig.password));&lt;br /&gt;
        os_sprintf(stationConfig.ssid, &amp;quot;%s&amp;quot;, WIFI_CLIENTSSID);&lt;br /&gt;
        os_sprintf(stationConfig.password, &amp;quot;%s&amp;quot;, WIFI_CLIENTPASSWORD);&lt;br /&gt;
        wifi_station_set_config(&amp;amp;stationConfig);&lt;br /&gt;
        wifi_get_macaddr(SOFTAP_IF, macaddr);&lt;br /&gt;
    }&lt;br /&gt;
    // For adjusting the output data in uart mode setup STA&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    if(wifi_get_opmode() == STATION_MODE)&lt;br /&gt;
    {&lt;br /&gt;
        wifi_station_get_config(&amp;amp;stationConfig);&lt;br /&gt;
        os_sprintf(info,&amp;quot;OPMODE: %u, SSID: %s, PASSWORD: %s\r\n&amp;quot;,&lt;br /&gt;
            wifi_get_opmode(),&lt;br /&gt;
            stationConfig.ssid,&lt;br /&gt;
            stationConfig.password);&lt;br /&gt;
        uart0_sendStr(info);&lt;br /&gt;
    }&lt;br /&gt;
    #endif&lt;br /&gt;
     // Start the timer test the connection to Wi-Fi, check the connection every 1 sec., If the connection is established, then run TCP-client and send a test string.&lt;br /&gt;
    os_timer_disarm(&amp;amp;WiFiLinker);&lt;br /&gt;
    os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
    os_timer_arm(&amp;amp;WiFiLinker, 1000, 0);&lt;br /&gt;
    // Initialize GPIO,&lt;br /&gt;
    BtnInit();&lt;br /&gt;
     // Display a message about the successful launch&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    uart0_sendStr(&amp;quot;ESP8266 platform started!\r\n&amp;quot;);&lt;br /&gt;
    #endif&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* GPIO initialization procedure&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void BtnInit() {&lt;br /&gt;
    PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);&lt;br /&gt;
     // Turn off the pull-up resistor - (pull down)&lt;br /&gt;
    PIN_PULLDWN_DIS(PERIPHS_IO_MUX_GPIO0_U);&lt;br /&gt;
     // Turn on the pull-up resistor + (pull up)&lt;br /&gt;
    PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U);  &lt;br /&gt;
     // Translate to enter GPIO0&lt;br /&gt;
    gpio_output_set(0, 0, 0, BIT0);&lt;br /&gt;
     // Start the timer, GPIO test&lt;br /&gt;
    os_timer_disarm(&amp;amp;BtnTimer);&lt;br /&gt;
    os_timer_setfn(&amp;amp;BtnTimer, BtnTimerCb, NULL);&lt;br /&gt;
    os_timer_arm(&amp;amp;BtnTimer, 500, 1);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Verification ===&lt;br /&gt;
The verification procedure is done on the forehead, without any elimination of contact bounce, the mind needs to be done differently, just as will be seen below, that does not go senddata no verification at raising interface wi-fi, that should also be taken into account. &lt;br /&gt;
* The verification procedure GPIO&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void ICACHE_FLASH_ATTR BtnTimerCb(void *arg)&lt;br /&gt;
{&lt;br /&gt;
    if (!GPIO_INPUT_GET(BTNGPIO))&lt;br /&gt;
    {&lt;br /&gt;
        GPIO_Time_Active++;&lt;br /&gt;
    } else {&lt;br /&gt;
        if (GPIO_Time_Active != 0)&lt;br /&gt;
        {&lt;br /&gt;
            #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;Start sending data...\r\n&amp;quot;);&lt;br /&gt;
            #endif&lt;br /&gt;
            // Отправляем данные&lt;br /&gt;
            senddata();&lt;br /&gt;
        }&lt;br /&gt;
        GPIO_Time_Active = 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* The verification procedure Wi-Fi connection (called a timer)&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)&lt;br /&gt;
{&lt;br /&gt;
     // Structure with information about, ip address of the client STA, subnet mask, gateway.&lt;br /&gt;
    struct ip_info ipConfig;&lt;br /&gt;
     // Disable the timer check wi-fi&lt;br /&gt;
    os_timer_disarm(&amp;amp;WiFiLinker);&lt;br /&gt;
     // Get information about network settings&lt;br /&gt;
    wifi_get_ip_info(STATION_IF, &amp;amp;ipConfig);&lt;br /&gt;
     // Check the status of wi-fi connection and the fact of the ip address&lt;br /&gt;
    if (wifi_station_get_connect_status() == STATION_GOT_IP &amp;amp;&amp;amp; ipConfig.ip.addr != 0)&lt;br /&gt;
    {&lt;br /&gt;
         // The compounds of the wi-fi set&lt;br /&gt;
        connState = WIFI_CONNECTED;&lt;br /&gt;
        #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;WiFi connected\r\n&amp;quot;);&lt;br /&gt;
        #endif&lt;br /&gt;
        #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;Start TCP connecting...\r\n&amp;quot;);&lt;br /&gt;
        #endif&lt;br /&gt;
        connState = TCP_CONNECTING;&lt;br /&gt;
         // Send data to the PC&lt;br /&gt;
        senddata();&lt;br /&gt;
         // Start the timer test the connection and send the data already every 5 seconds, see. Teh.zadanie&lt;br /&gt;
        os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
        os_timer_arm(&amp;amp;WiFiLinker, 5000, 0);&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
         // Wrong password&lt;br /&gt;
        if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD)&lt;br /&gt;
        {&lt;br /&gt;
            connState = WIFI_CONNECTING_ERROR;&lt;br /&gt;
            #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;WiFi connecting error, wrong password\r\n&amp;quot;);&lt;br /&gt;
            #endif&lt;br /&gt;
            os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
            os_timer_arm(&amp;amp;WiFiLinker, 1000, 0);&lt;br /&gt;
        }&lt;br /&gt;
         // AP found&lt;br /&gt;
        else if(wifi_station_get_connect_status() == STATION_NO_AP_FOUND)&lt;br /&gt;
        {&lt;br /&gt;
            connState = WIFI_CONNECTING_ERROR;&lt;br /&gt;
            #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;WiFi connecting error, ap not found\r\n&amp;quot;);&lt;br /&gt;
            #endif&lt;br /&gt;
            os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
            os_timer_arm(&amp;amp;WiFiLinker, 1000, 0);&lt;br /&gt;
        }&lt;br /&gt;
         // Error connecting to AP&lt;br /&gt;
        else if(wifi_station_get_connect_status() == STATION_CONNECT_FAIL)&lt;br /&gt;
        {&lt;br /&gt;
            connState = WIFI_CONNECTING_ERROR;&lt;br /&gt;
            #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;WiFi connecting fail\r\n&amp;quot;);&lt;br /&gt;
            #endif&lt;br /&gt;
            os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
            os_timer_arm(&amp;amp;WiFiLinker, 1000, 0);&lt;br /&gt;
        }&lt;br /&gt;
         // Other error&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            os_timer_setfn(&amp;amp;WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);&lt;br /&gt;
            os_timer_arm(&amp;amp;WiFiLinker, 1000, 0);&lt;br /&gt;
            connState = WIFI_CONNECTING;&lt;br /&gt;
            #ifdef PLATFORM_DEBUG&lt;br /&gt;
            uart0_sendStr(&amp;quot;WiFi connecting...\r\n&amp;quot;);&lt;br /&gt;
            #endif&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* The procedure for sending data to the PC&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void ICACHE_FLASH_ATTR&lt;br /&gt;
senddata()&lt;br /&gt;
{&lt;br /&gt;
    char info[150];&lt;br /&gt;
    char tcpserverip[15];&lt;br /&gt;
    struct espconn *pCon = (struct espconn *)os_zalloc(sizeof(struct espconn));&lt;br /&gt;
    if (pCon == NULL)&lt;br /&gt;
    {&lt;br /&gt;
        #ifdef PLATFORM_DEBUG&lt;br /&gt;
        uart0_sendStr(&amp;quot;TCP connect failed\r\n&amp;quot;);&lt;br /&gt;
        #endif&lt;br /&gt;
        return;&lt;br /&gt;
    }&lt;br /&gt;
    pCon-&amp;gt;type = ESPCONN_TCP;&lt;br /&gt;
    pCon-&amp;gt;state = ESPCONN_NONE;&lt;br /&gt;
     // Set address TCP-based server where the data will be send&lt;br /&gt;
    os_sprintf(tcpserverip, &amp;quot;%s&amp;quot;, TCPSERVERIP);&lt;br /&gt;
    uint32_t ip = ipaddr_addr(tcpserverip);&lt;br /&gt;
    pCon-&amp;gt;proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));&lt;br /&gt;
    pCon-&amp;gt;proto.tcp-&amp;gt;local_port = espconn_port();&lt;br /&gt;
     // Set the port TCP-based server, which will send data&lt;br /&gt;
    pCon-&amp;gt;proto.tcp-&amp;gt;remote_port = TCPSERVERPORT;&lt;br /&gt;
    os_memcpy(pCon-&amp;gt;proto.tcp-&amp;gt;remote_ip, &amp;amp;ip, 4);&lt;br /&gt;
     // Register the callback function to be called when the connection is established&lt;br /&gt;
     espconn_regist_connectcb (pCon, at_tcpclient_connect_cb);&lt;br /&gt;
     // You can register a callback function to be called when rekonekte, but we do not need it yet&lt;br /&gt;
     // espconn_regist_reconcb (pCon, at_tcpclient_recon_cb);&lt;br /&gt;
     // Display debugging information&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    os_sprintf(info,&amp;quot;Start espconn_connect to &amp;quot; IPSTR &amp;quot;:%d\r\n&amp;quot;,&lt;br /&gt;
           IP2STR(pCon-&amp;gt;proto.tcp-&amp;gt;remote_ip),&lt;br /&gt;
           pCon-&amp;gt;proto.tcp-&amp;gt;remote_port);&lt;br /&gt;
    uart0_sendStr(info);&lt;br /&gt;
    #endif&lt;br /&gt;
     // Connect to the TCP-server&lt;br /&gt;
    espconn_connect(pCon);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* callback function that is called after the connection&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void ICACHE_FLASH_ATTR&lt;br /&gt;
at_tcpclient_connect_cb(void *arg)&lt;br /&gt;
{&lt;br /&gt;
    struct espconn *pespconn = (struct espconn *)arg;&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    uart0_sendStr(&amp;quot;TCP client connect\r\n&amp;quot;);&lt;br /&gt;
    #endif&lt;br /&gt;
     // Callback function that is called after sending data&lt;br /&gt;
    espconn_regist_sentcb(pespconn, at_tcpclient_sent_cb);&lt;br /&gt;
     // Callback function that is called after disconnection&lt;br /&gt;
    espconn_regist_disconcb(pespconn, at_tcpclient_discon_cb);&lt;br /&gt;
    char payload[128];&lt;br /&gt;
     // Prepare the data string will send the MAC address of ESP8266 in AP mode and add the line ESP8266&lt;br /&gt;
    os_sprintf(payload, MACSTR &amp;quot;,%s\r\n&amp;quot;, MAC2STR(macaddr), &amp;quot;ESP8266&amp;quot;);&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    uart0_sendStr(payload);&lt;br /&gt;
    #endif&lt;br /&gt;
     // Send data&lt;br /&gt;
    espconn_sent(pespconn, payload, strlen(payload));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* callback functions called after sending data when power is removed&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
static void ICACHE_FLASH_ATTR&lt;br /&gt;
at_tcpclient_sent_cb(void *arg) {&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    uart0_sendStr(&amp;quot;Send callback\r\n&amp;quot;);&lt;br /&gt;
    #endif&lt;br /&gt;
     // The data sent, disconnected from the TCP-server&lt;br /&gt;
    struct espconn *pespconn = (struct espconn *)arg;&lt;br /&gt;
    espconn_disconnect(pespconn);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void ICACHE_FLASH_ATTR&lt;br /&gt;
at_tcpclient_discon_cb(void *arg) {&lt;br /&gt;
    struct espconn *pespconn = (struct espconn *)arg;&lt;br /&gt;
     // Disable, frees up memory&lt;br /&gt;
    os_free(pespconn-&amp;gt;proto.tcp);&lt;br /&gt;
    os_free(pespconn);&lt;br /&gt;
    #ifdef PLATFORM_DEBUG&lt;br /&gt;
    uart0_sendStr(&amp;quot;Disconnect callback\r\n&amp;quot;);&lt;br /&gt;
    #endif&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reference == &lt;br /&gt;
* Code reading tool [[source insight]]&lt;br /&gt;
* Environment [[virtualbox]]&lt;br /&gt;
[[Category:ESP8266 SDK Firmware]]&lt;/div&gt;</summary>
		<author><name>Chao</name></author>
	</entry>
</feed>