Lexin esp8266 learning rtos3.0 first six notes: esp8266-12 module based rtos3.1 ota version features remote firmware upgrade the air, on the official website domain name resolution dns increase! (With demo)

Disclaimer: This article is a blogger and a half stars heart bent on a blood knock out original works, shall not be reproduced without the bloggers allowed, Thanks for your support. https://blog.csdn.net/xh870189248/article/details/90079984

  • This series of blog study by the non-official and a half stars heart painstaking written by force, just do personal technology exchange and sharing, without any commercial purposes. If wrong, please leave a message, I promptly changed.

1, Esp8266 the development environment to build, start a "hellow world" serial printer. 2, started using GPIO Esp8266 the button to light your "first lamp." 3, the use Esp8266 "software timers," 0.5 seconds flashing timing of the lighting an LED. 4, Esp8266 understanding of the PWM, the PWM control in more depth with a change in luminance of the LED. Native 5, Esp8266 the advanced use of Lexin SDK package Post and Get requests clouds, got the "weather forecast information." 6, Esp8266 of understanding SmartConfig and Airkiss a key distribution network, to 8266 with the Internet cloud. Wifi without having to write code in the firmware in the name. 7, Esp8266 of understanding softAP hot spot distribution network mode principle, imitation "witty cloud" to define your own distribution network hotspot mode protocol. 8, Esp8266 you're looking for 8266 as of UDP, TCP client or server roles communications, in which the. 9, Esp8266 advanced Road Part 1: [Part small combat] the Windows system set Mqtt local server 8266, an LED lamp lighting LAN. 10, Esp8266 advanced Road Section 2: [next small combat] the Windows system set Mqtt local server 8266, an LED lamp lighting LAN. 11, Esp8266 advanced The Way 3: 8266 intelligent access Ali lit a LED light, look Lynx wizard voice control does not come to the party! 12, Esp8266 advanced Way to 4: illustrations learning to build 8266MQTT Ali cloud host server, for mobile network remote control an LED. 13, Esp8266 advanced Way to 5:











8266 set to be a complete hands-on small cases, smartConfig + MQTT agreement easy remote control of an LED.
14, Esp8266 advanced Way to 6: FreeRTOS system esp8266 learning the correct posture ------ environment to build, burn.
15, Esp8266 advanced road of 7: Things esp8266 yet clear stream, 8266 aliyun internet access non Ali SDS intelligent service, lighting an LED.
16, Esp8266 advanced Road Chapter 8: esp8266 based graft Nonos infrared H1838, to achieve infrared remote distribution network, a remote control light.
17, Esp8266 advanced Way to 9: Fast power switching five esp8266 self-development (as a switch), no buttons to trigger the 8266 into a key distribution network mode. 18, Esp8266 advanced Way to 10: esp8266 based NONOS achieve remote OTA upgrade, wireless "hot fix" to upgrade the firmware. 19, Esp8266 advanced on the road 11 : esp8266 drive ds18b20, dht11 temperature and humidity sensors, temperature and humidity sensors to collect server. 20, Esp8266 advanced Way to 12 : in-depth study of esp now esp8266 mode, do a little imitation wit cloud gateway, for easy connection to each other without the need for interactive data communications network. 21, Esp8266 advanced Way to 13 : On esp8266 how to achieve maximum efficiency and front-end data exchange in the local LAN network conditions.




