ESP-12F連線機智雲IoT、OTA升級設定
阿新 • • 發佈:2020-08-08
這裡只做簡單介紹,機智雲官方文件已經很全了。
以下文件以檯燈為例,一般檯燈需要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 \n"); 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 \n", 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.c
和 user_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--------------\n", system_get_sdk_version()); GIZWITS_LOG( "system_get_free_heap_size=%d\n",system_get_free_heap_size()); struct rst_info *rtc_info = system_get_rst_info(); GIZWITS_LOG( "reset reason: %x\n", 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):\n", rtc_info->exccause); } GIZWITS_LOG( "epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", 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---\n"); } else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2) { GIZWITS_LOG( "---UPGRADE_FW_BIN2---\n"); } 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 ---\n", 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 \n");
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 \n", 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\n",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