zoukankan      html  css  js  c++  java
  • ESP-12F连接机智云IoT、OTA升级设置(原创)

    这里只做简单介绍,机智云官方文档已经很全了。

    以下文档以台灯为例,一般台灯需要2个数据点,开关 和 PWM调光。


    数据点设置:


    产测工具设置

    产测工具添加需要测试的功能。


    修改固件代码,添加功能

    将下载的固件代码解压,进入目录:SoC_ESP8266_32M_source/app/Gizwits 修改 文件 gizwits_product.c

    修改:

    /* @param [in] info: event queue
    * @param [in] data: protocol data
    * @param [in] len: protocol data length
    * @return NULL
    * @ref gizwits_protocol.h
    */
    int8_t ICACHE_FLASH_ATTR gizwitsEventProcess(eventInfo_t *info, uint8_t *data, uint32_t len)
    {
        uint8_t i = 0;
        uint32 duty = 0;
    
        dataPoint_t * dataPointPtr = (dataPoint_t *)data;
        moduleStatusInfo_t * wifiData = (moduleStatusInfo_t *)data;
    
        if((NULL == info) || (NULL == data))
        {
            GIZWITS_LOG("!!! gizwitsEventProcess Error 
    ");
            return -1;
        }
    
        for(i = 0; i < info->num; i++)
        {
            switch(info->event[i])
            {
            case EVENT_switch_status :
                currentDataPoint.valueswitch_status = dataPointPtr->valueswitch_status;
                GIZWITS_LOG("==> Evt: EVENT_switch_status %d 
    ", currentDataPoint.valueswitch_status);
                if(0x01 == currentDataPoint.valueswitch_status)
                {
                    //user handle
    		gpio_output_set(BIT5, 0, BIT5, 0);  // 添加 LED 打开 代码,对应ESP模块 控制引脚 GPIO5
                }
                else
                {
                    //user handle
                    gpio_output_set(0, BIT5, BIT5, 0);  // 添加 LED 关闭 代码,对应ESP模块 控制引脚 GPIO5
                }
                break;
                
                ....
                    
    

    修改固件版本号(OTA升级用)

    进入目录:SoC_ESP8266_32M_source/app/Gizwits,修改文件:gizwits_product.h

    /**
    * Gagent minor version number for OTA upgrade
    * OTA hardware version number: 00ESP826
    * OTA software version number: 040206xx // "xx" is version number defaults to "25", consistent with the Gagent library version
    */
    #define SDK_VERSION                             "28" 	// 原来25,版本迭代,在原来的基础上加1
    

    有PWM功能时,代码的设置

    每次修改数据点后,,SOC/MCU固件代码需要重新生成。

    修改gizwits_product.cuser_main.c

    // 在 user_main.c 中添加 PWM 功能的初始化。
    /**
    * @brief program entry function
    
    * In the function to complete the user-related initialization
    * @param none
    * @return none
    */
    void ICACHE_FLASH_ATTR user_init(void)
    {
        uint32_t system_free_size = 0;
    
        wifi_station_set_auto_connect(1);
        wifi_set_sleep_type(NONE_SLEEP_T);//set none sleep mode
        espconn_tcp_set_max_con(10);
        uart_init_3(9600,115200);
        UART_SetPrintPort(1);
        GIZWITS_LOG( "---------------SDK version:%s--------------
    ", system_get_sdk_version());
        GIZWITS_LOG( "system_get_free_heap_size=%d
    ",system_get_free_heap_size());
    
        struct rst_info *rtc_info = system_get_rst_info();
        GIZWITS_LOG( "reset reason: %x
    ", rtc_info->reason);
        if (rtc_info->reason == REASON_WDT_RST ||
            rtc_info->reason == REASON_EXCEPTION_RST ||
            rtc_info->reason == REASON_SOFT_WDT_RST)
        {
            if (rtc_info->reason == REASON_EXCEPTION_RST)
            {
                GIZWITS_LOG("Fatal exception (%d):
    ", rtc_info->exccause);
            }
            GIZWITS_LOG( "epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x
    ",
                    rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);
        }
    
        if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1)
        {
            GIZWITS_LOG( "---UPGRADE_FW_BIN1---
    ");
        }
        else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2)
        {
            GIZWITS_LOG( "---UPGRADE_FW_BIN2---
    ");
        }
    
        keyInit();
        gizwitsInit();
    
    	// pwm初始化
        static uint32 pin_info_list[][3]={PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, 12};
        static uint32 duty=1000;
        pwm_init(1000, &duty, 1, pin_info_list);
    
    
        GIZWITS_LOG("--- system_free_size = %d ---
    ", system_get_free_heap_size());
    }
    
    
    // 在gizwits_product.c 中添加 pwm 控制代码
    
    /* @param [in] info: event queue
    * @param [in] data: protocol data
    * @param [in] len: protocol data length
    * @return NULL
    * @ref gizwits_protocol.h
    */
    int8_t ICACHE_FLASH_ATTR gizwitsEventProcess(eventInfo_t *info, uint8_t *data, uint32_t len)
    {
        uint8_t i = 0;
        uint32 duty = 0;
    
        dataPoint_t * dataPointPtr = (dataPoint_t *)data;
        moduleStatusInfo_t * wifiData = (moduleStatusInfo_t *)data;
    
        if((NULL == info) || (NULL == data))
        {
            GIZWITS_LOG("!!! gizwitsEventProcess Error 
    ");
            return -1;
        }
    
        for(i = 0; i < info->num; i++)
        {
            switch(info->event[i])
            {
            case EVENT_switch_status :
                currentDataPoint.valueswitch_status = dataPointPtr->valueswitch_status;
                GIZWITS_LOG("==> Evt: EVENT_switch_status %d 
    ", currentDataPoint.valueswitch_status);
                if(0x01 == currentDataPoint.valueswitch_status)
                {
                    gpio_output_set(BIT5, 0, BIT5, 0);  // Lamp ON
                    //user handle
                }
                else
                {
                    gpio_output_set(0, BIT5, BIT5, 0);  // Lamp ON
                    //user handle
                }
                break;
    
    
            case EVENT_brightness:
                currentDataPoint.valuebrightness= dataPointPtr->valuebrightness;
                GIZWITS_LOG("==> Evt:EVENT_brightness %d
    ",currentDataPoint.valuebrightness);
                
                //user handle
                // 添加pwm控制代码
                duty = currentDataPoint.valuebrightness * 100;   // (22222 => 20000 => 10000 => 5000) / 100
                pwm_set_duty(duty, 0);
                pwm_start();
                break;
                    
                ......
                    
    

    PWM设置,参考:

    • 《ESP8266_SDK_API参考指南 esp8266_non_os_sdk_api_reference_cn.pdf》
    • 《ESP8266技术参考 esp8266-technical_reference_cn.pdf》

    注意:初始化 PWM时 的 引脚顺序,

    static  uint32  pin_info_list[][3] = {
        PERIPHS_IO_MUX_MTDI_U,
        FUNC_GPIO12,
        12
    };
    
    

    编译机智云固件

    Linux平台,按照官方说明编译:

    • 源码编译方式
    cd app/
    ./gen_misc.sh 
    

    注: 机智云固件目前使用的是 NONOS2.0.x 版本,交叉编译器必须是 4.8.x 版本。


    OTA升级

    #define   SDK_VERSION         "25"    // OTA固件版本号,必须为两位数, 默认为当前Gagent库版本号
    
    • 推送的 OTA固件版本号 必须大于正工作的 OTA固件版本号。

    固件命名方式(固件名+固件系列+版本号+其他.bin),选择固件后,下面的选项会自动填入。

    如下:


    保存后,会先验证固件,验证成功后才能推送。


    参考资料

    参考机智云,开发者文档中心。


    end

  • 相关阅读:
    Java线程池之ThreadPoolExecutor
    React Native开发环境的搭建
    Android Lint——内嵌于Android Studio的代码优化工具
    Android异步处理技术
    NavigationView的头部的事件监听
    进程间通信之AIDL
    跨进程通信之Messenger
    Android 进程增加存活率
    android MVP模式思考
    Vim学习
  • 原文地址:https://www.cnblogs.com/wybliw/p/13458448.html
Copyright © 2011-2022 走看看