mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
统一os_log
This commit is contained in:
@@ -94,10 +94,10 @@ static int HttpGetIndexPage(httpd_request_t *req)
|
|||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_ZIP);
|
err = httpd_send_all_header(req, HTTP_RES_200, sizeof(index_html), HTTP_CONTENT_HTML_ZIP);
|
||||||
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting headers."));
|
require_noerr_action(err, exit, http_log("ERROR: Unable to send http wifisetting headers."));
|
||||||
|
|
||||||
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
|
err = httpd_send_body(req->sock, index_html, sizeof(index_html));
|
||||||
require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http wifisetting body."));
|
require_noerr_action(err, exit, http_log("ERROR: Unable to send http wifisetting body."));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
@@ -284,13 +284,13 @@ static int HttpAddTask(httpd_request_t *req)
|
|||||||
|
|
||||||
pTimedTask task = (pTimedTask)malloc(sizeof(struct TimedTask));
|
pTimedTask task = (pTimedTask)malloc(sizeof(struct TimedTask));
|
||||||
int re = sscanf(buf, "%ld %d %d", &task->prs_time, &task->socket_idx, &task->on);
|
int re = sscanf(buf, "%ld %d %d", &task->prs_time, &task->socket_idx, &task->on);
|
||||||
app_httpd_log("AddTask buf[%s] re[%d] (%ld %d %d)",
|
http_log("AddTask buf[%s] re[%d] (%ld %d %d)",
|
||||||
buf, re, task->prs_time, task->socket_idx, task->on);
|
buf, re, task->prs_time, task->socket_idx, task->on);
|
||||||
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|
if (task->prs_time < 1577428136 || task->prs_time > 9577428136
|
||||||
|| task->socket_idx < 0 || task->socket_idx > 5
|
|| task->socket_idx < 0 || task->socket_idx > 5
|
||||||
|| (task->on != 0 && task->on != 1))
|
|| (task->on != 0 && task->on != 1))
|
||||||
{
|
{
|
||||||
app_httpd_log("AddTask Error!");
|
http_log("AddTask Error!");
|
||||||
re = 0;
|
re = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ static int HttpDelTask(httpd_request_t *req)
|
|||||||
{
|
{
|
||||||
//TODO 从url获取时间
|
//TODO 从url获取时间
|
||||||
char* time_str = strstr(req->filename, "?time=");
|
char* time_str = strstr(req->filename, "?time=");
|
||||||
app_httpd_log("HttpDelTask url[%s] time_str[%s][%s]", req->filename, time_str, time_str + 6);
|
http_log("HttpDelTask url[%s] time_str[%s][%s]", req->filename, time_str, time_str + 6);
|
||||||
|
|
||||||
int time1;
|
int time1;
|
||||||
sscanf(time_str + 6, "%d", &time1);
|
sscanf(time_str + 6, "%d", &time1);
|
||||||
@@ -335,7 +335,7 @@ static int OtaStart(httpd_request_t *req)
|
|||||||
err = httpd_get_data(req, buf, 64);
|
err = httpd_get_data(req, buf, 64);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
|
|
||||||
app_httpd_log("OtaStart ota_url[%s]", buf);
|
http_log("OtaStart ota_url[%s]", buf);
|
||||||
UserOtaStart(buf, NULL);
|
UserOtaStart(buf, NULL);
|
||||||
|
|
||||||
send_http("OK", 2, exit, &err);
|
send_http("OK", 2, exit, &err);
|
||||||
@@ -363,26 +363,26 @@ static void AppHttpRegisterHandlers()
|
|||||||
int rc;
|
int rc;
|
||||||
rc = httpd_register_wsgi_handlers(g_app_handlers, g_app_handlers_no);
|
rc = httpd_register_wsgi_handlers(g_app_handlers, g_app_handlers_no);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
app_httpd_log("failed to register test web handler");
|
http_log("failed to register test web handler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _AppHttpdStart()
|
static int _AppHttpdStart()
|
||||||
{
|
{
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
app_httpd_log("initializing web-services");
|
http_log("initializing web-services");
|
||||||
|
|
||||||
/*Initialize HTTPD*/
|
/*Initialize HTTPD*/
|
||||||
if(is_http_init == false) {
|
if(is_http_init == false) {
|
||||||
err = httpd_init();
|
err = httpd_init();
|
||||||
require_noerr_action(err, exit, app_httpd_log("failed to initialize httpd"));
|
require_noerr_action(err, exit, http_log("failed to initialize httpd"));
|
||||||
is_http_init = true;
|
is_http_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Start http thread*/
|
/*Start http thread*/
|
||||||
err = httpd_start();
|
err = httpd_start();
|
||||||
if(err != kNoErr) {
|
if(err != kNoErr) {
|
||||||
app_httpd_log("failed to start httpd thread");
|
http_log("failed to start httpd thread");
|
||||||
httpd_shutdown();
|
httpd_shutdown();
|
||||||
}
|
}
|
||||||
exit:
|
exit:
|
||||||
@@ -410,9 +410,9 @@ int AppHttpdStop()
|
|||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
/* HTTPD and services */
|
/* HTTPD and services */
|
||||||
app_httpd_log("stopping down httpd");
|
http_log("stopping down httpd");
|
||||||
err = httpd_stop();
|
err = httpd_stop();
|
||||||
require_noerr_action(err, exit, app_httpd_log("failed to halt httpd"));
|
require_noerr_action(err, exit, http_log("failed to halt httpd"));
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
@@ -34,15 +34,13 @@
|
|||||||
|
|
||||||
#define HTTP_CONTENT_HTML_ZIP "text/html\r\nContent-Encoding: gzip"
|
#define HTTP_CONTENT_HTML_ZIP "text/html\r\nContent-Encoding: gzip"
|
||||||
|
|
||||||
#define app_httpd_log(M, ...) do { custom_log("apphttpd", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
#define HTTPD_HDR_DEFORT (HTTPD_HDR_ADD_SERVER|HTTPD_HDR_ADD_CONN_CLOSE|HTTPD_HDR_ADD_PRAGMA_NO_CACHE)
|
#define HTTPD_HDR_DEFORT (HTTPD_HDR_ADD_SERVER|HTTPD_HDR_ADD_CONN_CLOSE|HTTPD_HDR_ADD_PRAGMA_NO_CACHE)
|
||||||
|
|
||||||
#define send_http(DATA, LEN, LABEL, P_ERR) \
|
#define send_http(DATA, LEN, LABEL, P_ERR) \
|
||||||
*(P_ERR) = httpd_send_all_header(req, HTTP_RES_200, LEN , HTTP_CONTENT_HTML_STR); \
|
*(P_ERR) = httpd_send_all_header(req, HTTP_RES_200, LEN , HTTP_CONTENT_HTML_STR); \
|
||||||
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA headers.")); \
|
require_noerr_action(*(P_ERR), LABEL, http_log("ERROR: Unable to send http DATA headers.")); \
|
||||||
*(P_ERR) = httpd_send_body(req->sock, (const unsigned char*)DATA, LEN); \
|
*(P_ERR) = httpd_send_body(req->sock, (const unsigned char*)DATA, LEN); \
|
||||||
require_noerr_action(*(P_ERR), LABEL, app_httpd_log("ERROR: Unable to send http DATA body.")); \
|
require_noerr_action(*(P_ERR), LABEL, http_log("ERROR: Unable to send http DATA body.")); \
|
||||||
|
|
||||||
#define TC1_STATUS_JSON \
|
#define TC1_STATUS_JSON \
|
||||||
"{\
|
"{\
|
||||||
|
|||||||
30
TC1/main.c
30
TC1/main.c
@@ -8,8 +8,6 @@
|
|||||||
#include "http_server/app_httpd.h"
|
#include "http_server/app_httpd.h"
|
||||||
#include "timed_task/timed_task.h"
|
#include "timed_task/timed_task.h"
|
||||||
|
|
||||||
#define os_log(format, ...) do { custom_log("TC1", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
char rtc_init = 0; //sntp校时成功标志位
|
char rtc_init = 0; //sntp校时成功标志位
|
||||||
uint32_t total_time = 0;
|
uint32_t total_time = 0;
|
||||||
char str_mac[16] = { 0 };
|
char str_mac[16] = { 0 };
|
||||||
@@ -48,7 +46,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
int application_start(void)
|
int application_start(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
os_log("start version[%s]", VERSION);
|
tc1_log("start version[%s]", VERSION);
|
||||||
|
|
||||||
//char main_num=0;
|
//char main_num=0;
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
@@ -65,13 +63,13 @@ int application_start(void)
|
|||||||
mico_wlan_get_mac_address(mac);
|
mico_wlan_get_mac_address(mac);
|
||||||
sprintf(str_mac, "%02X%02X%02X%02X%02X%02X",
|
sprintf(str_mac, "%02X%02X%02X%02X%02X%02X",
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
os_log("str_mac[%s]", str_mac);
|
tc1_log("str_mac[%s]", str_mac);
|
||||||
|
|
||||||
bool open_ap = false;
|
bool open_ap = false;
|
||||||
MicoGpioInitialize((mico_gpio_t)Button, INPUT_PULL_UP);
|
MicoGpioInitialize((mico_gpio_t)Button, INPUT_PULL_UP);
|
||||||
if (!MicoGpioInputGet(Button))
|
if (!MicoGpioInputGet(Button))
|
||||||
{ //开机时按钮状态
|
{ //开机时按钮状态
|
||||||
os_log("press ap_init");
|
tc1_log("press ap_init");
|
||||||
ApInit(false);
|
ApInit(false);
|
||||||
open_ap = true;
|
open_ap = true;
|
||||||
}
|
}
|
||||||
@@ -86,7 +84,7 @@ int application_start(void)
|
|||||||
|
|
||||||
if (user_config->version != USER_CONFIG_VERSION)
|
if (user_config->version != USER_CONFIG_VERSION)
|
||||||
{
|
{
|
||||||
os_log("WARNGIN: user params restored!");
|
tc1_log("WARNGIN: user params restored!");
|
||||||
err = mico_system_context_restore(sys_config);
|
err = mico_system_context_restore(sys_config);
|
||||||
require_noerr(err, exit);
|
require_noerr(err, exit);
|
||||||
}
|
}
|
||||||
@@ -96,13 +94,13 @@ int application_start(void)
|
|||||||
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac+8);
|
sprintf(sys_config->micoSystemConfig.name, ZTC1_NAME, str_mac+8);
|
||||||
}
|
}
|
||||||
|
|
||||||
os_log("user:%s",user_config->user);
|
tc1_log("user:%s",user_config->user);
|
||||||
os_log("device name:%s",sys_config->micoSystemConfig.name);
|
tc1_log("device name:%s",sys_config->micoSystemConfig.name);
|
||||||
os_log("mqtt_ip:%s",user_config->mqtt_ip);
|
tc1_log("mqtt_ip:%s",user_config->mqtt_ip);
|
||||||
os_log("mqtt_port:%d",user_config->mqtt_port);
|
tc1_log("mqtt_port:%d",user_config->mqtt_port);
|
||||||
os_log("mqtt_user:%s",user_config->mqtt_user);
|
tc1_log("mqtt_user:%s",user_config->mqtt_user);
|
||||||
os_log("mqtt_password:%s",user_config->mqtt_password);
|
tc1_log("mqtt_password:%s",user_config->mqtt_password);
|
||||||
os_log("version:%d",user_config->version);
|
tc1_log("version:%d",user_config->version);
|
||||||
|
|
||||||
WifiInit();
|
WifiInit();
|
||||||
if (!open_ap)
|
if (!open_ap)
|
||||||
@@ -143,20 +141,20 @@ int application_start(void)
|
|||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
if (task_top && now >= task_top->prs_time)
|
if (task_top && now >= task_top->prs_time)
|
||||||
{
|
{
|
||||||
os_log("process task time[%ld] socket_idx[%d] on[%d]",
|
tc1_log("process task time[%ld] socket_idx[%d] on[%d]",
|
||||||
task_top->prs_time, task_top->socket_idx, task_top->on);
|
task_top->prs_time, task_top->socket_idx, task_top->on);
|
||||||
UserRelaySet(task_top->socket_idx, task_top->on);
|
UserRelaySet(task_top->socket_idx, task_top->on);
|
||||||
DelFirstTask();
|
DelFirstTask();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//os_log("timed task count[%u]", task_count);
|
//tc1_log("timed task count[%u]", task_count);
|
||||||
}
|
}
|
||||||
mico_thread_msleep(1000);
|
mico_thread_msleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
os_log("application_start ERROR!");
|
tc1_log("application_start ERROR!");
|
||||||
if (power_buf) free(power_buf);
|
if (power_buf) free(power_buf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,15 @@
|
|||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "micokit_ext.h"
|
#include "micokit_ext.h"
|
||||||
|
|
||||||
|
#define app_log(M, ...) do { custom_log("APP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define key_log(M, ...) do { custom_log("KEY", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define ota_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define rtc_log(M, ...) do { custom_log("RTC", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define tc1_log(M, ...) do { custom_log("TC1", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define http_log(M, ...) do { custom_log("HTTP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
#define wifi_log(M, ...) do { custom_log("WIFI", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
||||||
|
|
||||||
#define VERSION "v1.0.15"
|
#define VERSION "v1.0.15"
|
||||||
|
|
||||||
#define TYPE 1
|
#define TYPE 1
|
||||||
|
|||||||
@@ -20,9 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
|
||||||
#define app_log(M, ...) do { custom_log("APP", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
|
||||||
#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "MQTTClient.h"
|
#include "MQTTClient.h"
|
||||||
|
|||||||
@@ -29,19 +29,13 @@
|
|||||||
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#include "mico.h"
|
#include "main.h"
|
||||||
#include "HTTPUtils.h"
|
#include "HTTPUtils.h"
|
||||||
#include "SocketUtils.h"
|
#include "SocketUtils.h"
|
||||||
#include "ota_server.h"
|
#include "ota_server.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
|
||||||
#if OTA_DEBUG
|
|
||||||
#define ota_server_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log(M, ##__VA_ARGS__) } while(0)
|
|
||||||
#else
|
|
||||||
#define ota_server_log(M, ...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static ota_server_context_t *ota_server_context = NULL;
|
static ota_server_context_t *ota_server_context = NULL;
|
||||||
static HTTPHeader_t *httpHeader = NULL;
|
static HTTPHeader_t *httpHeader = NULL;
|
||||||
|
|
||||||
@@ -176,7 +170,7 @@ static int OtaServerSendHeader(void)
|
|||||||
|
|
||||||
ret = OtaServerSend((char *) header, strlen(header));
|
ret = OtaServerSend((char *) header, strlen(header));
|
||||||
|
|
||||||
// ota_server_log("send: %d\r\n%s", strlen(header), header);
|
// ota_log("send: %d\r\n%s", strlen(header), header);
|
||||||
if (header != NULL) free(header);
|
if (header != NULL) free(header);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -219,7 +213,7 @@ static int OtaServerConnectServer(struct in_addr in_addr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ota_server_log("ota server connected!");
|
ota_log("ota server connected!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +247,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
|
|||||||
pptr=hostent_content->h_addr_list;
|
pptr=hostent_content->h_addr_list;
|
||||||
in_addr.s_addr = *(uint32_t *)(*pptr);
|
in_addr.s_addr = *(uint32_t *)(*pptr);
|
||||||
strcpy(ota_server_context->download_url.ip, inet_ntoa(in_addr));
|
strcpy(ota_server_context->download_url.ip, inet_ntoa(in_addr));
|
||||||
ota_server_log("OTA server address: %s, host ip: %s", ota_server_context->download_url.host, ota_server_context->download_url.ip);
|
ota_log("OTA server address: %s, host ip: %s", ota_server_context->download_url.host, ota_server_context->download_url.ip);
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
|
MicoFlashErase(MICO_PARTITION_OTA_TEMP, 0x0, ota_partition->partition_length);
|
||||||
@@ -309,7 +303,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
|
|||||||
case kNoSpaceErr:
|
case kNoSpaceErr:
|
||||||
case kConnectionErr:
|
case kConnectionErr:
|
||||||
default:
|
default:
|
||||||
ota_server_log("ERROR: HTTP Header parse error: %d", err);
|
ota_log("ERROR: HTTP Header parse error: %d", err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +324,7 @@ static void OtaServerThread(mico_thread_arg_t arg)
|
|||||||
mico_ota_switch_to_new_fw(ota_server_context->download_state.download_len, crc16);
|
mico_ota_switch_to_new_fw(ota_server_context->download_state.download_len, crc16);
|
||||||
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
|
mico_system_power_perform(mico_system_context_get(), eState_Software_Reset);
|
||||||
}else{
|
}else{
|
||||||
ota_server_log("OTA md5 check err, Calculation:%s, Get:%s", md5_value_string, ota_server_context->ota_check.md5);
|
ota_log("OTA md5 check err, Calculation:%s, Get:%s", md5_value_string, ota_server_context->ota_check.md5);
|
||||||
OtaServerProgressSet(OTA_FAIL);
|
OtaServerProgressSet(OTA_FAIL);
|
||||||
}
|
}
|
||||||
goto DELETE;
|
goto DELETE;
|
||||||
@@ -354,7 +348,7 @@ DELETE:
|
|||||||
ota_server_context = NULL;
|
ota_server_context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ota_server_log("ota server thread will delete");
|
ota_log("ota server thread will delete");
|
||||||
mico_rtos_delete_thread(NULL);
|
mico_rtos_delete_thread(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
#define os_log(format, ...) do { custom_log("OTA", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
#include "ota_server/ota_server.h"
|
#include "ota_server/ota_server.h"
|
||||||
@@ -15,17 +14,17 @@ static void OtaServerStatusHandler(OTA_STATE_E state, float progress)
|
|||||||
{
|
{
|
||||||
case OTA_LOADING:
|
case OTA_LOADING:
|
||||||
ota_progress = progress;
|
ota_progress = progress;
|
||||||
os_log("ota server is loading, progress %.2f%%", progress);
|
ota_log("ota server is loading, progress %.2f%%", progress);
|
||||||
if (((int) progress)%10 == 1)
|
if (((int) progress)%10 == 1)
|
||||||
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":%d}", str_mac,((int) progress));
|
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":%d}", str_mac,((int) progress));
|
||||||
break;
|
break;
|
||||||
case OTA_SUCCE:
|
case OTA_SUCCE:
|
||||||
ota_progress = 100;
|
ota_progress = 100;
|
||||||
os_log("ota server daemons success");
|
ota_log("ota server daemons success");
|
||||||
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":100}", str_mac);
|
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":100}", str_mac);
|
||||||
break;
|
break;
|
||||||
case OTA_FAIL:
|
case OTA_FAIL:
|
||||||
os_log("ota server daemons failed");
|
ota_log("ota server daemons failed");
|
||||||
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":-1}", str_mac);
|
sprintf(str, "{\"mac\":\"%s\",\"ota_progress\":-1}", str_mac);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -36,7 +35,7 @@ static void OtaServerStatusHandler(OTA_STATE_E state, float progress)
|
|||||||
void UserOtaStart(char *url, char *md5)
|
void UserOtaStart(char *url, char *md5)
|
||||||
{
|
{
|
||||||
ota_progress = 0;
|
ota_progress = 0;
|
||||||
os_log("ready to ota:%s",url);
|
ota_log("ready to ota:%s",url);
|
||||||
OtaServerStart(url, md5, OtaServerStatusHandler);
|
OtaServerStart(url, md5, OtaServerStatusHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
#define os_log(format, ...) do { custom_log("RTC", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "sntp.h"
|
#include "sntp.h"
|
||||||
@@ -37,7 +35,7 @@ OSStatus UserSntpGetTime()
|
|||||||
hostent_content = gethostbyname(ntp_hosts[i]);
|
hostent_content = gethostbyname(ntp_hosts[i]);
|
||||||
if (hostent_content == NULL)
|
if (hostent_content == NULL)
|
||||||
{
|
{
|
||||||
os_log("gethostbyname(%s)", ntp_hosts[i]);
|
rtc_log("gethostbyname(%s)", ntp_hosts[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pptr = hostent_content->h_addr_list;
|
pptr = hostent_content->h_addr_list;
|
||||||
@@ -52,7 +50,7 @@ OSStatus UserSntpGetTime()
|
|||||||
|
|
||||||
if (err != kNoErr)
|
if (err != kNoErr)
|
||||||
{
|
{
|
||||||
os_log("sntp_get_time4 err[%d]", err);
|
rtc_log("sntp_get_time4 err[%d]", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ OSStatus UserRtcInit(void)
|
|||||||
0x1000, 0);
|
0x1000, 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) os_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);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return err;
|
return err;
|
||||||
@@ -94,7 +92,7 @@ void RtcThread(mico_thread_arg_t arg)
|
|||||||
err = UserSntpGetTime();
|
err = UserSntpGetTime();
|
||||||
if (err == kNoErr)
|
if (err == kNoErr)
|
||||||
{
|
{
|
||||||
os_log("sntp success!");
|
rtc_log("sntp success!");
|
||||||
rtc_init = 1;
|
rtc_init = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -143,7 +141,7 @@ void RtcThread(mico_thread_arg_t arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// exit:
|
// exit:
|
||||||
os_log("EXIT: rtc exit with err = %d.", err);
|
rtc_log("EXIT: rtc exit with err = %d.", err);
|
||||||
mico_rtos_delete_thread(NULL);
|
mico_rtos_delete_thread(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
#define os_log(format, ...) do { custom_log("KEY", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
@@ -104,14 +103,14 @@ void UserRelaySetAll(char y)
|
|||||||
|
|
||||||
static void KeyLongPress(void)
|
static void KeyLongPress(void)
|
||||||
{
|
{
|
||||||
// os_log("KeyLongPress");
|
// key_log("KeyLongPress");
|
||||||
// UserLedSet(1);
|
// UserLedSet(1);
|
||||||
// UserMqttSend("mqtt test");
|
// UserMqttSend("mqtt test");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void KeyLong10sPress(void)
|
static void KeyLong10sPress(void)
|
||||||
{
|
{
|
||||||
os_log("WARNGIN: user params restored!");
|
key_log("WARNGIN: user params restored!");
|
||||||
appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
appRestoreDefault_callback(user_config, sizeof(user_config_t));
|
||||||
sys_config->micoSystemConfig.ssid[0] = 0;
|
sys_config->micoSystemConfig.ssid[0] = 0;
|
||||||
mico_system_context_update(mico_system_context_get());
|
mico_system_context_update(mico_system_context_get());
|
||||||
@@ -152,7 +151,7 @@ static void KeyTimeoutHandler(void* arg)
|
|||||||
key_time++;
|
key_time++;
|
||||||
if (key_time <= BUTTON_LONG_PRESS_TIME)
|
if (key_time <= BUTTON_LONG_PRESS_TIME)
|
||||||
{
|
{
|
||||||
os_log("button long pressed:%d",key_time);
|
key_log("button long pressed:%d",key_time);
|
||||||
|
|
||||||
if (key_time == 30)
|
if (key_time == 30)
|
||||||
{
|
{
|
||||||
@@ -179,7 +178,7 @@ static void KeyTimeoutHandler(void* arg)
|
|||||||
if (key_time < BUTTON_LONG_PRESS_TIME)
|
if (key_time < BUTTON_LONG_PRESS_TIME)
|
||||||
{ //100ms*10=1s 大于1s为长按
|
{ //100ms*10=1s 大于1s为长按
|
||||||
key_time = 0;
|
key_time = 0;
|
||||||
os_log("button short pressed:%d",key_time);
|
key_log("button short pressed:%d",key_time);
|
||||||
KeyShortPress();
|
KeyShortPress();
|
||||||
}
|
}
|
||||||
else if (key_time > 100)
|
else if (key_time > 100)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
#define os_log(format, ...) do { custom_log("OTA", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
#include "TimeUtils.h"
|
#include "TimeUtils.h"
|
||||||
|
|
||||||
#include "mico.h"
|
#include "mico.h"
|
||||||
@@ -70,7 +69,7 @@ static void PowerIrqHandler(void* arg)
|
|||||||
|
|
||||||
void PowerInit(void)
|
void PowerInit(void)
|
||||||
{
|
{
|
||||||
os_log("user_power_init");
|
ota_log("user_power_init");
|
||||||
MicoGpioInitialize(POWER, INPUT_PULL_UP);
|
MicoGpioInitialize(POWER, INPUT_PULL_UP);
|
||||||
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);
|
MicoGpioEnableIRQ(POWER, IRQ_TRIGGER_FALLING_EDGE, PowerIrqHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "http_server/web_log.h"
|
#include "http_server/web_log.h"
|
||||||
|
|
||||||
#define os_log(format, ...) do { custom_log("WIFI", format, ##__VA_ARGS__); web_log(format, ##__VA_ARGS__) } while(0)
|
|
||||||
|
|
||||||
char wifi_status = WIFI_STATE_NOCONNECT;
|
char wifi_status = WIFI_STATE_NOCONNECT;
|
||||||
|
|
||||||
mico_timer_t wifi_led_timer;
|
mico_timer_t wifi_led_timer;
|
||||||
@@ -19,7 +17,7 @@ static void WifiGetIpCallback(IPStatusTypedef *pnet, void * arg)
|
|||||||
strcpy(ip_status.gateway, pnet->gate);
|
strcpy(ip_status.gateway, pnet->gate);
|
||||||
strcpy(ip_status.mask, pnet->mask);
|
strcpy(ip_status.mask, pnet->mask);
|
||||||
|
|
||||||
os_log("got IP:%s", pnet->ip);
|
wifi_log("got IP:%s", pnet->ip);
|
||||||
wifi_status = WIFI_STATE_CONNECTED;
|
wifi_status = WIFI_STATE_CONNECTED;
|
||||||
//UserFunctionCmdReceived(1,"{\"cmd\":\"device report\"}");
|
//UserFunctionCmdReceived(1,"{\"cmd\":\"device report\"}");
|
||||||
}
|
}
|
||||||
@@ -36,7 +34,7 @@ static void WifiStatusCallback(WiFiEvent status, void* arg)
|
|||||||
OSStatus status = micoWlanSuspendSoftAP(); //关闭AP
|
OSStatus status = micoWlanSuspendSoftAP(); //关闭AP
|
||||||
if (status != kNoErr)
|
if (status != kNoErr)
|
||||||
{
|
{
|
||||||
os_log("close ap error[%d]", status);
|
wifi_log("close ap error[%d]", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ip_status.mode = 1;
|
ip_status.mode = 1;
|
||||||
@@ -68,7 +66,7 @@ char* wifi_ret = NULL;
|
|||||||
void WifiScanCallback(ScanResult_adv* scan_ret, void* arg)
|
void WifiScanCallback(ScanResult_adv* scan_ret, void* arg)
|
||||||
{
|
{
|
||||||
int count = (int)scan_ret->ApNum;
|
int count = (int)scan_ret->ApNum;
|
||||||
os_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", count, scan_ret->ApList[0].ssid);
|
wifi_log("wifi_scan_callback ApNum[%d] ApList[0](%s)", count, scan_ret->ApList[0].ssid);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
wifi_ret = malloc(sizeof(char)*count * (32 + 2) + 50);
|
wifi_ret = malloc(sizeof(char)*count * (32 + 2) + 50);
|
||||||
@@ -80,7 +78,7 @@ void WifiScanCallback(ScanResult_adv* scan_ret, void* arg)
|
|||||||
{
|
{
|
||||||
ApInfo* ap = (ApInfo*)&scan_ret->ApList[i];
|
ApInfo* ap = (ApInfo*)&scan_ret->ApList[i];
|
||||||
uint8_t* mac = (uint8_t*)ap->bssid;
|
uint8_t* mac = (uint8_t*)ap->bssid;
|
||||||
os_log("wifi_scan_callback ssid[%16s] bssid[%02X-%02X-%02X-%02X-%02X-%02X] security[%d]",
|
wifi_log("wifi_scan_callback ssid[%16s] bssid[%02X-%02X-%02X-%02X-%02X-%02X] security[%d]",
|
||||||
ap->ssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ap->security);
|
ap->ssid, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], ap->security);
|
||||||
char* ssid = scan_ret->ApList[i].ssid;
|
char* ssid = scan_ret->ApList[i].ssid;
|
||||||
//排除隐藏的wifi和SSID带'或"的我wifi
|
//排除隐藏的wifi和SSID带'或"的我wifi
|
||||||
@@ -110,7 +108,7 @@ static void WifiLedTimerCallback(void* arg)
|
|||||||
switch (wifi_status)
|
switch (wifi_status)
|
||||||
{
|
{
|
||||||
case WIFI_STATE_FAIL:
|
case WIFI_STATE_FAIL:
|
||||||
os_log("wifi connect fail");
|
wifi_log("wifi connect fail");
|
||||||
UserLedSet(0);
|
UserLedSet(0);
|
||||||
mico_rtos_stop_timer(&wifi_led_timer);
|
mico_rtos_stop_timer(&wifi_led_timer);
|
||||||
break;
|
break;
|
||||||
@@ -134,7 +132,7 @@ static void WifiLedTimerCallback(void* arg)
|
|||||||
|
|
||||||
void WifiConnect(char* wifi_ssid, char* wifi_key)
|
void WifiConnect(char* wifi_ssid, char* wifi_key)
|
||||||
{
|
{
|
||||||
os_log("WifiConnect wifi_ssid[%s] wifi_key[%s]", wifi_ssid, wifi_key);
|
wifi_log("WifiConnect wifi_ssid[%s] wifi_key[%s]", wifi_ssid, wifi_key);
|
||||||
//wifi配置初始化
|
//wifi配置初始化
|
||||||
network_InitTypeDef_st wNetConfig;
|
network_InitTypeDef_st wNetConfig;
|
||||||
|
|
||||||
@@ -174,7 +172,7 @@ void ApConfig(char* name, char* key)
|
|||||||
{
|
{
|
||||||
strncpy(user_config->ap_name, name, 32);
|
strncpy(user_config->ap_name, name, 32);
|
||||||
strncpy(user_config->ap_key, key, 32);
|
strncpy(user_config->ap_key, key, 32);
|
||||||
os_log("ApConfig ap_name[%s] ap_key[%s]", user_config->ap_name, user_config->ap_key);
|
wifi_log("ApConfig ap_name[%s] ap_key[%s]", user_config->ap_name, user_config->ap_key);
|
||||||
micoWlanSuspendStation();
|
micoWlanSuspendStation();
|
||||||
ApInit(false);
|
ApInit(false);
|
||||||
mico_system_context_update(sys_config);
|
mico_system_context_update(sys_config);
|
||||||
@@ -186,7 +184,7 @@ void ApInit(bool use_defaul)
|
|||||||
{
|
{
|
||||||
sprintf(user_config->ap_name, ZZ_AP_NAME, str_mac + 6);
|
sprintf(user_config->ap_name, ZZ_AP_NAME, str_mac + 6);
|
||||||
sprintf(user_config->ap_key, "%s", ZZ_AP_KEY);
|
sprintf(user_config->ap_key, "%s", ZZ_AP_KEY);
|
||||||
os_log("ApInit ap_name[%s] ap_ke[%s]", user_config->ap_name, user_config->ap_key);
|
wifi_log("ApInit ap_name[%s] ap_ke[%s]", user_config->ap_name, user_config->ap_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
network_InitTypeDef_st wNetConfig;
|
network_InitTypeDef_st wNetConfig;
|
||||||
@@ -201,6 +199,6 @@ void ApInit(bool use_defaul)
|
|||||||
strcpy((char *)wNetConfig.dnsServer_ip_addr, ZZ_AP_DNS_SERVER);
|
strcpy((char *)wNetConfig.dnsServer_ip_addr, ZZ_AP_DNS_SERVER);
|
||||||
micoWlanStart(&wNetConfig);
|
micoWlanStart(&wNetConfig);
|
||||||
|
|
||||||
os_log("ApInit ssid[%s] key[%s]", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
|
wifi_log("ApInit ssid[%s] key[%s]", wNetConfig.wifi_ssid, wNetConfig.wifi_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user