Lexin esp8266 learning rtos3.0 first four notes: take you process a stroke stroke micro-channel public number airkiss distribution network esp8266 and binding equipment, and successfully transplanted in esp8266 rtos3.1 sdk. (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/89187507

  • 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.


  • 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.


     They remember who philosopher said: people want to grow up in frustration, will come to understand the road ahead more difficult in a time of failure, waiting for his was going to be how kind of difficulties, they should not want to be defeated, and that as long as beat them! ------- a file from Reed Middle School to see.

     The current micro-channel small program but more and more fire! And now, in a micro-channel program development small applications that can be cross-platform, can be described as significant savings in development cycle, recently a lot of people have asked this thing in the group, I slowly for everyone to elaborate this process is how !

     In the previous article point I link , I mentioned a need to do a server H5interface implemented in a micro-channel public number and loaded in the esp8266distribution network principles. In the esp8266end is rtos2.0or is nonos 2.0 、3.0realized, however, until today 2019-4-10demonstrates so far, the official website is still out near-field discovery. While supporting airkissthe distribution network, but this is far less than our development needs.

     Angrily, I have access to micro-channel hardware development documentation, and familiarity with the development of esp8266, three hours to get out, to pit the migration process, as well as distribution network compatible iosand Androidend!

Here Insert Picture Description


Second, prepare materials.


  1. With a number of public function interface device turned on! General business or an individual certified test number! Open with optional device features!
  2. A server can be connected to external networks, Ali cloud purchase or other platform!
  3. A domain name record success, and have SSL certificate!
  4. A esp8266 minimum system module!

      How to micro-letter code development process ends, Bowen omitted! The back will be a more detailed tutorial for everyone, and this article focuses on the principles of micro-channel and near-field discovered how to send a message to the public micro-channel number, to achieve binding!


Third, the binding principle.


      As already said: Lexin of esp8266 rtos3.1 sdkthe code (below unified version of the sdk for this purpose) distribution network model has to support airkissit! But until today 2019-4-10so far, no code is found near field; I went to the micro-channel hardware cloud document looked at, it is also quite simple transplant!

      下图为微信硬件云提供,可以看到其原理非常简单,是一个本地的UDP通讯的过程;由设备端esp8266往局域网内的所有设备指定的端口12476发送一个特定的报文,微信客户端就会近场发现收到此信息!

Here Insert Picture Description


  • 假设当微信客户端收到此设备发来的信息之后,处理给服务器,就可以实现绑定当前配网用户保存在服务器记录里面了!

四、代码实现。


  • 一、首先要开启 udp客户端,因为这个版本是用的是lwip,所以创建socket
  • 二、然后向255.255.255.255这个服务器的12476端口发送指定的内容,此内容要经过微信提供的库文件的某个函数再一次处理得到! 并非直接传自己的内容过去!
  • 三、最后开始发送,微信提醒最好是 每隔5s内发送一次,发送20次以上,提高设备被微信客户端发现的速度:

4.1 添加airkiss静态库到工程!(非常重要)



4.2 创建socket


    int sock_fd;
    struct sockaddr_in client_addr;
    
    sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock_fd == -1)
    {
        printf("[xuhong] failed to create sock_fd!\n");
        vTaskDelete(NULL);
    }

    memset(&client_addr, 0, sizeof(client_addr));
    client_addr.sin_family = AF_INET;
    client_addr.sin_addr.s_addr = inet_addr("255.255.255.255");
    client_addr.sin_port = htons(LOCAL_UDP_PORT); //宏定义 12476

4.3 开始广播!


    int err;
    int count = 0;
    while (1)
    {
        lan_buf_len = sizeof(lan_buf);
        
        //把数据给微信接口二次加密处理返回
        airkiss_lan_ret_t ret = airkiss_lan_pack(AIRKISS_LAN_SSDP_NOTIFY_CMD, ACCOUNT_ID, buffer, 0, 0, lan_buf, &lan_buf_len, &akconf);
        if (ret != AIRKISS_LAN_PAKE_READY)
        {
            printf("Pack lan packet error! \n");
            vTaskDelete(NULL);
        }
        err = sendto(sock_fd, (char *)lan_buf, lan_buf_len, 0, (struct sockaddr *)&client_addr, sizeof(client_addr));
        ESP_LOGI(TAG, "[SY]  send local !  %d ", count); //打印广播的次数
        if (err < 0)
        {
            printf("[SY] failed to send local ! ... \n");
        }
        else
        {
            count++;
            if (count > COUNTS_BOACAST)
            {
               //关闭通道
                handleCreatSocket = NULL;
                shutdown(sock_fd, 0);
                close(sock_fd);
                vTaskDelete(NULL);
            }
        }
        vTaskDelay(1500 / portTICK_RATE_MS); //延迟1.5秒
    }


五、特别强调睬坑。


  • 前端笔记:onScanWXDeviceResult方法在苹果手机包括iPhone X、iPhone6收不到wifi设备的传来的一些信息!本人经过多次查阅,需要在openWXDeviceLib方法调用时候,也就是初始化硬件设备库,传入加上这个公众号原始ID。具体如下:
       //初始化硬件设备库,否则部分机型无法初始化成功导致后面的扫描不了本地设备!
        wx.invoke('openWXDeviceLib', {'connType': 'lan', 'brandUserName': 'gh_xxxxxx'}, function (res) {
            alert("openWXDeviceLib:" + JSON.stringify(res));
        });

  • ①: [device] end notice pit micro-channel public number distribution network airkiss development process, device-side deviceIDpass over format can not be a jsonformat, a personal recommendation to this string base64passed to the micro-letter encrypted. Otherwise, Apple did not directly no callback error message! ! !
  • ②: [pit] If the front end initialization js pay attention js sdkwhen there is no mass public number id, only for Apple phone such as iPhone X local LAN scanning device is not a callback, and no error message!
  • ③: [device] end pit notice last point: the device side of the pass in the public micro-channel number must be for the public micro-channel number of the original ID, format: gh_xxxx! Otherwise, Apple phone is not the callback information! But this has nothing to do with Android phones! Pass parameters is to call special attention to the following function:

airkiss_lan_pack(airkiss_lan_cmdid_t ak_lan_cmdid, void* appid, void* deviceid, void* _datain, unsigned short inlength, void* _dataout, unsigned short* outlength, const airkiss_config_t* config);
  • Functions for packaging, ak_lan_cmdidthe type to be packaged, appidfor the number of public vendor ID, deviceidas the device ID, _datainas data to be transmitted, inlengththe length of transmission data _dataoutis packetized data buffer, outlengththe buffer space is, the function returns successfully the assignment of the actual length of the packet!

  • Here is the code I have this display hardware Bowen in effect micro-channel public number:

Sixth, download.


Guess you like

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