22, Esp8266 advanced Way to 14 : esp8266 project How to add third-party static library files, and how to customize a folder, makeFile talk about those things. .
23, Esp8266 advanced Way to 15 : coming wave of esp8266 based freeRtos own private system connects remote server implementation OTA upgrade, contact with the basic knowledge under lwip. .
24, Esp8266 advanced Way to 16 : penetration study under review esp8266 external spi chip 25q series, the familiar 8266 block of code in its distribution, and handy place images or other information.
25, Esp8266 advanced Way to 17 : deep chat under esp8266 Uart serial communications interrupt programming for the serial port driver you are ready to file NONOS version and RTOS systems.
26, Esp8266 advanced Way to 18 : RTOS analysis MQTT implementation process to achieve transplantation MQTT agreement esp8266 rtos real-time system, may reconnection.
27, Esp8266 advanced Way to 19 : stick with the pace of development esp8266 rtos SDK v3.0 version with VisualStudio Code, idf new framework, saving memory modular development.
28, Esp8266 advanced Way to 20 : teach you how to parse the ease of use cJson some json data and how to generate some json data Lexin esp8266.
29, Esp8266 advanced Way to 21: Millions of messages free of Lexin esp8266 direct mode using the TCP protocol access MQTT Ali cloud Things platform to support private servers more support aliyun rules engine.
30, Esp8266 advanced Way to 22 : Lexin esp8266 SDK programming using IIC bus driver 0.96-inch OLED screen, display the weather forecast information.
31, Esp8266 advanced Way to 23 : When esp8266 encountered Html, how the built-in web control equipment, built-in web pages to sort out the implementation process, and to achieve do not need a router mobile phones can also be controlled esp8266.
32, Esp8266 advanced Way to 24 : small talk brings security encryption methods HmacMD5 and practice on esp8266, security of information transmission process of maximum protection.
33, Esp8266 advanced The Way 25 : How to gracefully like Lexin original package logical thinking esp8266 bottom register, make your own static library library files, let people use a third party?
34, Esp8266 advanced on the road 26 : Lexin esp8266 NONOS SDK 3.0-based programming using the SPI driver chip eight digital Max7219, date information is displayed.
35, Esp8266 advanced Way to 27 : Lexin esp8266 chip With wit cloud platform to do a commercial RGB bulb colorful adjustable overall program projects a bright eye-catching tall yet.
36, Esp8266 learning rtos3.0 notes the first one :Understanding esp8266 Rtos 3.0 sdk engineering structures, how esp8266 close to esp-idf project, how to customize the header files compiled?
37, Esp8266 learning rtos3.0 notes of the two : you're looking at here are the basic peripheral functions, including Gpio, Pwm and Uart interface.
38, Esp8266 learning rtos3.0 first three notes : An article with you fixed up understanding and use of storage technology NVS, how to use NVS save integers, strings, arrays and structures.
39, Esp8266 learning rtos3.0 first four notes : take your stroke micro-channel public number distribution network of smart devices esp8266 a stroke on the market and the process of binding equipment, and successfully transplanted in esp8266 rtos3.1 sdk.
40, Esp8266 learning rtos3.0 first five notes : Based Lexin idf framework, study trade surplus stable, dropped reconnect to solve Mqtt frame memory leak problem! Support esp8266 and esp32!
41, Esp8266 learning rtos3.0 first six notes : esp8266-12 module based rtos3.1 ota version features remote firmware upgrade the air, increasing the net on the basis of official dns name resolution!


  • A lot of people learn how to contact me with progress, the following notice and make a small dry goods free Share:

Fun esp8266with you fly, plus group paid QQgroup, to raise the threshold, do not like do not spray friends do not add: 434 878 850
esp8266 Free Source Code Learning Summary (continuously updated, welcomed the Star): https://github.com/xuhongv/StudyInEsp8266
esp32 free source Code learning summary (continuously updated, welcomed the Star): https://github.com/xuhongv/StudyInEsp32


