mirror of
https://github.com/oopuuu/zTC1.git
synced 2026-03-23 20:49:55 +08:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8496e8cfd6 | ||
|
|
ade64139cb | ||
|
|
eaf8f5bf60 | ||
|
|
5eecfefc74 | ||
|
|
0c675c6f03 | ||
|
|
982e82c2bb | ||
|
|
eece61e380 | ||
|
|
36861fadff | ||
|
|
f3b7477550 | ||
|
|
dfa8b1c475 | ||
|
|
c7d2f8d7d0 | ||
|
|
e352b74e19 | ||
|
|
3f5078294f | ||
|
|
d7e2243a86 | ||
|
|
4e1b376b6a | ||
|
|
393af288ec | ||
|
|
e9f1448a69 | ||
|
|
004eaf28dd | ||
|
|
55a5f93148 | ||
|
|
86b78d8a4e | ||
|
|
d8099ad499 | ||
|
|
4aca161327 | ||
|
|
67aa42fdd9 | ||
|
|
6e3a48cba6 | ||
|
|
fea21ab02a | ||
|
|
49847dc77c |
2
.gdbinit
2
.gdbinit
@@ -1,2 +1,2 @@
|
|||||||
set remotetimeout 20
|
set remotetimeout 20
|
||||||
shell start /B C:\Users\ooo\Desktop\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt
|
shell start /B F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/Win32/openocd_mico.exe -s ./ -f ./mico-os/makefiles/OpenOCD/interface/jlink_swd.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx.cfg -f ./mico-os/makefiles/OpenOCD/mw3xx/mw3xx_gdb_jtag.cfg -l ./build/openocd_log.txt
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/jlink_swd.cfg]
|
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/jlink_swd.cfg]
|
||||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx.cfg]
|
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx.cfg]
|
||||||
source [find C:\Users\ooo\Desktop\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]
|
source [find F:\TC1\MiCoder_v1.3_Win32-64\MiCoder/OpenOCD/mw3xx_gdb_jtag.cfg]
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ TC1 排插硬件分 A1 A2 两个版本, 本固件仅支持 **A1 版本**. A1 A2
|
|||||||
- [x] 后台可自定义设备名称,此名称将会同至ha mqtt作为mqtt中插座名称的前缀
|
- [x] 后台可自定义设备名称,此名称将会同至ha mqtt作为mqtt中插座名称的前缀
|
||||||
- [x] 后台可自定义按键连击,长按等功能
|
- [x] 后台可自定义按键连击,长按等功能
|
||||||
- [x] 定时开关现在支持更多操作项,与按键功能自定义一样
|
- [x] 定时开关现在支持更多操作项,与按键功能自定义一样
|
||||||
|
- [x] 现在可以上传本地文件来更新固件,同时可以在最新发布的固件说明中参考使用我搭建的文件服务来在线更新
|
||||||
|
# 固件烧录
|
||||||
|
- 参考原始固件代码提供者[a2633063](https://github.com/a2633063/zTC1/wiki/固件烧录)大佬提供的说明
|
||||||
# 编译固件
|
# 编译固件
|
||||||
|
|
||||||
- windows环境,先安装python2.7,下载安装的时候添加环境变量到Path,默认安装路径需要添加两个环境变量C:\Python27;C:\Python27\Scripts
|
- windows环境,先安装python2.7,下载安装的时候添加环境变量到Path,默认安装路径需要添加两个环境变量C:\Python27;C:\Python27\Scripts
|
||||||
|
|||||||
@@ -36,6 +36,11 @@
|
|||||||
#include <http-strings.h>
|
#include <http-strings.h>
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "httpd_priv.h"
|
#include "httpd_priv.h"
|
||||||
#include "app_httpd.h"
|
#include "app_httpd.h"
|
||||||
@@ -55,6 +60,8 @@ const struct httpd_wsgi_call g_app_handlers[];
|
|||||||
char power_info_json[2560] = {0};
|
char power_info_json[2560] = {0};
|
||||||
char up_time[16] = "00:00:00";
|
char up_time[16] = "00:00:00";
|
||||||
#define CHUNK_SIZE 512 // 每次发送 512 字节,避免 buffer 太大
|
#define CHUNK_SIZE 512 // 每次发送 512 字节,避免 buffer 太大
|
||||||
|
#define OTA_BUFFER_SIZE 512
|
||||||
|
#define MAX_OTA_SIZE 1024*1024
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void GetPraFromUrl(char* url, char* pra, char* val)
|
void GetPraFromUrl(char* url, char* pra, char* val)
|
||||||
@@ -255,6 +262,90 @@ static int HttpSetButtonEvent(httpd_request_t *req) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define OTA_BUF_SIZE 5120
|
||||||
|
|
||||||
|
static int HttpSetOTAFile(httpd_request_t *req)
|
||||||
|
{
|
||||||
|
tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d, req.chunked=%d",
|
||||||
|
req->hdr_parsed, req->remaining_bytes, req->body_nbytes, req->chunked);
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
|
int total = 0;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
// req->chunked = 1;
|
||||||
|
|
||||||
|
int total1 = req->remaining_bytes;
|
||||||
|
char *buffer = malloc(OTA_BUF_SIZE);
|
||||||
|
if (!buffer) return kNoMemoryErr;
|
||||||
|
uint32_t offset = 0;
|
||||||
|
|
||||||
|
mico_logic_partition_t* ota_partition = MicoFlashGetInfo(MICO_PARTITION_OTA_TEMP);
|
||||||
|
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
|
||||||
|
CRC16_Context crc_context;
|
||||||
|
CRC16_Init(&crc_context);
|
||||||
|
// 尝试读取全部 POST 数据
|
||||||
|
while (1) {
|
||||||
|
ret = httpd_get_data2(req, buffer,OTA_BUF_SIZE);
|
||||||
|
|
||||||
|
// ret = httpd_recv(req->sock, buffer, 128, 0);
|
||||||
|
total += ret;
|
||||||
|
// req->remaining_bytes -= ret;
|
||||||
|
|
||||||
|
if (ret > 0) {
|
||||||
|
CRC16_Update(&crc_context, buffer, ret);
|
||||||
|
err = MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (uint8_t *)buffer, ret);
|
||||||
|
require_noerr_quiet(err, exit);
|
||||||
|
tc1_log("[OTA] 本次读取 %d 字节,累计 %d 字节", ret, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret == 0 || req->remaining_bytes <= 0) {
|
||||||
|
// 读取完毕
|
||||||
|
tc1_log("[OTA] 数据读取完成, 总计 %d 字节", total);
|
||||||
|
break;
|
||||||
|
} else if (ret < 0) {
|
||||||
|
tc1_log("[OTA] 数据读取失败, ret=%d", ret);
|
||||||
|
err = kConnectionErr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mico_rtos_thread_msleep(100);
|
||||||
|
|
||||||
|
// tc1_log("[OTA] %x", buffer);
|
||||||
|
// tc1_log("[OTA] hdr_parsed=%d, remaining=%d, body_nbytes=%d",
|
||||||
|
// req->hdr_parsed, req->remaining_bytes, req->body_nbytes);
|
||||||
|
}
|
||||||
|
// if (buffer) free(buffer);
|
||||||
|
uint16_t crc16;
|
||||||
|
CRC16_Final(&crc_context, &crc16);
|
||||||
|
|
||||||
|
|
||||||
|
err = mico_ota_switch_to_new_fw(total, crc16);
|
||||||
|
tc1_log("[OTA] mico_ota_switch_to_new_fw err=%d", err);
|
||||||
|
require_noerr(err, exit);
|
||||||
|
|
||||||
|
char resp[128];
|
||||||
|
snprintf(resp, sizeof(resp), "OK, total: %d bytes, req %d %d", total, req->body_nbytes, total1);
|
||||||
|
send_http(resp, strlen(resp), exit, &err);
|
||||||
|
|
||||||
|
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
|
||||||
|
exit:
|
||||||
|
if (buffer) free(buffer);
|
||||||
|
return err;
|
||||||
|
|
||||||
|
// ota_file_req = req;
|
||||||
|
|
||||||
|
// OSStatus err = kNoErr;
|
||||||
|
// err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "OtaFileThread", OtaFileThread, 0x1000, 0);
|
||||||
|
// char buf[16] = {0};
|
||||||
|
// sprintf(buf, "%d", sizeof(ota_file_req));
|
||||||
|
// send_http(buf, strlen(buf), exit, &err);
|
||||||
|
|
||||||
|
// exit:
|
||||||
|
// if (buf) free(buf);
|
||||||
|
// return err;
|
||||||
|
}
|
||||||
|
|
||||||
static int HttpSetDeviceName(httpd_request_t *req) {
|
static int HttpSetDeviceName(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
@@ -344,19 +435,62 @@ static int HttpGetWifiConfig(httpd_request_t *req) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 单个十六进制字符转数字(安全)
|
||||||
|
static int hex_char_to_int(char c) {
|
||||||
|
if ('0' <= c && c <= '9') return c - '0';
|
||||||
|
if ('a' <= c && c <= 'f') return c - 'a' + 10;
|
||||||
|
if ('A' <= c && c <= 'F') return c - 'A' + 10;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 健壮版 URL 解码函数
|
||||||
|
void url_decode(const char *src, char *dest, size_t max_len) {
|
||||||
|
size_t i = 0;
|
||||||
|
while (*src && i < max_len - 1) {
|
||||||
|
if (*src == '%') {
|
||||||
|
if (isxdigit((unsigned char)src[1]) && isxdigit((unsigned char)src[2])) {
|
||||||
|
int high = hex_char_to_int(src[1]);
|
||||||
|
int low = hex_char_to_int(src[2]);
|
||||||
|
if (high >= 0 && low >= 0) {
|
||||||
|
dest[i++] = (char)((high << 4) | low);
|
||||||
|
src += 3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 非法编码,跳过 %
|
||||||
|
src++;
|
||||||
|
} else if (*src == '+') {
|
||||||
|
dest[i++] = ' ';
|
||||||
|
src++;
|
||||||
|
} else {
|
||||||
|
dest[i++] = *src++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
static int HttpSetWifiConfig(httpd_request_t *req) {
|
static int HttpSetWifiConfig(httpd_request_t *req) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
int buf_size = 97;
|
char *buf = malloc(256);
|
||||||
char *buf = malloc(buf_size);
|
char *ssid_enc = malloc(128);
|
||||||
int mode = -1;
|
char *key_enc = malloc(128);
|
||||||
char *wifi_ssid = malloc(32);
|
char *wifi_ssid = malloc(128);
|
||||||
char *wifi_key = malloc(32);
|
char *wifi_key = malloc(128);
|
||||||
|
int mode = -1;
|
||||||
|
|
||||||
err = httpd_get_data(req, buf, buf_size);
|
|
||||||
|
|
||||||
|
err = httpd_get_data(req, buf, 256);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
|
// 假设 httpd_get_data(req, buf, 256);
|
||||||
sscanf(buf, "%d %s %s", &mode, wifi_ssid, wifi_key);
|
// tc1_log("wifi config %s",buf);
|
||||||
|
sscanf(buf, "%d %s %s", &mode, ssid_enc, key_enc);
|
||||||
|
// tc1_log("wifi config %s %s",ssid_enc,key_enc);
|
||||||
|
url_decode(ssid_enc, wifi_ssid,128);
|
||||||
|
url_decode(key_enc, wifi_key,128);
|
||||||
|
// tc1_log("wifi config decode %s %s",wifi_ssid,wifi_key);
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
WifiConnect(wifi_ssid, wifi_key);
|
WifiConnect(wifi_ssid, wifi_key);
|
||||||
} else {
|
} else {
|
||||||
@@ -643,6 +777,7 @@ const struct httpd_wsgi_call g_app_handlers[] = {
|
|||||||
{"/childLock", HTTPD_HDR_DEFORT, 0, NULL, HttpSetChildLock, NULL, NULL},
|
{"/childLock", HTTPD_HDR_DEFORT, 0, NULL, HttpSetChildLock, NULL, NULL},
|
||||||
{"/deviceName", HTTPD_HDR_DEFORT, 0, NULL, HttpSetDeviceName, NULL, NULL},
|
{"/deviceName", HTTPD_HDR_DEFORT, 0, NULL, HttpSetDeviceName, NULL, NULL},
|
||||||
{"/buttonEvents", HTTPD_HDR_DEFORT, 0, HttpGetButtonEvents, HttpSetButtonEvent, NULL, NULL},
|
{"/buttonEvents", HTTPD_HDR_DEFORT, 0, HttpGetButtonEvents, HttpSetButtonEvent, NULL, NULL},
|
||||||
|
{"/ota/fileUpload", HTTPD_HDR_DEFORT, 0, NULL, HttpSetOTAFile, NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
static int g_app_handlers_no = sizeof(g_app_handlers) / sizeof(struct httpd_wsgi_call);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%d,'p_count_2_days_ago':%d,'child_lock_enabled':%d,'deviceName':'%s','btnClicks':%s}"
|
#define POWER_INFO_JSON "{'sockets':'%s','idx':%d,'len':%d,'p_count':%ld,'powers':[%s],'up_time':'%s','led_enabled':%d,'total_switch_on':%d,'socketNames':'%s','p_count_1_day_ago':%d,'p_count_2_days_ago':%d,'child_lock_enabled':%d,'deviceName':'%s','btnClicks':%s}"
|
||||||
|
|
||||||
int AppHttpdStart(void);
|
extern int AppHttpdStart(void);
|
||||||
|
|
||||||
int AppHttpdStop();
|
extern int AppHttpdStop();
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
|
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
|
||||||
<header class="demo-header mdl-layout__header">
|
<header class="demo-header mdl-layout__header">
|
||||||
<div class="mdl-layout__header-row">
|
<div class="mdl-layout__header-row">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-device-name">
|
<button class="mdl-button mdl-button--icon edit-device-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -40,22 +40,22 @@
|
|||||||
</button>
|
</button>
|
||||||
<span class="mdl-layout-title">TC1智能插座</span>
|
<span class="mdl-layout-title">TC1智能插座</span>
|
||||||
<div class="mdl-layout-spacer"></div>
|
<div class="mdl-layout-spacer"></div>
|
||||||
<!-- <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"-->
|
<!-- <button class="mdl-button mdl-button--icon"-->
|
||||||
<!-- id="hdrbtn">-->
|
<!-- id="hdrbtn">-->
|
||||||
<!-- <i class="material-icons">-->
|
<!-- <i class="material-icons">-->
|
||||||
<!-- <svg>-->
|
<!-- <svg>-->
|
||||||
<!-- <use xlink:href="#icon-translate"/>-->
|
<!-- <use xlink:href="#icon-translate"/>-->
|
||||||
<!-- </svg>-->
|
<!-- </svg>-->
|
||||||
<!-- </i>-->
|
<!-- </i>-->
|
||||||
<!-- </button>-->
|
<!-- </button>-->
|
||||||
<!-- <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"-->
|
<!-- <ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right"-->
|
||||||
<!-- for="hdrbtn">-->
|
<!-- for="hdrbtn">-->
|
||||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>-->
|
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('en')">English</li>-->
|
||||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>-->
|
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('cn')">中文</li>-->
|
||||||
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>-->
|
<!-- <li class="mdl-menu__item" onclick="ChangeLanguage('jp')">日本語</li>-->
|
||||||
<!-- </ul>-->
|
<!-- </ul>-->
|
||||||
<button onclick="reboot()"
|
<button onclick="reboot()"
|
||||||
class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon"
|
class="mdl-button mdl-button--icon"
|
||||||
id="rebootbtn">
|
id="rebootbtn">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
<use xlink:href="#icon-cloud_download"/>
|
<use xlink:href="#icon-cloud_download"/>
|
||||||
</svg>
|
</svg>
|
||||||
</i>
|
</i>
|
||||||
<span class="lang" langKey="OTA">在线升级</span>
|
<span class="lang" langKey="OTA">固件升级</span>
|
||||||
</a>
|
</a>
|
||||||
<a class="mdl-navigation__link" href="javascript:ShowPage(7);">
|
<a class="mdl-navigation__link" href="javascript:ShowPage(7);">
|
||||||
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
<i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -195,7 +195,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -214,7 +214,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -233,7 +233,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -252,7 +252,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -271,7 +271,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="mdl-list__item">
|
<li class="mdl-list__item">
|
||||||
<span class="mdl-list__item-primary-content">
|
<span class="mdl-list__item-primary-content">
|
||||||
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon edit-socket-name">
|
<button class="mdl-button mdl-button--icon edit-socket-name">
|
||||||
<i class="material-icons">
|
<i class="material-icons">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#icon-edit"/>
|
<use xlink:href="#icon-edit"/>
|
||||||
@@ -291,30 +291,30 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page page1 mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing">
|
<div class="page page1 mdl-cell mdl-cell--4-col mdl-cell--8-col-tablet mdl-grid mdl-grid--no-spacing">
|
||||||
<div class="demo-options mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
|
<div class="demo-options mdl-card mdl-shadow--2dp mdl-cell mdl-cell--4-col mdl-cell--3-col-tablet mdl-cell--12-col-desktop">
|
||||||
<div class="mdl-card__supporting-text">
|
<div class="mdl-card__supporting-text">
|
||||||
<div class="mdl-card__title mdl-card--expand">
|
<div class="mdl-card__title mdl-card--expand">
|
||||||
<h2 class="mdl-card__title-text">功率图</h2>
|
<h2 class="mdl-card__title-text">功率图</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="ct-chart-par"
|
<div id="ct-chart-par"
|
||||||
class="page page1 mdl-card__supporting-text mdl-shadow--2dp"
|
class="page page1 mdl-card__supporting-text mdl-shadow--2dp"
|
||||||
style="height:315px;overflow-x:scroll;overflow-y:hidden;">
|
style="height:315px;overflow-x:scroll;overflow-y:hidden;">
|
||||||
<table class="pw">
|
<table class="pw">
|
||||||
<tr>
|
<tr>
|
||||||
<td>当前功率: <span id="p" class="success">0</span> W</td>
|
<td>当前功率: <span id="p" class="success">0</span> W</td>
|
||||||
<td>今日电量: <span id="w_t" class="error">0</span> kW·h</td>
|
<td>今日电量: <span id="w_t" class="error">0</span> kW·h</td>
|
||||||
<td>昨日电量: <span id="w_y" class="error">0</span> kW·h</td>
|
<td>昨日电量: <span id="w_y" class="error">0</span> kW·h</td>
|
||||||
<td>总电量: <span id="w" class="error">0</span> kW·h</td>
|
<td>总电量: <span id="w" class="error">0</span> kW·h</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div id="ct-chart" class="ct-chart ct-perfect-fourth"
|
<div id="ct-chart" class="ct-chart ct-perfect-fourth"
|
||||||
style="height:280px;margin-top:40px;"></div>
|
style="height:280px;margin-top:40px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -368,10 +368,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a id="wifi_submit"
|
<button type="button" id="wifi_submit"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
提交
|
提交
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -401,10 +401,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a id="mqtt_submit"
|
<button type="button" id="mqtt_submit"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
提交
|
提交
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -422,10 +422,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a id="mqtt_freq_submit"
|
<button type="button" id="mqtt_freq_submit"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
提交
|
提交
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -438,20 +438,6 @@
|
|||||||
<th>循环</th>
|
<th>循环</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td>02-15 07:11</td>
|
|
||||||
<td>1</td>
|
|
||||||
<td>0</td>
|
|
||||||
<td>0</td>
|
|
||||||
<td><a>删除</a></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>2020-02-15<br>07:11:08</td>
|
|
||||||
<td>1</td>
|
|
||||||
<td>0</td>
|
|
||||||
<td>6</td>
|
|
||||||
<td><a>删除</a></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -519,10 +505,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a href="javascript:AddTimedTask();"
|
<button type="button" onclick="AddTimedTask();"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
提交
|
提交
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -539,7 +525,7 @@
|
|||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="page page4 over-unset mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
<div class="page page4 over-unset mdl-cell mdl-cell--5-col demo-card-square mdl-card mdl-shadow--2dp"
|
||||||
style="z-index: unset;">
|
style="z-index: unset;">
|
||||||
@@ -598,10 +584,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a href="javascript:addButtonEvent();"
|
<button type="button" onclick="addButtonEvent();"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
添加
|
添加
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -610,23 +596,23 @@
|
|||||||
<table class="mdl-data-table mdl-js-data-table">
|
<table class="mdl-data-table mdl-js-data-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>版本</th>
|
<th>版本</th>
|
||||||
<th id="info_version">v1.0.33</th>
|
<th id="info_version"></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>IP</td>
|
<td>IP</td>
|
||||||
<td id="info_ip">192.168.33.222</td>
|
<td id="info_ip"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>子网掩码</td>
|
<td>子网掩码</td>
|
||||||
<td id="info_mask">255.255.255.0</td>
|
<td id="info_mask"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>网关</td>
|
<td>网关</td>
|
||||||
<td id="info_gateway">192.168.33.1</td>
|
<td id="info_gateway"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>启动时间</td>
|
<td>启动时间</td>
|
||||||
<td id="uptime">10:13:43</td>
|
<td id="uptime"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div class="mdl-card__actions mdl-card--border" style="display: flex; align-items: center; flex-wrap: wrap;">
|
<div class="mdl-card__actions mdl-card--border" style="display: flex; align-items: center; flex-wrap: wrap;">
|
||||||
@@ -638,7 +624,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</i>
|
</i>
|
||||||
<!-- <span>2020-02-22</span> -->
|
<!-- <span>2020-02-22</span> -->
|
||||||
<a class="mdl-button" id="st-date">2020-02-22</a>
|
<a class="mdl-button" id="st-date"></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -655,14 +641,33 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a href="javascript:OtaStart();"
|
<button type="button" onclick="OtaStart();" id="submit-ota-link"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
提交
|
提交
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="ota_status" class="mdl-progress mdl-js-progress"></div>
|
<div id="ota_status" class="mdl-progress mdl-js-progress"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="page page6 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||||
|
<div class="mdl-card__title mdl-card--expand">
|
||||||
|
<h2 class="mdl-card__title-text">本地升级</h2>
|
||||||
|
</div>
|
||||||
|
<div class="mdl-card__supporting-text">
|
||||||
|
<form id="otaForm" action="/ota/fileUpload" method="post" enctype="multipart/form-data">
|
||||||
|
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||||
|
<input class="mdl-textfield__input" type="file" id="ota_file" name="ota_file">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
|
<button type="button" onclick="OtaFileUpload();" class="mdl-button mdl-button--colored " id="submit-ota-file">
|
||||||
|
上传 OTA 文件
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div id="upload_status" class="mdl-progress mdl-js-progress"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="page page7 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
<div class="page page7 mdl-cell mdl-cell--12-col demo-card-square mdl-card mdl-shadow--2dp">
|
||||||
<div class="mdl-card__title mdl-card--expand">
|
<div class="mdl-card__title mdl-card--expand">
|
||||||
<h2 class="mdl-card__title-text">系统日志</h2>
|
<h2 class="mdl-card__title-text">系统日志</h2>
|
||||||
@@ -671,10 +676,10 @@
|
|||||||
<pre id="sys_log"></pre>
|
<pre id="sys_log"></pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-card__actions mdl-card--border">
|
<div class="mdl-card__actions mdl-card--border">
|
||||||
<a href="javascript:GetSysLog();"
|
<button type="button" onclick="GetSysLog();"
|
||||||
class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
|
class="mdl-button mdl-button--colored ">
|
||||||
刷新
|
刷新
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -777,7 +782,7 @@
|
|||||||
Config: {en: "Config", cn: "设置"},
|
Config: {en: "Config", cn: "设置"},
|
||||||
TimedTask: {en: "Timed Task", cn: "定时任务"},
|
TimedTask: {en: "Timed Task", cn: "定时任务"},
|
||||||
SystemStatus: {en: "System Status", cn: "系统状态"},
|
SystemStatus: {en: "System Status", cn: "系统状态"},
|
||||||
OTA: {en: "OTA", cn: "在线升级"},
|
OTA: {en: "OTA", cn: "固件升级"},
|
||||||
SystemLog: {en: "System Log", cn: "系统日志"},
|
SystemLog: {en: "System Log", cn: "系统日志"},
|
||||||
About: {en: "About", cn: "关于"},
|
About: {en: "About", cn: "关于"},
|
||||||
//主页
|
//主页
|
||||||
@@ -957,6 +962,7 @@
|
|||||||
BTN_OPERATIONS.push("重新配网");
|
BTN_OPERATIONS.push("重新配网");
|
||||||
BTN_OPERATIONS.push("重置系统");
|
BTN_OPERATIONS.push("重置系统");
|
||||||
BTN_OPERATIONS.push("切换童锁");
|
BTN_OPERATIONS.push("切换童锁");
|
||||||
|
BTN_OPERATIONS.push("重启网页");
|
||||||
|
|
||||||
$('#btn_action_selector').append(
|
$('#btn_action_selector').append(
|
||||||
$('<li>')
|
$('<li>')
|
||||||
@@ -1216,15 +1222,15 @@ componentHandler.upgradeDom();
|
|||||||
var mode = $("#custom_station").prop("checked") ? 1 : 0;
|
var mode = $("#custom_station").prop("checked") ? 1 : 0;
|
||||||
var ssid = $("#custom_ssid").val();
|
var ssid = $("#custom_ssid").val();
|
||||||
var passwd = $("#custom_password").val();
|
var passwd = $("#custom_password").val();
|
||||||
if (ContainQM(ssid) || ContainQM(passwd)) {
|
//if (ContainQM(ssid) || ContainQM(passwd)) {
|
||||||
alert(qm_mess);
|
// alert(qm_mess);
|
||||||
return;
|
// return;
|
||||||
}
|
//}
|
||||||
if (passwd.length < 8) {
|
if (passwd.length < 8) {
|
||||||
alert(le_mess);
|
alert(le_mess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var params = mode + " " + ssid + " " + passwd;
|
var params = mode + " " + encodeURIComponent(ssid) + " " + encodeURIComponent(passwd);
|
||||||
HttpPost("/wifi/config", function (re) {
|
HttpPost("/wifi/config", function (re) {
|
||||||
ShowToast(re);
|
ShowToast(re);
|
||||||
}, params);
|
}, params);
|
||||||
@@ -1240,6 +1246,7 @@ componentHandler.upgradeDom();
|
|||||||
var w = document.getElementById("w");
|
var w = document.getElementById("w");
|
||||||
var w_t = document.getElementById("w_t");
|
var w_t = document.getElementById("w_t");
|
||||||
var w_y = document.getElementById("w_y");
|
var w_y = document.getElementById("w_y");
|
||||||
|
var powerTimerId;
|
||||||
|
|
||||||
function GetPowerRecord() {
|
function GetPowerRecord() {
|
||||||
HttpPost("/power", function (re) {
|
HttpPost("/power", function (re) {
|
||||||
@@ -1305,7 +1312,7 @@ componentHandler.upgradeDom();
|
|||||||
switch_lables[i+3].MaterialSwitch.off();
|
switch_lables[i+3].MaterialSwitch.off();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.powerTimeout= window.setTimeout(GetPowerRecord, 3000);
|
powerTimerId= window.setTimeout(GetPowerRecord, 3000);
|
||||||
}, power_idx.toString());
|
}, power_idx.toString());
|
||||||
}
|
}
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
@@ -1484,12 +1491,51 @@ HttpPost("/shortClickEvent", function (re) {
|
|||||||
var ota_url = document.getElementById("ota_url").value;
|
var ota_url = document.getElementById("ota_url").value;
|
||||||
var protocol = window.location.protocol;
|
var protocol = window.location.protocol;
|
||||||
var baseUrl = protocol+"//"+window.location.host;
|
var baseUrl = protocol+"//"+window.location.host;
|
||||||
|
document.getElementById("submit-ota-link").disabled = true;
|
||||||
clearTimeout(window.powerTimeout);
|
|
||||||
HttpPost("/ota", function (re) {
|
HttpPost("/ota", function (re) {
|
||||||
OtaStatus();
|
OtaStatus();
|
||||||
}, ota_url);
|
}, ota_url);
|
||||||
}
|
}
|
||||||
|
var upload_status = document.querySelector('#upload_status');
|
||||||
|
upload_status.addEventListener('mdl-componentupgraded', function() {
|
||||||
|
this.MaterialProgress.setProgress(0);
|
||||||
|
});
|
||||||
|
function OtaFileUpload() {
|
||||||
|
//alert("假的假的是假的,忽略");
|
||||||
|
//return;
|
||||||
|
var fileInput = document.getElementById("ota_file");
|
||||||
|
if (fileInput.files.length === 0) {
|
||||||
|
ShowToast("请选择要上传的 OTA 文件");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(powerTimerId);
|
||||||
|
console.log(fileInput.files[0].size); // 应显示 647168 左右
|
||||||
|
document.getElementById("submit-ota-file").disabled = true;
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/ota/fileUpload");
|
||||||
|
|
||||||
|
xhr.upload.onprogress = function (e) {
|
||||||
|
if (e.lengthComputable) {
|
||||||
|
let percent = (e.loaded / e.total * 100).toFixed(1);
|
||||||
|
upload_status.MaterialProgress.setProgress(percent);
|
||||||
|
console.log(`上传进度:${percent}%`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.onload = function () {
|
||||||
|
alert("上传完成:" + xhr.responseText);
|
||||||
|
document.getElementById("submit-ota-file").disabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.onerror = function () {
|
||||||
|
alert("上传失败");
|
||||||
|
document.getElementById("submit-ota-file").disabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/octet-stream");
|
||||||
|
xhr.send(fileInput.files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
var ota_status = document.querySelector('#ota_status');
|
var ota_status = document.querySelector('#ota_status');
|
||||||
ota_status.addEventListener('mdl-componentupgraded', function() {
|
ota_status.addEventListener('mdl-componentupgraded', function() {
|
||||||
this.MaterialProgress.setProgress(0);
|
this.MaterialProgress.setProgress(0);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include "mico.h"
|
||||||
|
|
||||||
|
|
||||||
#include"http_server/web_log.h"
|
#include"http_server/web_log.h"
|
||||||
|
|
||||||
@@ -36,6 +38,9 @@ char* GetLogRecord()
|
|||||||
tmp += strlen(tmp);
|
tmp += strlen(tmp);
|
||||||
if (!log_record.logs[i%LOG_NUM]) continue;
|
if (!log_record.logs[i%LOG_NUM]) continue;
|
||||||
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
sprintf(tmp, "%s\n", log_record.logs[i%LOG_NUM]);
|
||||||
|
if(i == log_record.idx){
|
||||||
|
sprintf(tmp, "%s\nFreeMem %d bytes\n",log_record.logs[i%LOG_NUM],MicoGetMemoryInfo()->free_memory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return log_record_str;
|
return log_record_str;
|
||||||
}
|
}
|
||||||
|
|||||||
10
TC1/main.c
10
TC1/main.c
@@ -10,7 +10,6 @@
|
|||||||
#include "user_wifi.h"
|
#include "user_wifi.h"
|
||||||
#include "time_server/user_rtc.h"
|
#include "time_server/user_rtc.h"
|
||||||
#include "user_power.h"
|
#include "user_power.h"
|
||||||
#include "mqtt_server/user_mqtt_client.h"
|
|
||||||
#include "http_server/app_httpd.h"
|
#include "http_server/app_httpd.h"
|
||||||
#include "timed_task/timed_task.h"
|
#include "timed_task/timed_task.h"
|
||||||
|
|
||||||
@@ -186,10 +185,6 @@ int application_start(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyInit();
|
KeyInit();
|
||||||
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
|
||||||
err = UserMqttInit();
|
|
||||||
require_noerr(err, exit);
|
|
||||||
}
|
|
||||||
err = UserRtcInit();
|
err = UserRtcInit();
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
PowerInit();
|
PowerInit();
|
||||||
@@ -199,12 +194,12 @@ int application_start(void) {
|
|||||||
|
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "p_count",
|
||||||
(mico_thread_function_t) schedule_p_count_task,
|
(mico_thread_function_t) schedule_p_count_task,
|
||||||
0x2000, 0);
|
0x800, 0);
|
||||||
require_noerr_string(err, exit, "ERROR: Unable to start the p_count thread.");
|
require_noerr_string(err, exit, "ERROR: Unable to start the p_count thread.");
|
||||||
|
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "mqtt_power_report",
|
||||||
(mico_thread_function_t) reportMqttPowerInfoThread,
|
(mico_thread_function_t) reportMqttPowerInfoThread,
|
||||||
0x2000, 0);
|
0x800, 0);
|
||||||
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
|
require_noerr_string(err, exit, "ERROR: Unable to start the mqtt_power_report thread.");
|
||||||
|
|
||||||
|
|
||||||
@@ -213,7 +208,6 @@ int application_start(void) {
|
|||||||
if (user_config->task_top && now >= user_config->task_top->prs_time) {
|
if (user_config->task_top && now >= user_config->task_top->prs_time) {
|
||||||
ProcessTask();
|
ProcessTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
mico_thread_msleep(1000);
|
mico_thread_msleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
|
#define wifi_log(M, ...) custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__);
|
||||||
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
|
#define power_log(M, ...) custom_log("POWER", M, ##__VA_ARGS__); web_log("POWER", M, ##__VA_ARGS__);
|
||||||
|
|
||||||
#define VERSION "v2.1.7"
|
#define VERSION "v2.2.0"
|
||||||
|
|
||||||
#define TYPE 1
|
#define TYPE 1
|
||||||
#define TYPE_NAME "TC1"
|
#define TYPE_NAME "TC1"
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ mico_queue_t mqtt_msg_send_queue = NULL;
|
|||||||
|
|
||||||
Client c; // mqtt client object
|
Client c; // mqtt client object
|
||||||
Network n; // socket network for mqtt client
|
Network n; // socket network for mqtt client
|
||||||
|
volatile bool mqtt_thread_should_exit = false;
|
||||||
|
|
||||||
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
|
static mico_worker_thread_t mqtt_client_worker_thread; /* Worker thread to manage send/recv events */
|
||||||
//static mico_timed_event_t mqtt_client_send_event;
|
//static mico_timed_event_t mqtt_client_send_event;
|
||||||
@@ -98,10 +99,32 @@ void UserMqttTimerFunc(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OSStatus UserMqttDeInit(void) {
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
|
// 1. 请求线程退出
|
||||||
|
mqtt_thread_should_exit = true;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_mqtt_msg_send_queue(void) {
|
||||||
|
if(mqtt_msg_send_queue == NULL){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
void *msg = NULL;
|
||||||
|
while (mico_rtos_is_queue_empty(&mqtt_msg_send_queue) == false) {
|
||||||
|
if (mico_rtos_pop_from_queue(&mqtt_msg_send_queue, &msg, 0) == kNoErr) {
|
||||||
|
if (msg) free(msg); // 释放消息内存,避免泄漏
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Application entrance */
|
/* Application entrance */
|
||||||
OSStatus UserMqttInit(void) {
|
OSStatus UserMqttInit(void) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
if(mqtt_msg_send_queue != NULL)
|
||||||
|
return err;
|
||||||
sprintf(topic_set, MQTT_CLIENT_SUB_TOPIC1);
|
sprintf(topic_set, MQTT_CLIENT_SUB_TOPIC1);
|
||||||
sprintf(topic_state, MQTT_CLIENT_PUB_TOPIC, str_mac);
|
sprintf(topic_state, MQTT_CLIENT_PUB_TOPIC, str_mac);
|
||||||
//TODO size:0x800
|
//TODO size:0x800
|
||||||
@@ -136,13 +159,32 @@ OSStatus UserMqttInit(void) {
|
|||||||
static OSStatus UserMqttClientRelease(Client *c, Network *n) {
|
static OSStatus UserMqttClientRelease(Client *c, Network *n) {
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
if (c->isconnected) MQTTDisconnect(c);
|
if (c == NULL || n == NULL) return kParamErr;
|
||||||
|
|
||||||
n->disconnect(n); // close connection
|
if (c->isconnected) {
|
||||||
|
MQTTDisconnect(c);
|
||||||
|
c->isconnected = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (MQTT_SUCCESS != MQTTClientDeinit(c)) { mqtt_log("MQTTClientDeinit failed!");
|
if (c->buf) {
|
||||||
|
free(c->buf);
|
||||||
|
c->buf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c->readbuf) {
|
||||||
|
free(c->readbuf);
|
||||||
|
c->readbuf = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n->disconnect) {
|
||||||
|
n->disconnect(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MQTT_SUCCESS != MQTTClientDeinit(c)) {
|
||||||
|
mqtt_log("MQTTClientDeinit failed!");
|
||||||
err = kDeletedErr;
|
err = kDeletedErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +219,9 @@ static OSStatus MqttMsgPublish(Client *c, const char *topic, char qos, char reta
|
|||||||
}
|
}
|
||||||
|
|
||||||
void registerMqttEvents(void) {
|
void registerMqttEvents(void) {
|
||||||
|
if(timer_status !=0){
|
||||||
|
mico_stop_timer(&timer_handle);
|
||||||
|
}
|
||||||
timer_status = 0;
|
timer_status = 0;
|
||||||
mico_start_timer(&timer_handle);
|
mico_start_timer(&timer_handle);
|
||||||
}
|
}
|
||||||
@@ -202,16 +247,18 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
|
|
||||||
/* create msg send queue event fd */
|
/* create msg send queue event fd */
|
||||||
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
|
msg_send_event_fd = mico_create_event_fd(mqtt_msg_send_queue);
|
||||||
|
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
||||||
|
|
||||||
require_action(msg_send_event_fd >= 0, exit,
|
require_action(msg_send_event_fd >= 0, exit,
|
||||||
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
|
mqtt_log("ERROR: create msg send queue event fd failed!!!"));
|
||||||
|
mqtt_thread_should_exit = false;
|
||||||
MQTT_start:
|
MQTT_start:
|
||||||
|
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
/* 1. create network connection */
|
/* 1. create network connection */
|
||||||
ssl_settings.ssl_enable = false;
|
ssl_settings.ssl_enable = false;
|
||||||
LinkStatusTypeDef LinkStatus;
|
LinkStatusTypeDef LinkStatus;
|
||||||
while (1) {
|
while (!mqtt_thread_should_exit) {
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
mico_rtos_thread_sleep(3);
|
mico_rtos_thread_sleep(3);
|
||||||
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
|
if (MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)
|
||||||
@@ -228,7 +275,8 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
if (rc == MQTT_SUCCESS) break;
|
if (rc == MQTT_SUCCESS) break;
|
||||||
|
|
||||||
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
//mqtt_log("ERROR: MQTT network connect err=%d, reconnect after 3s...", rc);
|
||||||
}mqtt_log("MQTT network connect success!");
|
}
|
||||||
|
mqtt_log("MQTT network connect success!");
|
||||||
|
|
||||||
/* 2. init mqtt client */
|
/* 2. init mqtt client */
|
||||||
//c.heartbeat_retry_max = 2;
|
//c.heartbeat_retry_max = 2;
|
||||||
@@ -249,7 +297,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
rc = MQTTConnect(&c, &connectData);
|
rc = MQTTConnect(&c, &connectData);
|
||||||
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client connect err.");
|
require_noerr_string(rc, MQTT_reconnect, "ERROR: MQTT client connect err.");
|
||||||
|
|
||||||
mqtt_log("MQTT client connect success!");
|
mqtt_log("MQTT client connect success, result: %d ", rc);
|
||||||
|
|
||||||
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
UserLedSet(RelayOut() && user_config->power_led_enabled);
|
||||||
|
|
||||||
@@ -269,10 +317,9 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
UserMqttSendTotalSocketState();
|
UserMqttSendTotalSocketState();
|
||||||
UserMqttSendChildLockState();
|
UserMqttSendChildLockState();
|
||||||
|
|
||||||
mico_init_timer(&timer_handle, 150, UserMqttTimerFunc, &arg);
|
|
||||||
registerMqttEvents();
|
registerMqttEvents();
|
||||||
/* 5. client loop for recv msg && keepalive */
|
/* 5. client loop for recv msg && keepalive */
|
||||||
while (1) {
|
while (!mqtt_thread_should_exit) {
|
||||||
isconnect = true;
|
isconnect = true;
|
||||||
no_mqtt_msg_exchange = true;
|
no_mqtt_msg_exchange = true;
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
@@ -298,13 +345,12 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
err = MqttMsgPublish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
err = MqttMsgPublish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained,
|
||||||
(const unsigned char *) p_send_msg->data,
|
(const unsigned char *) p_send_msg->data,
|
||||||
p_send_msg->datalen);
|
p_send_msg->datalen);
|
||||||
|
free(p_send_msg);
|
||||||
|
p_send_msg = NULL;
|
||||||
require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT publish data err");
|
require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT publish data err");
|
||||||
|
|
||||||
//mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].", p_send_msg->topic, p_send_msg->datalen);
|
//mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].", p_send_msg->topic, p_send_msg->datalen);
|
||||||
no_mqtt_msg_exchange = false;
|
no_mqtt_msg_exchange = false;
|
||||||
free(p_send_msg);
|
|
||||||
p_send_msg = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +366,7 @@ void MqttClientThread(mico_thread_arg_t arg) {
|
|||||||
mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err);
|
mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d, err = %d", rc, err);
|
||||||
|
|
||||||
timer_status = 100;
|
timer_status = 100;
|
||||||
|
clear_mqtt_msg_send_queue();
|
||||||
UserMqttClientRelease(&c, &n);
|
UserMqttClientRelease(&c, &n);
|
||||||
isconnect = false;
|
isconnect = false;
|
||||||
UserLedSet(-1);
|
UserLedSet(-1);
|
||||||
@@ -329,10 +375,12 @@ mqtt_log("Disconnect MQTT client, and reconnect after 5s, reason: mqtt_rc = %d,
|
|||||||
mico_rtos_thread_sleep(5);
|
mico_rtos_thread_sleep(5);
|
||||||
goto MQTT_start;
|
goto MQTT_start;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
isconnect = false;mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
isconnect = false;
|
||||||
|
mqtt_log("EXIT: MQTT client exit with err = %d.", err);
|
||||||
UserMqttClientRelease(&c, &n);
|
UserMqttClientRelease(&c, &n);
|
||||||
mico_rtos_delete_thread(NULL);
|
mico_rtos_delete_thread(NULL); // 自删
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// callback, msg received from mqtt server
|
// callback, msg received from mqtt server
|
||||||
@@ -423,7 +471,9 @@ void ProcessHaCmd(char *cmd) {
|
|||||||
childLockEnabled = on;
|
childLockEnabled = on;
|
||||||
UserMqttSendChildLockState();
|
UserMqttSendChildLockState();
|
||||||
mico_system_context_update(sys_config);
|
mico_system_context_update(sys_config);
|
||||||
}else if (strcmp(cmd, "reboot") == 0) {
|
}else if (strcmp(cmd, "reboot") == ' ') {
|
||||||
|
sscanf(cmd, "reboot %s", mac);
|
||||||
|
if (strcmp(mac, str_mac)) return;
|
||||||
MicoSystemReboot(); // 立即重启设备
|
MicoSystemReboot(); // 立即重启设备
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -431,7 +481,7 @@ void ProcessHaCmd(char *cmd) {
|
|||||||
OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
OSStatus UserMqttSendTopic(char *topic, char *arg, char retained) {
|
||||||
OSStatus err = kUnknownErr;
|
OSStatus err = kUnknownErr;
|
||||||
p_mqtt_send_msg_t p_send_msg = NULL;
|
p_mqtt_send_msg_t p_send_msg = NULL;
|
||||||
if(mqtt_msg_send_queue == NULL){
|
if(mqtt_msg_send_queue == NULL|| !isconnect){
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,13 +628,13 @@ void UserMqttHassAutoRebootButton(void) {
|
|||||||
"\"uniq_id\":\"tc1_%s_reboot\","
|
"\"uniq_id\":\"tc1_%s_reboot\","
|
||||||
"\"object_id\":\"tc1_%s_reboot\","
|
"\"object_id\":\"tc1_%s_reboot\","
|
||||||
"\"cmd_t\":\"device/ztc1/set\","
|
"\"cmd_t\":\"device/ztc1/set\","
|
||||||
"\"pl_prs\":\"reboot\","
|
"\"pl_prs\":\"reboot %s\","
|
||||||
"\"device\":{"
|
"\"device\":{"
|
||||||
"\"identifiers\":[\"tc1_%s\"],"
|
"\"identifiers\":[\"tc1_%s\"],"
|
||||||
"\"name\":\"%s\","
|
"\"name\":\"%s\","
|
||||||
"\"model\":\"TC1\","
|
"\"model\":\"TC1\","
|
||||||
"\"manufacturer\":\"PHICOMM\"}}",
|
"\"manufacturer\":\"PHICOMM\"}}",
|
||||||
str_mac,str_mac,str_mac, sys_config->micoSystemConfig.name);
|
str_mac,str_mac,str_mac,str_mac, sys_config->micoSystemConfig.name);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 1);
|
UserMqttSendTopic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf) free(send_buf);
|
if (send_buf) free(send_buf);
|
||||||
@@ -775,7 +825,7 @@ void UserMqttHassAutoPower(void) {
|
|||||||
char topic_buf[128] = {0};
|
char topic_buf[128] = {0};
|
||||||
char send_buf[128] = {0};
|
char send_buf[128] = {0};
|
||||||
|
|
||||||
void UserMqttHassPower(void) {
|
extern void UserMqttHassPower(void) {
|
||||||
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
|
sprintf(topic_buf, "homeassistant/sensor/%s/power/state", str_mac);
|
||||||
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power / 10);
|
sprintf(send_buf, "{\"power\":\"%.3f\"}", real_time_power / 10);
|
||||||
UserMqttSendTopic(topic_buf, send_buf, 0);
|
UserMqttSendTopic(topic_buf, send_buf, 0);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#define MQTT_LED_ENABLED user_config->power_led_enabled
|
#define MQTT_LED_ENABLED user_config->power_led_enabled
|
||||||
|
|
||||||
extern OSStatus UserMqttInit(void);
|
extern OSStatus UserMqttInit(void);
|
||||||
|
extern OSStatus UserMqttDeInit(void);
|
||||||
|
|
||||||
extern OSStatus UserMqttSend(char *arg);
|
extern OSStatus UserMqttSend(char *arg);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#define __ota_server_H
|
#define __ota_server_H
|
||||||
|
|
||||||
#define OTA_DEBUG (1)
|
#define OTA_DEBUG (1)
|
||||||
#define OTA_USE_HTTPS (0)
|
#define OTA_USE_HTTPS (1)
|
||||||
|
|
||||||
#define OTA_MD5_LENTH 32
|
#define OTA_MD5_LENTH 32
|
||||||
#define OTA_SEND_HEAD_SIZE 256
|
#define OTA_SEND_HEAD_SIZE 256
|
||||||
@@ -49,8 +49,8 @@ typedef enum _OTA_STATE_E{
|
|||||||
}OTA_STATE_E;
|
}OTA_STATE_E;
|
||||||
|
|
||||||
typedef enum _HTTP_SECURITY_E{
|
typedef enum _HTTP_SECURITY_E{
|
||||||
HTTP_SECURITY_HTTP,
|
HTTP_SECURITY_HTTP,
|
||||||
HTTP_SECURITY_HTTPS
|
HTTP_SECURITY_HTTPS
|
||||||
} HTTP_SECURITY_E;
|
} HTTP_SECURITY_E;
|
||||||
|
|
||||||
typedef enum _OTA_CONTROL_E{
|
typedef enum _OTA_CONTROL_E{
|
||||||
@@ -87,11 +87,11 @@ typedef struct _ota_check_t{
|
|||||||
typedef void (*ota_server_cb_fn) (OTA_STATE_E state, float progress);
|
typedef void (*ota_server_cb_fn) (OTA_STATE_E state, float progress);
|
||||||
|
|
||||||
typedef struct _ota_server_context_t{
|
typedef struct _ota_server_context_t{
|
||||||
download_url_t download_url;
|
download_url_t download_url;
|
||||||
download_state_t download_state;
|
download_state_t download_state;
|
||||||
ota_check_t ota_check;
|
ota_check_t ota_check;
|
||||||
OTA_CONTROL_E ota_control;
|
OTA_CONTROL_E ota_control;
|
||||||
ota_server_cb_fn ota_server_cb;
|
ota_server_cb_fn ota_server_cb;
|
||||||
} ota_server_context_t;
|
} ota_server_context_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -109,34 +109,34 @@ typedef struct _ota_server_context_t{
|
|||||||
* @return kNoErr : on success.
|
* @return kNoErr : on success.
|
||||||
* @return kGeneralErr : if an error occurred
|
* @return kGeneralErr : if an error occurred
|
||||||
*/
|
*/
|
||||||
OSStatus OtaServerStart(char *url, char *md5, ota_server_cb_fn call_back);
|
OSStatus ota_server_start( char *url, char *md5, ota_server_cb_fn call_back );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Get OTA server state
|
/** @brief Get OTA server state
|
||||||
*
|
*
|
||||||
* @return OTA_CONTROL_E : state
|
* @return OTA_CONTROL_E : state
|
||||||
*/
|
*/
|
||||||
OTA_CONTROL_E OtaServerStateGet(void);
|
OTA_CONTROL_E ota_server_state_get( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Pause OTA server daemons
|
/** @brief Pause OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerPause(void);
|
void ota_server_pause( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Continue OTA server daemons
|
/** @brief Continue OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerContinue(void);
|
void ota_server_continue( void );
|
||||||
|
|
||||||
|
|
||||||
/** @brief Stop OTA server daemons
|
/** @brief Stop OTA server daemons
|
||||||
*
|
*
|
||||||
* @return No
|
* @return No
|
||||||
*/
|
*/
|
||||||
void OtaServerStop(void);
|
void ota_server_stop( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -36,6 +36,6 @@ void UserOtaStart(char *url, char *md5)
|
|||||||
{
|
{
|
||||||
ota_progress = 0;
|
ota_progress = 0;
|
||||||
ota_log("ready to ota:%s",url);
|
ota_log("ready to ota:%s",url);
|
||||||
OtaServerStart(url, md5, OtaServerStatusHandler);
|
ota_server_start(url, md5, OtaServerStatusHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ OSStatus UserRtcInit(void)
|
|||||||
/* start rtc client */
|
/* start rtc client */
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
||||||
(mico_thread_function_t) RtcThread,
|
(mico_thread_function_t) RtcThread,
|
||||||
0x1000, 0);
|
0x800, 0);
|
||||||
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
|
require_noerr_string(err, exit, "ERROR: Unable to start the rtc thread.");
|
||||||
|
|
||||||
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
|
if (kNoErr != err) rtc_log("ERROR1, app thread exit err: %d kNoErr[%d]", err, kNoErr);
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ char* get_func_name(char func_code) {
|
|||||||
return "Toggle LED";
|
return "Toggle LED";
|
||||||
case REBOOT_SYSTEM:
|
case REBOOT_SYSTEM:
|
||||||
return "Reboot";
|
return "Reboot";
|
||||||
|
case REBOOT_HTTP:
|
||||||
|
return "REBOOT_HTTP";
|
||||||
case CONFIG_WIFI:
|
case CONFIG_WIFI:
|
||||||
return "WiFi Config";
|
return "WiFi Config";
|
||||||
case RESET_SYSTEM:
|
case RESET_SYSTEM:
|
||||||
@@ -226,10 +228,18 @@ static void KeyEventHandler(int num, boolean longPress) {
|
|||||||
break;
|
break;
|
||||||
MicoSystemReboot();
|
MicoSystemReboot();
|
||||||
break;
|
break;
|
||||||
|
case REBOOT_HTTP:
|
||||||
|
if (childLockEnabled)
|
||||||
|
break;
|
||||||
|
AppHttpdStop();
|
||||||
|
mico_rtos_thread_sleep(1);
|
||||||
|
AppHttpdStart();
|
||||||
|
break;
|
||||||
case CONFIG_WIFI:
|
case CONFIG_WIFI:
|
||||||
if (childLockEnabled)
|
if (childLockEnabled)
|
||||||
break;
|
break;
|
||||||
StartLedBlink(3);
|
StartLedBlink(3);
|
||||||
|
UserMqttDeInit();
|
||||||
micoWlanSuspendStation();
|
micoWlanSuspendStation();
|
||||||
ApInit(true);
|
ApInit(true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#define CONFIG_WIFI 9
|
#define CONFIG_WIFI 9
|
||||||
#define RESET_SYSTEM 10
|
#define RESET_SYSTEM 10
|
||||||
#define SWITCH_CHILD_LOCK_ENABLE 11
|
#define SWITCH_CHILD_LOCK_ENABLE 11
|
||||||
|
#define REBOOT_HTTP 12
|
||||||
|
|
||||||
extern char socket_status[32];
|
extern char socket_status[32];
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "mico_socket.h"
|
#include "mico_socket.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
#include "mqtt_server/user_mqtt_client.h"
|
||||||
|
|
||||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||||
|
|
||||||
@@ -122,6 +123,9 @@ static void WifiLedTimerCallback(void* arg)
|
|||||||
UserLedSet(-1);
|
UserLedSet(-1);
|
||||||
break;
|
break;
|
||||||
case WIFI_STATE_CONNECTED:
|
case WIFI_STATE_CONNECTED:
|
||||||
|
if (!(MQTT_SERVER[0] < 0x20 || MQTT_SERVER[0] > 0x7f || MQTT_SERVER_PORT < 1)){
|
||||||
|
UserMqttInit();
|
||||||
|
}
|
||||||
UserLedSet(0);
|
UserLedSet(0);
|
||||||
mico_rtos_stop_timer(&wifi_led_timer);
|
mico_rtos_stop_timer(&wifi_led_timer);
|
||||||
if (RelayOut()&&user_config->power_led_enabled)
|
if (RelayOut()&&user_config->power_led_enabled)
|
||||||
|
|||||||
@@ -39,17 +39,11 @@ OSStatus system_discovery_init( system_context_t * const inContext )
|
|||||||
init.service_name = "_easylink._tcp.local.";
|
init.service_name = "_easylink._tcp.local.";
|
||||||
|
|
||||||
/* name#xxxxxx.local. */
|
/* name#xxxxxx.local. */
|
||||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
|
snprintf( temp_txt, 100, "%s.local.", inContext->flashContentInRam.micoSystemConfig.name);
|
||||||
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
|
|
||||||
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
|
|
||||||
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
|
|
||||||
init.host_name = (char*)__strdup(temp_txt);
|
init.host_name = (char*)__strdup(temp_txt);
|
||||||
|
|
||||||
/* name#xxxxxx. */
|
/* name#xxxxxx. */
|
||||||
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
|
snprintf( temp_txt, 100, "%s", inContext->flashContentInRam.micoSystemConfig.name);
|
||||||
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
|
|
||||||
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
|
|
||||||
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
|
|
||||||
init.instance_name = (char*)__strdup(temp_txt);
|
init.instance_name = (char*)__strdup(temp_txt);
|
||||||
|
|
||||||
#ifndef MICO_LOCAL_SERVER_PORT
|
#ifndef MICO_LOCAL_SERVER_PORT
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ httpd_state_t httpd_state;
|
|||||||
|
|
||||||
static mico_thread_t httpd_main_thread;
|
static mico_thread_t httpd_main_thread;
|
||||||
|
|
||||||
#define http_server_thread_stack_size 0x2000
|
// 0x8000 不行
|
||||||
|
#define http_server_thread_stack_size 0x6000
|
||||||
|
|
||||||
/* Why HTTPD_MAX_MESSAGE + 2?
|
/* Why HTTPD_MAX_MESSAGE + 2?
|
||||||
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.
|
* Handlers are allowed to use HTTPD_MAX_MESSAGE bytes of this buffer.
|
||||||
|
|||||||
@@ -1125,6 +1125,8 @@ int httpd_parse_hdr_tags(httpd_request_t *req, int sock,
|
|||||||
*/
|
*/
|
||||||
int httpd_get_data(httpd_request_t *req, char *content, int length);
|
int httpd_get_data(httpd_request_t *req, char *content, int length);
|
||||||
|
|
||||||
|
int httpd_get_data2(httpd_request_t *req, char *content, int length);
|
||||||
|
|
||||||
/** @brief Get the incoming JSON data in case of HTTP POST request
|
/** @brief Get the incoming JSON data in case of HTTP POST request
|
||||||
*
|
*
|
||||||
* @note This function is an extension to \ref httpd_get_data. Additionally this
|
* @note This function is an extension to \ref httpd_get_data. Additionally this
|
||||||
|
|||||||
@@ -58,173 +58,203 @@ static httpd_request_t httpd_req;
|
|||||||
int httpd_send_chunk_begin(int conn, int size)
|
int httpd_send_chunk_begin(int conn, int size)
|
||||||
{
|
{
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
char buf[CHUNK_SIZE_DIGITS];
|
char buf[CHUNK_SIZE_DIGITS];
|
||||||
int i;
|
int i;
|
||||||
int digit;
|
int digit;
|
||||||
int begin = 1;
|
int begin = 1;
|
||||||
|
|
||||||
for (i = CHUNK_SIZE_DIGITS - 1; i >= 0; i--) {
|
for (i = CHUNK_SIZE_DIGITS - 1; i >= 0; i--) {
|
||||||
digit = size & 0xf;
|
digit = size & 0xf;
|
||||||
if (!begin && !size) {
|
if (!begin && !size) {
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf[i] = (digit > 9) ? digit - 0xA + 'a' : digit + '0';
|
buf[i] = (digit > 9) ? digit - 0xA + 'a' : digit + '0';
|
||||||
size = size >> 4;
|
size = size >> 4;
|
||||||
begin = 0;
|
begin = 0;
|
||||||
}
|
}
|
||||||
err = httpd_send(conn, &buf[i], CHUNK_SIZE_DIGITS - i);
|
err = httpd_send(conn, &buf[i], CHUNK_SIZE_DIGITS - i);
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = httpd_send_crlf(conn);
|
err = httpd_send_crlf(conn);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the last chunk which is simply an ascii "0\r\n\r\n"
|
/* Send the last chunk which is simply an ascii "0\r\n\r\n"
|
||||||
*/
|
*/
|
||||||
int httpd_send_last_chunk(int conn)
|
int httpd_send_last_chunk(int conn)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = httpd_send(conn, http_last_chunk,
|
err = httpd_send(conn, http_last_chunk,
|
||||||
sizeof(http_last_chunk) - 1);
|
sizeof(http_last_chunk) - 1);
|
||||||
|
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
httpd_d("Send last chunk failed");
|
httpd_d("Send last chunk failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send one chunk of data of a given size
|
/* Send one chunk of data of a given size
|
||||||
*/
|
*/
|
||||||
int httpd_send_chunk(int conn, const char *buf, int len)
|
int httpd_send_chunk(int conn, const char *buf, int len)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
/* Send chunk begin header */
|
/* Send chunk begin header */
|
||||||
err = httpd_send_chunk_begin(conn, len);
|
err = httpd_send_chunk_begin(conn, len);
|
||||||
if (err != kNoErr)
|
if (err != kNoErr)
|
||||||
return err;
|
return err;
|
||||||
/* Send our data */
|
/* Send our data */
|
||||||
err = httpd_send(conn, buf, len);
|
err = httpd_send(conn, buf, len);
|
||||||
if (err != kNoErr)
|
if (err != kNoErr)
|
||||||
return err;
|
return err;
|
||||||
/* Send chunk end indicator */
|
/* Send chunk end indicator */
|
||||||
err = httpd_send_crlf(conn);
|
err = httpd_send_crlf(conn);
|
||||||
if (err != kNoErr)
|
if (err != kNoErr)
|
||||||
return err;
|
return err;
|
||||||
} else {
|
} else {
|
||||||
/* Length is 0, last chunk */
|
/* Length is 0, last chunk */
|
||||||
err = httpd_send(conn, http_last_chunk,
|
err = httpd_send(conn, http_last_chunk,
|
||||||
sizeof(http_last_chunk) - 1);
|
sizeof(http_last_chunk) - 1);
|
||||||
if (err != kNoErr)
|
if (err != kNoErr)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Helper function to send a buffer over a connection.
|
/*Helper function to send a buffer over a connection.
|
||||||
*/
|
*/
|
||||||
int httpd_send(int conn, const char *buf, int len)
|
int httpd_send(int conn, const char *buf, int len)
|
||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
do {
|
struct timeval t;
|
||||||
|
fd_set writefds;
|
||||||
|
|
||||||
|
t.tv_sec = 0;
|
||||||
|
t.tv_usec = 200*1000;
|
||||||
|
|
||||||
|
do {
|
||||||
#ifdef CONFIG_ENABLE_HTTPS
|
#ifdef CONFIG_ENABLE_HTTPS
|
||||||
if (httpd_is_https_active())
|
if (httpd_is_https_active())
|
||||||
num = tls_send(httpd_tls_handle, buf, len);
|
num = tls_send(httpd_tls_handle, buf, len);
|
||||||
else
|
else
|
||||||
#endif /* ENABLE_HTTPS */
|
#endif /* ENABLE_HTTPS */
|
||||||
num = send(conn, buf, len, 0);
|
FD_ZERO( &writefds );
|
||||||
if (num < 0) {
|
FD_SET( conn, &writefds );
|
||||||
httpd_d("send() failed: %d" ,conn);
|
|
||||||
return -kInProgressErr;
|
select( conn + 1, NULL, &writefds, NULL, &t );
|
||||||
}
|
if( FD_ISSET( conn, &writefds) )
|
||||||
len -= num;
|
{
|
||||||
buf += num;
|
num = send(conn, buf, len, 0);
|
||||||
} while (len > 0);
|
if (num < 0) {
|
||||||
|
httpd_d("send() failed: %d" ,conn);
|
||||||
|
return -kInProgressErr;
|
||||||
|
}
|
||||||
|
len -= num;
|
||||||
|
buf += num;
|
||||||
|
}
|
||||||
|
} while (len > 0);
|
||||||
|
|
||||||
|
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int httpd_recv(int fd, void *buf, size_t n, int flags)
|
int httpd_recv(int fd, void *buf, size_t n, int flags)
|
||||||
{
|
{
|
||||||
|
int len = 0;
|
||||||
|
struct timeval t;
|
||||||
|
fd_set readfds;
|
||||||
|
|
||||||
|
FD_ZERO( &readfds );
|
||||||
|
FD_SET( fd, &readfds );
|
||||||
|
|
||||||
|
t.tv_sec = 0;
|
||||||
|
t.tv_usec = 200*1000;
|
||||||
|
|
||||||
#ifdef CONFIG_ENABLE_HTTPS
|
#ifdef CONFIG_ENABLE_HTTPS
|
||||||
if (httpd_is_https_active())
|
if (httpd_is_https_active())
|
||||||
return tls_recv(httpd_tls_handle, buf, n);
|
return tls_recv(httpd_tls_handle, buf, n);
|
||||||
else
|
else
|
||||||
#endif /* ENABLE_HTTPS */
|
#endif /* ENABLE_HTTPS */
|
||||||
return recv(fd, buf, n, flags);
|
return recv(fd, buf, n, flags);
|
||||||
|
select( fd + 1, &readfds, NULL, NULL, &t );
|
||||||
|
|
||||||
|
if( FD_ISSET( fd, &readfds) )
|
||||||
|
{
|
||||||
|
len = recv( fd, buf, n, flags );
|
||||||
|
}
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int httpd_send_hdr_from_code(int sock, int stat_code,
|
int httpd_send_hdr_from_code(int sock, int stat_code,
|
||||||
enum http_content_type content_type)
|
enum http_content_type content_type)
|
||||||
{
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
unsigned int str_len;
|
unsigned int str_len;
|
||||||
/*
|
/*
|
||||||
* Set the HTTP Response Status 200 OK, 404 NOT FOUND etc.
|
* Set the HTTP Response Status 200 OK, 404 NOT FOUND etc.
|
||||||
* Also set the Transfer-Encoding to chunked.
|
* Also set the Transfer-Encoding to chunked.
|
||||||
*/
|
*/
|
||||||
switch (stat_code) {
|
switch (stat_code) {
|
||||||
case -WM_E_HTTPD_HANDLER_404:
|
case -WM_E_HTTPD_HANDLER_404:
|
||||||
str = http_header_404;
|
str = http_header_404;
|
||||||
str_len = strlen(http_header_404);
|
str_len = strlen(http_header_404);
|
||||||
break;
|
break;
|
||||||
case -WM_E_HTTPD_HANDLER_400:
|
case -WM_E_HTTPD_HANDLER_400:
|
||||||
str = http_header_400;
|
str = http_header_400;
|
||||||
str_len = strlen(http_header_400);
|
str_len = strlen(http_header_400);
|
||||||
break;
|
break;
|
||||||
case -WM_E_HTTPD_HANDLER_500:
|
case -WM_E_HTTPD_HANDLER_500:
|
||||||
str = http_header_500;
|
str = http_header_500;
|
||||||
str_len = strlen(http_header_500);
|
str_len = strlen(http_header_500);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* The handler doesn't want an HTTP error code, but would return
|
/* The handler doesn't want an HTTP error code, but would return
|
||||||
* 200 OK with an error in the response */
|
* 200 OK with an error in the response */
|
||||||
str = http_header_200;
|
str = http_header_200;
|
||||||
str_len = strlen(http_header_200);
|
str_len = strlen(http_header_200);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpd_send(sock, str, str_len) != kNoErr) {
|
if (httpd_send(sock, str, str_len) != kNoErr) {
|
||||||
return -kInProgressErr;
|
return -kInProgressErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send the Content-Type */
|
/* Send the Content-Type */
|
||||||
switch (content_type) {
|
switch (content_type) {
|
||||||
case HTTP_CONTENT_JSON:
|
case HTTP_CONTENT_JSON:
|
||||||
str = http_content_type_json_nocache;
|
str = http_content_type_json_nocache;
|
||||||
str_len = sizeof(http_content_type_json_nocache) - 1;
|
str_len = sizeof(http_content_type_json_nocache) - 1;
|
||||||
break;
|
break;
|
||||||
case HTTP_CONTENT_XML:
|
case HTTP_CONTENT_XML:
|
||||||
str = http_content_type_xml_nocache;
|
str = http_content_type_xml_nocache;
|
||||||
str_len = sizeof(http_content_type_xml_nocache) - 1;
|
str_len = sizeof(http_content_type_xml_nocache) - 1;
|
||||||
break;
|
break;
|
||||||
case HTTP_CONTENT_HTML:
|
case HTTP_CONTENT_HTML:
|
||||||
str = http_content_type_html;
|
str = http_content_type_html;
|
||||||
str_len = sizeof(http_content_type_html) - 1;
|
str_len = sizeof(http_content_type_html) - 1;
|
||||||
break;
|
break;
|
||||||
case HTTP_CONTENT_JPEG:
|
case HTTP_CONTENT_JPEG:
|
||||||
str = http_content_type_jpg;
|
str = http_content_type_jpg;
|
||||||
str_len = sizeof(http_content_type_jpg) - 1;
|
str_len = sizeof(http_content_type_jpg) - 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
str = http_content_type_plain;
|
str = http_content_type_plain;
|
||||||
str_len = sizeof(http_content_type_plain) - 1;
|
str_len = sizeof(http_content_type_plain) - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (httpd_send(sock, str, str_len) != kNoErr) {
|
if (httpd_send(sock, str, str_len) != kNoErr) {
|
||||||
return -kInProgressErr;
|
return -kInProgressErr;
|
||||||
}
|
}
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -234,62 +264,62 @@ static char httpd_error[HTTPD_MAX_ERROR_STRING + 1];
|
|||||||
void httpd_set_error(const char *fmt, ...)
|
void httpd_set_error(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
|
|
||||||
va_start(argp, fmt);
|
va_start(argp, fmt);
|
||||||
vsnprintf(httpd_error, HTTPD_MAX_ERROR_STRING + 1, fmt, argp);
|
vsnprintf(httpd_error, HTTPD_MAX_ERROR_STRING + 1, fmt, argp);
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
httpd_d("http set err");
|
httpd_d("http set err");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function to send an error.
|
/* Helper function to send an error.
|
||||||
*/
|
*/
|
||||||
int httpd_send_error(int conn, int http_error)
|
int httpd_send_error(int conn, int http_error)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
switch (http_error) {
|
switch (http_error) {
|
||||||
case HTTP_404:
|
case HTTP_404:
|
||||||
err = httpd_send(conn, http_header_404,
|
err = httpd_send(conn, http_header_404,
|
||||||
strlen(http_header_404));
|
strlen(http_header_404));
|
||||||
break;
|
break;
|
||||||
case HTTP_500:
|
case HTTP_500:
|
||||||
err = httpd_send(conn, http_header_500,
|
err = httpd_send(conn, http_header_500,
|
||||||
strlen(http_header_500));
|
strlen(http_header_500));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HTTP_505:
|
case HTTP_505:
|
||||||
err = httpd_send(conn, http_header_505,
|
err = httpd_send(conn, http_header_505,
|
||||||
strlen(http_header_505));
|
strlen(http_header_505));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = httpd_send(conn, http_header_type_chunked,
|
err = httpd_send(conn, http_header_type_chunked,
|
||||||
strlen(http_header_type_chunked));
|
strlen(http_header_type_chunked));
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = httpd_send(conn, http_content_type_plain,
|
err = httpd_send(conn, http_content_type_plain,
|
||||||
sizeof(http_content_type_plain) - 1);
|
sizeof(http_content_type_plain) - 1);
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = httpd_send_crlf(conn);
|
err = httpd_send_crlf(conn);
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = httpd_send_chunk(conn, httpd_error, strlen(httpd_error));
|
err = httpd_send_chunk(conn, httpd_error, strlen(httpd_error));
|
||||||
if (err != kNoErr) {
|
if (err != kNoErr) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
return httpd_send_last_chunk(conn);
|
return httpd_send_last_chunk(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -299,28 +329,28 @@ int httpd_send_error(int conn, int http_error)
|
|||||||
* data after that.
|
* data after that.
|
||||||
*/
|
*/
|
||||||
void httpd_purge_socket_data(httpd_request_t *req, char *msg_in,
|
void httpd_purge_socket_data(httpd_request_t *req, char *msg_in,
|
||||||
int msg_in_len, int conn)
|
int msg_in_len, int conn)
|
||||||
{
|
{
|
||||||
int status = httpd_parse_hdr_tags(req, conn, msg_in, msg_in_len);
|
int status = httpd_parse_hdr_tags(req, conn, msg_in, msg_in_len);
|
||||||
if (status != kNoErr) {
|
if (status != kNoErr) {
|
||||||
/* We were unsuccessful in purging the socket.*/
|
/* We were unsuccessful in purging the socket.*/
|
||||||
httpd_d("Unable to purge socket: %d", status);
|
httpd_d("Unable to purge socket: %d", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned data_remaining = req->body_nbytes;
|
unsigned data_remaining = req->body_nbytes;
|
||||||
|
|
||||||
while (data_remaining) {
|
while (data_remaining) {
|
||||||
unsigned to_read = msg_in_len >= data_remaining ?
|
unsigned to_read = msg_in_len >= data_remaining ?
|
||||||
data_remaining : msg_in_len;
|
data_remaining : msg_in_len;
|
||||||
int actually_read = httpd_recv(conn, msg_in, to_read, 0);
|
int actually_read = httpd_recv(conn, msg_in, to_read, 0);
|
||||||
if (actually_read < 0) {
|
if (actually_read < 0) {
|
||||||
httpd_d("Unable to read content."
|
httpd_d("Unable to read content."
|
||||||
"Was purging socket data");
|
"Was purging socket data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data_remaining -= actually_read;
|
data_remaining -= actually_read;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle an incoming message (request) from the client. This is the
|
/* Handle an incoming message (request) from the client. This is the
|
||||||
@@ -328,72 +358,72 @@ void httpd_purge_socket_data(httpd_request_t *req, char *msg_in,
|
|||||||
*/
|
*/
|
||||||
int httpd_handle_message(int conn)
|
int httpd_handle_message(int conn)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int req_line_len;
|
int req_line_len;
|
||||||
char msg_in[128];
|
char msg_in[128];
|
||||||
|
|
||||||
/* clear out the httpd_req structure */
|
/* clear out the httpd_req structure */
|
||||||
memset(&httpd_req, 0x00, sizeof(httpd_req));
|
memset(&httpd_req, 0x00, sizeof(httpd_req));
|
||||||
|
|
||||||
httpd_req.sock = conn;
|
httpd_req.sock = conn;
|
||||||
|
|
||||||
/* Read the first line of the HTTP header */
|
/* Read the first line of the HTTP header */
|
||||||
req_line_len = htsys_getln_soc(conn, msg_in, sizeof(msg_in));
|
req_line_len = htsys_getln_soc(conn, msg_in, sizeof(msg_in));
|
||||||
if (req_line_len == 0)
|
if (req_line_len == 0)
|
||||||
return HTTPD_DONE;
|
return HTTPD_DONE;
|
||||||
|
|
||||||
if (req_line_len < 0) {
|
if (req_line_len < 0) {
|
||||||
httpd_d("Could not read from socket");
|
httpd_d("Could not read from socket");
|
||||||
return -kInProgressErr;
|
return -kInProgressErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the first line of the header */
|
/* Parse the first line of the header */
|
||||||
err = httpd_parse_hdr_main(msg_in, &httpd_req);
|
err = httpd_parse_hdr_main(msg_in, &httpd_req);
|
||||||
if (err == -WM_E_HTTPD_NOTSUPP)
|
if (err == -WM_E_HTTPD_NOTSUPP)
|
||||||
/* Send 505 HTTP Version not supported */
|
/* Send 505 HTTP Version not supported */
|
||||||
return httpd_send_error(conn, HTTP_505);
|
return httpd_send_error(conn, HTTP_505);
|
||||||
else if (err != kNoErr) {
|
else if (err != kNoErr) {
|
||||||
/* Send 500 Internal Server Error */
|
/* Send 500 Internal Server Error */
|
||||||
return httpd_send_error(conn, HTTP_500);
|
return httpd_send_error(conn, HTTP_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set a generic error that can be overridden by the wsgi handling. */
|
/* set a generic error that can be overridden by the wsgi handling. */
|
||||||
httpd_d("Presetting");
|
httpd_d("Presetting");
|
||||||
|
|
||||||
/* Web Services Gateway Interface branch point:
|
/* Web Services Gateway Interface branch point:
|
||||||
* At this point we have the request type (httpd_req.type) and the path
|
* At this point we have the request type (httpd_req.type) and the path
|
||||||
* (httpd_req.filename) and all the headers waiting to be read from
|
* (httpd_req.filename) and all the headers waiting to be read from
|
||||||
* the socket.
|
* the socket.
|
||||||
*
|
*
|
||||||
* The call bellow will iterate through all the url patterns and
|
* The call bellow will iterate through all the url patterns and
|
||||||
* invoke the handlers that match the request type and pattern. If
|
* invoke the handlers that match the request type and pattern. If
|
||||||
* request type and url patern match, invoke the handler.
|
* request type and url patern match, invoke the handler.
|
||||||
*/
|
*/
|
||||||
err = httpd_wsgi(&httpd_req);
|
err = httpd_wsgi(&httpd_req);
|
||||||
|
|
||||||
if (err == HTTPD_DONE) {
|
if (err == HTTPD_DONE) {
|
||||||
httpd_d("Done processing request.");
|
httpd_d("Done processing request.");
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
} else if (err == -WM_E_HTTPD_NO_HANDLER) {
|
} else if (err == -WM_E_HTTPD_NO_HANDLER) {
|
||||||
httpd_d("No handler for the given URL %s was found",
|
httpd_d("No handler for the given URL %s was found",
|
||||||
httpd_req.filename);
|
httpd_req.filename);
|
||||||
/*
|
/*
|
||||||
* We have not yet read the complete data from the current
|
* We have not yet read the complete data from the current
|
||||||
* request, from the socket. We are in an error state and
|
* request, from the socket. We are in an error state and
|
||||||
* we wish to cancel this HTTP transaction. We sent
|
* we wish to cancel this HTTP transaction. We sent
|
||||||
* appropriate message to the client and read (flush) out
|
* appropriate message to the client and read (flush) out
|
||||||
* all the pending data in the socket. We let the client
|
* all the pending data in the socket. We let the client
|
||||||
* close the socket for us, if necessary.
|
* close the socket for us, if necessary.
|
||||||
*/
|
*/
|
||||||
httpd_purge_socket_data(&httpd_req, msg_in,
|
httpd_purge_socket_data(&httpd_req, msg_in,
|
||||||
sizeof(msg_in), conn);
|
sizeof(msg_in), conn);
|
||||||
httpd_set_error("File %s not_found", httpd_req.filename);
|
httpd_set_error("File %s not_found", httpd_req.filename);
|
||||||
httpd_send_error(conn, HTTP_404);
|
httpd_send_error(conn, HTTP_404);
|
||||||
return kNoErr;
|
return kNoErr;
|
||||||
} else {
|
} else {
|
||||||
httpd_d("WSGI handler failed.");
|
httpd_d("WSGI handler failed.");
|
||||||
/* Send 500 Internal Server Error */
|
/* Send 500 Internal Server Error */
|
||||||
return httpd_send_error(conn, HTTP_500);
|
return httpd_send_error(conn, HTTP_500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -543,6 +543,52 @@ out:
|
|||||||
return req->remaining_bytes;
|
return req->remaining_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int httpd_get_data2(httpd_request_t *req, char *content, int length)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
// /* Is this condition required? */
|
||||||
|
// if (req->body_nbytes >= HTTPD_MAX_MESSAGE - 2)
|
||||||
|
// return -kInProgressErr;
|
||||||
|
|
||||||
|
if (!req->hdr_parsed) {
|
||||||
|
buf = malloc(HTTPD_MAX_MESSAGE);
|
||||||
|
if (!buf) {
|
||||||
|
system_log("Failed to allocate memory for buffer");
|
||||||
|
return -kInProgressErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = httpd_parse_hdr_tags(req, req->sock, buf,
|
||||||
|
HTTPD_MAX_MESSAGE);
|
||||||
|
|
||||||
|
if (ret != kNoErr) {
|
||||||
|
system_log("Unable to parse header tags");
|
||||||
|
goto out;
|
||||||
|
} else {
|
||||||
|
system_log("Headers parsed successfully\r\n");
|
||||||
|
req->hdr_parsed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle here */
|
||||||
|
ret = httpd_recv(req->sock, content,
|
||||||
|
length, 0);
|
||||||
|
if (ret == -1) {
|
||||||
|
system_log("Failed to read POST data");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
/* scratch will now have the JSON data */
|
||||||
|
// content[ret] = '\0';
|
||||||
|
req->remaining_bytes -= ret;
|
||||||
|
system_log("Read %d bytes and remaining %d bytes",
|
||||||
|
ret, req->remaining_bytes);
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int get_matching_chars(const char *s1, const char *s2)
|
static int get_matching_chars(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
int match = 0;
|
int match = 0;
|
||||||
|
|||||||
@@ -56,21 +56,21 @@ static OSStatus onReceivedData( struct _HTTPHeader_t * httpHeader,
|
|||||||
|
|
||||||
static void hex2str(uint8_t *hex, int hex_len, char *str)
|
static void hex2str(uint8_t *hex, int hex_len, char *str)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(i=0; i<hex_len; i++){
|
for(i=0; i<hex_len; i++){
|
||||||
sprintf(str+i*2, "%02x", hex[i]);
|
sprintf(str+i*2, "%02x", hex[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void upper2lower(char *str, int len)
|
static void upper2lower(char *str, int len)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(i=0; i<len; i++)
|
for(i=0; i<len; i++)
|
||||||
{
|
{
|
||||||
if( (*(str+i) >= 'A') && (*(str+i) <= 'Z') ){
|
if( (*(str+i) >= 'A') && (*(str+i) <= 'Z') ){
|
||||||
*(str+i) += 32;
|
*(str+i) += 32;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ota_server_send( uint8_t *data, int datalen )
|
static int ota_server_send( uint8_t *data, int datalen )
|
||||||
@@ -104,7 +104,7 @@ static OSStatus ota_server_connect( struct sockaddr_in *addr, socklen_t addrlen
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ static void ota_server_thread( mico_thread_arg_t arg )
|
|||||||
struct in_addr in_addr;
|
struct in_addr in_addr;
|
||||||
|
|
||||||
mico_logic_partition_t* ota_partition = MicoFlashGetInfo( MICO_PARTITION_OTA_TEMP );
|
mico_logic_partition_t* ota_partition = MicoFlashGetInfo( MICO_PARTITION_OTA_TEMP );
|
||||||
|
|
||||||
ota_server_context->ota_control = OTA_CONTROL_START;
|
ota_server_context->ota_control = OTA_CONTROL_START;
|
||||||
|
|
||||||
hostent_content = gethostbyname( ota_server_context->download_url.host );
|
hostent_content = gethostbyname( ota_server_context->download_url.host );
|
||||||
@@ -256,12 +256,12 @@ static void ota_server_thread( mico_thread_arg_t arg )
|
|||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length );
|
MicoFlashErase( MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length );
|
||||||
|
|
||||||
CRC16_Init( &crc_context );
|
CRC16_Init( &crc_context );
|
||||||
if( ota_server_context->ota_check.is_md5 == true ){
|
if( ota_server_context->ota_check.is_md5 == true ){
|
||||||
InitMd5( &md5 );
|
InitMd5( &md5 );
|
||||||
}
|
}
|
||||||
|
|
||||||
httpHeader = HTTPHeaderCreateWithCallback( 1024, onReceivedData, NULL, NULL );
|
httpHeader = HTTPHeaderCreateWithCallback( 1024, onReceivedData, NULL, NULL );
|
||||||
require_action( httpHeader, DELETE, ota_server_progress_set(OTA_FAIL) );
|
require_action( httpHeader, DELETE, ota_server_progress_set(OTA_FAIL) );
|
||||||
|
|
||||||
@@ -334,13 +334,13 @@ static void ota_server_thread( mico_thread_arg_t arg )
|
|||||||
goto DELETE;
|
goto DELETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECONNECTED:
|
RECONNECTED:
|
||||||
ota_server_socket_close( );
|
ota_server_socket_close( );
|
||||||
mico_thread_sleep(2);
|
mico_thread_sleep(2);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
DELETE:
|
DELETE:
|
||||||
HTTPHeaderDestory( &httpHeader );
|
HTTPHeaderDestory( &httpHeader );
|
||||||
ota_server_socket_close( );
|
ota_server_socket_close( );
|
||||||
if( ota_server_context != NULL ){
|
if( ota_server_context != NULL ){
|
||||||
@@ -421,7 +421,7 @@ static OSStatus ota_server_set_url( char *url )
|
|||||||
strcpy( ota_server_context->download_url.url, pos );
|
strcpy( ota_server_context->download_url.url, pos );
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
url_free( url_t );
|
url_free( url_t );
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -461,7 +461,7 @@ OSStatus ota_server_start( char *url, char *md5, ota_server_cb_fn call_back )
|
|||||||
ota_server_context->ota_server_cb = call_back;
|
ota_server_context->ota_server_cb = call_back;
|
||||||
|
|
||||||
err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY, "OTA", ota_server_thread, OTA_SERVER_THREAD_STACK_SIZE, 0 );
|
err = mico_rtos_create_thread( NULL, MICO_APPLICATION_PRIORITY, "OTA", ota_server_thread, OTA_SERVER_THREAD_STACK_SIZE, 0 );
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,4 +483,4 @@ void ota_server_stop( void )
|
|||||||
OTA_CONTROL_E ota_server_get( void )
|
OTA_CONTROL_E ota_server_get( void )
|
||||||
{
|
{
|
||||||
return ota_server_context->ota_control;
|
return ota_server_context->ota_control;
|
||||||
}
|
}
|
||||||
@@ -49,8 +49,8 @@ typedef enum _OTA_STATE_E{
|
|||||||
}OTA_STATE_E;
|
}OTA_STATE_E;
|
||||||
|
|
||||||
typedef enum _HTTP_SECURITY_E{
|
typedef enum _HTTP_SECURITY_E{
|
||||||
HTTP_SECURITY_HTTP,
|
HTTP_SECURITY_HTTP,
|
||||||
HTTP_SECURITY_HTTPS
|
HTTP_SECURITY_HTTPS
|
||||||
} HTTP_SECURITY_E;
|
} HTTP_SECURITY_E;
|
||||||
|
|
||||||
typedef enum _OTA_CONTROL_E{
|
typedef enum _OTA_CONTROL_E{
|
||||||
@@ -87,11 +87,11 @@ typedef struct _ota_check_t{
|
|||||||
typedef void (*ota_server_cb_fn) (OTA_STATE_E state, float progress);
|
typedef void (*ota_server_cb_fn) (OTA_STATE_E state, float progress);
|
||||||
|
|
||||||
typedef struct _ota_server_context_t{
|
typedef struct _ota_server_context_t{
|
||||||
download_url_t download_url;
|
download_url_t download_url;
|
||||||
download_state_t download_state;
|
download_state_t download_state;
|
||||||
ota_check_t ota_check;
|
ota_check_t ota_check;
|
||||||
OTA_CONTROL_E ota_control;
|
OTA_CONTROL_E ota_control;
|
||||||
ota_server_cb_fn ota_server_cb;
|
ota_server_cb_fn ota_server_cb;
|
||||||
} ota_server_context_t;
|
} ota_server_context_t;
|
||||||
|
|
||||||
|
|
||||||
@@ -139,4 +139,4 @@ void ota_server_continue( void );
|
|||||||
*/
|
*/
|
||||||
void ota_server_stop( void );
|
void ota_server_stop( void );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -40,33 +40,35 @@
|
|||||||
#include "URLUtils.h"
|
#include "URLUtils.h"
|
||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
|
|
||||||
|
#define Boolean bool
|
||||||
|
|
||||||
#define kHTTPPostMethod "POST"
|
#define kHTTPPostMethod "POST"
|
||||||
|
|
||||||
// Status-Code =
|
// Status-Code =
|
||||||
// "100" ; Section 10.1.1: Continue
|
// "100" ; Section 10.1.1: Continue
|
||||||
// | "101" ; Section 10.1.2: Switching Protocols
|
// | "101" ; Section 10.1.2: Switching Protocols
|
||||||
// | "200" ; Section 10.2.1: OK
|
// | "200" ; Section 10.2.1: OK
|
||||||
// | "201" ; Section 10.2.2: Created
|
// | "201" ; Section 10.2.2: Created
|
||||||
// | "202" ; Section 10.2.3: Accepted
|
// | "202" ; Section 10.2.3: Accepted
|
||||||
// | "203" ; Section 10.2.4: Non-Authoritative Information
|
// | "203" ; Section 10.2.4: Non-Authoritative Information
|
||||||
// | "204" ; Section 10.2.5: No Content
|
// | "204" ; Section 10.2.5: No Content
|
||||||
// | "205" ; Section 10.2.6: Reset Content
|
// | "205" ; Section 10.2.6: Reset Content
|
||||||
// | "206" ; Section 10.2.7: Partial Content
|
// | "206" ; Section 10.2.7: Partial Content
|
||||||
// | "207" ; ??? : Multi-Status
|
// | "207" ; ??? : Multi-Status
|
||||||
// | "300" ; Section 10.3.1: Multiple Choices
|
// | "300" ; Section 10.3.1: Multiple Choices
|
||||||
// | "301" ; Section 10.3.2: Moved Permanently
|
// | "301" ; Section 10.3.2: Moved Permanently
|
||||||
// | "302" ; Section 10.3.3: Found
|
// | "302" ; Section 10.3.3: Found
|
||||||
// | "303" ; Section 10.3.4: See Other
|
// | "303" ; Section 10.3.4: See Other
|
||||||
// | "304" ; Section 10.3.5: Not Modified
|
// | "304" ; Section 10.3.5: Not Modified
|
||||||
// | "305" ; Section 10.3.6: Use Proxy
|
// | "305" ; Section 10.3.6: Use Proxy
|
||||||
// | "307" ; Section 10.3.8: Temporary Redirect
|
// | "307" ; Section 10.3.8: Temporary Redirect
|
||||||
// | "400" ; Section 10.4.1: Bad Request
|
// | "400" ; Section 10.4.1: Bad Request
|
||||||
// | "401" ; Section 10.4.2: Unauthorized
|
// | "401" ; Section 10.4.2: Unauthorized
|
||||||
// | "402" ; Section 10.4.3: Payment Required
|
// | "402" ; Section 10.4.3: Payment Required
|
||||||
// | "403" ; Section 10.4.4: Forbidden
|
// | "403" ; Section 10.4.4: Forbidden
|
||||||
// | "404" ; Section 10.4.5: Not Found
|
// | "404" ; Section 10.4.5: Not Found
|
||||||
// | "405" ; Section 10.4.6: Method Not Allowed
|
// | "405" ; Section 10.4.6: Method Not Allowed
|
||||||
// | "406" ; Section 10.4.7: Not Acceptable
|
// | "406" ; Section 10.4.7: Not Acceptable
|
||||||
|
|
||||||
|
|
||||||
#define kStatusAccept 202
|
#define kStatusAccept 202
|
||||||
@@ -76,9 +78,9 @@
|
|||||||
#define kStatusBadRequest 400
|
#define kStatusBadRequest 400
|
||||||
#define kStatusNotFound 404
|
#define kStatusNotFound 404
|
||||||
#define kStatusMethodNotAllowed 405
|
#define kStatusMethodNotAllowed 405
|
||||||
#define kStatusForbidden 403
|
#define kStatusForbidden 403
|
||||||
#define kStatusAuthenticationErr 470
|
#define kStatusAuthenticationErr 470
|
||||||
#define kStatusInternalServerErr 500
|
#define kStatusInternalServerErr 500
|
||||||
|
|
||||||
#define kMIMEType_Binary "application/octet-stream"
|
#define kMIMEType_Binary "application/octet-stream"
|
||||||
#define kMIMEType_DMAP "application/x-dmap-tagged"
|
#define kMIMEType_DMAP "application/x-dmap-tagged"
|
||||||
@@ -130,7 +132,7 @@ typedef struct _HTTPHeader_t
|
|||||||
|
|
||||||
void * userContext;
|
void * userContext;
|
||||||
bool isCallbackSupported;
|
bool isCallbackSupported;
|
||||||
OSStatus (*onReceivedDataCallback) ( struct _HTTPHeader_t * , uint32_t, uint8_t *, size_t, void * );
|
OSStatus (*onReceivedDataCallback) ( struct _HTTPHeader_t * , uint32_t, uint8_t *, size_t, void * );
|
||||||
void (*onClearCallback) ( struct _HTTPHeader_t * httpHeader, void * userContext );
|
void (*onClearCallback) ( struct _HTTPHeader_t * httpHeader, void * userContext );
|
||||||
|
|
||||||
|
|
||||||
@@ -168,14 +170,14 @@ int HTTPHeaderMatchURL( HTTPHeader_t *inHeader, const char *url );
|
|||||||
char* HTTPHeaderMatchPartialURL( HTTPHeader_t *inHeader, const char *url );
|
char* HTTPHeaderMatchPartialURL( HTTPHeader_t *inHeader, const char *url );
|
||||||
|
|
||||||
|
|
||||||
int HTTPGetHeaderField( const char *inHeaderPtr,
|
int HTTPGetHeaderField( const char *inHeaderPtr,
|
||||||
size_t inHeaderLen,
|
size_t inHeaderLen,
|
||||||
const char *inName,
|
const char *inName,
|
||||||
const char **outNamePtr,
|
const char **outNamePtr,
|
||||||
size_t *outNameLen,
|
size_t *outNameLen,
|
||||||
const char **outValuePtr,
|
const char **outValuePtr,
|
||||||
size_t *outValueLen,
|
size_t *outValueLen,
|
||||||
const char **outNext );
|
const char **outNext );
|
||||||
|
|
||||||
HTTPHeader_t * HTTPHeaderCreate( size_t bufLen );
|
HTTPHeader_t * HTTPHeaderCreate( size_t bufLen );
|
||||||
|
|
||||||
@@ -196,10 +198,9 @@ OSStatus CreateHTTPRespondMessageNoCopy( int status, const char *contentType, si
|
|||||||
OSStatus CreateHTTPMessage( const char *methold, const char *url, const char *contentType, uint8_t *inData, size_t inDataLen, uint8_t **outMessage, size_t *outMessageSize );
|
OSStatus CreateHTTPMessage( const char *methold, const char *url, const char *contentType, uint8_t *inData, size_t inDataLen, uint8_t **outMessage, size_t *outMessageSize );
|
||||||
|
|
||||||
OSStatus CreateHTTPMessageWithHost( const char *methold, const char *url,
|
OSStatus CreateHTTPMessageWithHost( const char *methold, const char *url,
|
||||||
const char* host, uint16_t port,
|
const char* host, uint16_t port,
|
||||||
const char *contentType,
|
const char *contentType,
|
||||||
uint8_t *inData, size_t inDataLen,
|
uint8_t *inData, size_t inDataLen,
|
||||||
uint8_t **outMessage, size_t *outMessageSize );
|
uint8_t **outMessage, size_t *outMessageSize );
|
||||||
|
|
||||||
#endif // __HTTPUtils_h__
|
#endif // __HTTPUtils_h__
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user