I. Introduction;


     On the road of life, there are many crossroads, and most importantly, it probably twelve. This is what I recently read "Teacher, good" in the movie a classic lines. When the second Lexin was invited to work, my heart is the vitality of blood. But because of their environment and their own personal reasons, I had to give up this invitation. Since it gave up the idea, then they would have It well good current work, to think of life after one day, I also have confidence in the courage to live up to the decision to start the year.


     When are surrounded by good people, you have to be infected! They accept new things, strong hands, solid foundation, good thinking! Big companies are small companies need talent, so why recruitment of highly educated people! Most questions qq group, so I had to reflect on a current problem: not good at thinking, this is a learning instill the idea! How to solve technical problems? Take my group of friends qq group inside of it, like he took up a project to run, more problems are: failure to compile, run barrier, connection to the server was unsuccessful! Such problems are generally is not a solid foundation!


     "Predecessors trees descendants cool", I GitHub or in this blog inside, put a lot of code, the text inside the column are put up my hand to run generalist, which is the predecessor trees! But the descendants cool, you need a sound man, can build a good basic environment, the overall understanding of the difference between each version of the SDK, the most basic is to have a single-chip Start Basics!


     In general, advised those already employed college students or friends, in the development of microcontroller no matter what the issue, the first time to see chip log print information analysis, this log can be analyzed in the vast majority of what the problem is they are so The phenomenon! Including JavaScript applet I contacted, Android development app, php server docking Lynx elves are like to play log, debugging constantly thinking where the problem! This is as a standard programmer skills!


     Finally, say, that we will ask questions, be sure to explain the current hardware environment, sdk version, code, screenshots, explain the phenomenon, log print information! Question tone-friendly! No matter where this questioning, never let him feel your studious attitude.

Here Insert Picture Description


Second, understanding flash distribution;


     The following discussion is based on support for the partition ota not single factory app;


     In 3.0the version, esp32and esp8266the distribution of memory are the same, so they took our esp8266-12fmodule, the following picture, we say under layers (all hand-written, non-translated from):


  1. As mentioned earlier, the NVSstorage mechanism Lexin self-development of database-like flash technique, its position you can see below!
  2. PartitionTable It is the partition table, which literally means the position of custom applications written for each user.
  3. pyh_initRf radio frequency is related to the!
  4. coredump It is abnormal when the program running out to save log location information, the mentioned how in esp32, currently in esp8266 is not mentioned;
  5. ota-0And ota-1everyone should read to understand is the upgraded 2 program location.
  6. factory app Burning is the first time the location of the user program!
  7. not useIs part did not use, you can store your own things here, such as font!

Here Insert Picture Description


     In addition there are several points I need to add is:

  • 这个分区并不是一味不变的,大家可以自定义的。换句话说,我可以自定义存储位置以及其存储大小,一般对于初学者来说别修改,否则会让你的程序跑不起来的!默认的采用分区文件是在:ESP8266_RTOS_SDK/components/partition_table/partitions_two_ota.csv

  • 这个存储的地方在哪里的呢?当有人问你的时候,别说存储在 esp8266芯片里面的,其实是在 它接的一个 flash 芯片上的,比如下面的 25q32 ;

  • not use部分的存储可以在代码读取出来,同样地,我们也可以通过 espTools 提供的工具把 数据转存为 NVS 数据格式存储在 NVS 位置,这个我以后会提到!

Here Insert Picture Description


三、配置好远程固件下载的信息;


第一步:拷贝一份官方示范到自己的文件夹;


     为什么要拷贝一份官方示范?因为我不喜欢动官方的源码,一方面为了对比自己后面修改的代码,二是可以直接pull官方最新的代码不发生冲突!这是我个人习惯!或者你直接进去其文件夹配置就好了,我的是基于 rtos3.1版本的,其路径是:

..\ESP8266_RTOS_SDK\examples\system\ota

第二步:切进去修改远程的文件配置等;


     切进去后 make menuconfig , 找到 Example Configuration,其每项如下所示,具体输入看实际而定!

     注意:如果你是直接使用官网的代码,下面的服务器地址只能是ip地址,如果你是用我下面提供的,必须是域名哈!

Here Insert Picture Description


四、配置好芯片信息;


     esp8266 的ota 不管在 哪个 SDK 版本,都是需要配置芯片信息的,3.0版本之前是在Makefile文件配置,但是 3.0 之后是在 shell 窗口打开make menuconfig 配置的!操作如下动态图所示:

 -->Partition Table
    --> Partition Table (选择第二个表示支持ota,采用默认的分区) 
      --> Partition Table Offset set (输入0x8000就是上面说的分区表位置)

Here Insert Picture Description


  • 注意看我的 烧录配置,尤其注意flash设置为 2MB !

Here Insert Picture Description


五、升级过程概述;


     这部分没啥好讲的,和 2.0 那些代码过程都是一样的!下面贴出我之前写的 一个博文链接,可以加深理解其过程:https://blog.csdn.net/xh870189248/article/details/80095139

Here Insert Picture Description


六、部分代码概述;


  • 为了区分其固件版本,我加了一个宏表示当前版本定义,下面表示是 1.0 版本 :
#define  FW   "V1.0"

  • 在官网的基础上,我并没修改什么代码,仅仅加了下面的dns解析我们的域名:

static int connect_to_http_server()
{
    ESP_LOGI(TAG, "Server IP: %s Server Port:%d", EXAMPLE_SERVER_IP, EXAMPLE_SERVER_PORT);
    int ret;
    struct addrinfo hints, *addr_list, *cur;
    struct sockaddr_in serverAddr;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC; // Allow IPv4 or IPv6
    hints.ai_flags = 0;
    hints.ai_protocol = 0;
    hints.ai_socktype = SOCK_STREAM;
    
    //域名解析得到ip地址
    ret = getaddrinfo(EXAMPLE_SERVER_IP, NULL, &hints, &addr_list);
    
    if (ret != 0)
    {
        printf("DNS parsing failed!\r\n");
        return -1;
    }

    for (cur = addr_list; cur != NULL; cur = cur->ai_next)
    {
        char ip[128];
        inet_ntop(AF_INET, &(((struct sockaddr_in *)cur->ai_addr)->sin_addr), ip, 128);
        printf("DNS IP: %s  \r\n", ip);
        socket_id = socket(AF_INET, SOCK_STREAM, 0); // 创建套接字描述符
        if (socket_id < 0)
        {
            ret = -1;
            printf("socket created failed!\r\n");
            continue;
        }
        bzero(&serverAddr, sizeof(struct sockaddr_in)); // 清零
        serverAddr.sin_family = AF_INET;
        //这个是设置ip地址
        serverAddr.sin_addr.s_addr = inet_addr((const char *)ip);
        //serverAddr.sin_addr.s_addr = inet_addr((const char*)("192.168.1.124"));
        serverAddr.sin_port = htons(EXAMPLE_SERVER_PORT); 

        if (connect(socket_id, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) == 0)
        {
            printf("connect server success!\r\n");
            ret = 0;
            break;
        }else  {
            printf("error = %d\r\n", errno); // #define EHOSTUNREACH 113 // No route to host 无法路由到主机
        }
        close(socket_id);
        ret = -1;
    }
    if (cur == NULL)
        ret = -1;
    freeaddrinfo(addr_list);
    return ret;
}


  • 我们在程序入口加如打印当前的版本:
    //打印版本
    ESP_LOGI(TAG, "Version : %s", FW);

七、其他;


7.1 注意事项;


  1. 每次手动烧录固件,请先make erase_flash,因为这样可以清除所有的信息,保证程序读取是在 factory app 区域!再烧录make flash
  2. 确保你的服务器上的固件地址正常访问,是http 请求访问,不是 https 哈!!!
  3. 为了区分是否正确ota升级,先修改下固件版本,比如v1.1,放去服务器,再修改低版本的通过本地烧录到硬件去。
  4. 放到服务器的固件本地位置是在编译后的 build文件夹下的ota.bin文件哈!
  • 很多人怎么联系我一起学习进步,下面打个小小公告和干货无偿分享:

玩转esp8266带你飞、加群付费QQ群,提高门槛,干货多多,不喜的朋友勿喷勿加:434878850
esp8266源代码免费学习汇总(持续更新,欢迎star):https://github.com/xuhongv/StudyInEsp8266
esp32源代码免费学习汇总(持续更新,欢迎star):https://github.com/xuhongv/StudyInEsp32


Here Insert Picture Description

Guess you like

Origin blog.csdn.net/xh870189248/article/details/90079984