diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index 1c76a0f..9e0fea7 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -38,6 +38,7 @@ #include "httpd_priv.h" #include "app_httpd.h" #include "user_gpio.h" +#include "user_wifi.h" #include "main.h" @@ -70,12 +71,12 @@ static int http_get_socket_status(httpd_request_t *req) { OSStatus err = kNoErr; - char* status = get_socket_status(); + const unsigned char* status = get_socket_status(); - err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR); + err = httpd_send_all_header(req, HTTP_RES_200, strlen(socket_status), HTTP_CONTENT_HTML_STR); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers.")); - err = httpd_send_body(req->sock, socket_status, strlen(status)); + err = httpd_send_body(req->sock, status, strlen(socket_status)); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body.")); exit: @@ -96,10 +97,10 @@ static int http_set_socket_status(httpd_request_t *req) char* status = "OK"; - err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR); + err = httpd_send_all_header(req, HTTP_RES_200, strlen(socket_status), HTTP_CONTENT_HTML_STR); require_noerr_action(err, save_out, app_httpd_log("ERROR: Unable to send http socket_status headers.")); - err = httpd_send_body(req->sock, status, strlen(status)); + err = httpd_send_body(req->sock, (const unsigned char*)status, strlen(socket_status)); require_noerr_action(err, save_out, app_httpd_log("ERROR: Unable to send http socket_status body.")); save_out: @@ -111,12 +112,12 @@ static int http_get_wifi_config(httpd_request_t *req) { OSStatus err = kNoErr; - char* status = get_socket_status(); + const unsigned char* status = get_socket_status(); - err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR); + err = httpd_send_all_header(req, HTTP_RES_200, strlen(socket_status), HTTP_CONTENT_HTML_STR); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers.")); - err = httpd_send_body(req->sock, socket_status, strlen(status)); + err = httpd_send_body(req->sock, status, strlen(socket_status)); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body.")); exit: @@ -147,10 +148,10 @@ static int http_set_wifi_config(httpd_request_t *req) char* status = "OK"; - err = httpd_send_all_header(req, HTTP_RES_200, strlen(status), HTTP_CONTENT_HTML_STR); + err = httpd_send_all_header(req, HTTP_RES_200, strlen(socket_status), HTTP_CONTENT_HTML_STR); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status headers.")); - err = httpd_send_body(req->sock, status, strlen(status)); + err = httpd_send_body(req->sock, (const unsigned char*)status, strlen(socket_status)); require_noerr_action(err, exit, app_httpd_log("ERROR: Unable to send http socket_status body.")); exit: @@ -158,8 +159,8 @@ exit: save_out: if (buf) free(buf); - if (ssid_size) free(ssid_size); - if (key_size) free(key_size); + if (wifi_ssid) free(wifi_ssid); + if (wifi_key) free(wifi_key); return err; } diff --git a/TC1/ota_server/ota_server.c b/TC1/ota_server/ota_server.c index 6fef706..bcb0d0e 100644 --- a/TC1/ota_server/ota_server.c +++ b/TC1/ota_server/ota_server.c @@ -50,7 +50,7 @@ static uint32_t offset = 0; static OSStatus onReceivedData(struct _HTTPHeader_t * httpHeader, uint32_t pos, - char *data, + uint8_t *data, size_t len, void * userContext); @@ -228,7 +228,7 @@ static void ota_server_progress_set(OTA_STATE_E state) progress =(float) ota_server_context->download_state.download_begin_pos / ota_server_context->download_state.download_len; progress = progress*100; - if( ota_server_context->ota_server_cb != NULL) + if(ota_server_context->ota_server_cb != NULL) ota_server_context->ota_server_cb(state, progress); } @@ -358,7 +358,7 @@ DELETE: } /*one request may receive multi reply*/ -static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, char * inData, +static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, uint8_t * inData, size_t inLen, void * inUserContext) { OSStatus err = kNoErr; @@ -373,7 +373,7 @@ static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, Md5Update(&md5, inData, inLen); } - MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (char *) inData, inLen); + MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, inData, inLen); ota_server_progress_set(OTA_LOADING); diff --git a/TC1/user_function.c b/TC1/user_function.c index 52cac80..a912954 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -70,7 +70,7 @@ void user_function_cmd_received(int udp_flag, char* pusrdata) //开始正式处理所有命令 if ((p_name && cJSON_IsString(p_name) && strcmp(p_name->valuestring, sys_config->micoSystemConfig.name) == 0) //name || (p_mac && cJSON_IsString(p_mac) && strcmp(p_mac->valuestring, strMac) == 0) //mac - ) + ) { cJSON *json_send = cJSON_CreateObject(); cJSON_AddStringToObject(json_send, "mac", strMac); @@ -103,11 +103,11 @@ void user_function_cmd_received(int udp_flag, char* pusrdata) char *temp_buf = malloc(16); if (temp_buf != NULL) { - sprintf(temp_buf, "%d.%d", power / 10, power % 10); + sprintf(temp_buf, "%d.%d", (int)(power/10), (int)(power%10)); cJSON_AddStringToObject(json_send, "power", temp_buf); free(temp_buf); } - os_log("power:%d",power); + os_log("power:%d", (int)power); } //解析主机setting----------------------------------------------------------------- cJSON *p_setting = cJSON_GetObjectItem(pJsonRoot, "setting"); @@ -311,7 +311,7 @@ bool json_plug_task_analysis(unsigned char x, unsigned char y, cJSON * pJsonRoot && cJSON_IsNumber(p_plug_task_repeat) && cJSON_IsNumber(p_plug_task_action) && cJSON_IsNumber(p_plug_task_on) - ) + ) { return_flag = true; user_config->plug[x].task[y].hour = p_plug_task_hour->valueint; diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c index 67f49c2..90153ab 100644 --- a/TC1/user_gpio.c +++ b/TC1/user_gpio.c @@ -20,7 +20,7 @@ void user_led_set(char x) bool relay_out(void) { - unsigned char i; + int i; for (i = 0; i < PLUG_NUM; i++) { if (user_config->plug[i].on != 0) @@ -31,16 +31,16 @@ bool relay_out(void) return false; } -char* get_socket_status() +const unsigned char* get_socket_status() { - sprintf(socket_status, "%d,%d,%d,%d,%d,%d\0", + sprintf(socket_status, "%d,%d,%d,%d,%d,%d", user_config->plug[0].on, user_config->plug[1].on, user_config->plug[2].on, user_config->plug[3].on, user_config->plug[4].on, user_config->plug[5].on); - return socket_status; + return (const unsigned char*)socket_status; } void set_socket_status(char* socket_status) diff --git a/TC1/user_gpio.h b/TC1/user_gpio.h index 4d304e4..906d306 100644 --- a/TC1/user_gpio.h +++ b/TC1/user_gpio.h @@ -11,6 +11,7 @@ void key_init(void); void user_relay_set(unsigned char x,unsigned char y); void user_relay_set_all(char y); bool relay_out(void); -char* get_socket_status(); +const unsigned char* get_socket_status(); +void set_socket_status(char* socket_status); #endif diff --git a/TC1/user_mqtt_client.c b/TC1/user_mqtt_client.c index 5ad49a4..306a28a 100644 --- a/TC1/user_mqtt_client.c +++ b/TC1/user_mqtt_client.c @@ -93,7 +93,7 @@ Client c; // mqtt client object Network n; // socket network for mqtt client 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; char topic_state[MAX_MQTT_TOPIC_SIZE]; char topic_set[MAX_MQTT_TOPIC_SIZE]; @@ -264,7 +264,7 @@ void mqtt_client_thread(mico_thread_arg_t arg) { OSStatus err = kUnknownErr; - int i, rc = -1; + int rc = -1; fd_set readfds; struct timeval t = { 0, MQTT_YIELD_TMIE * 1000 }; @@ -378,7 +378,7 @@ void mqtt_client_thread(mico_thread_arg_t arg) // send message to server err = mqtt_msg_publish(&c, p_send_msg->topic, p_send_msg->qos, p_send_msg->retained, - p_send_msg->data, + (const unsigned char*)p_send_msg->data, p_send_msg->datalen); require_noerr_string(err, MQTT_reconnect, "ERROR: MQTT publish data err"); @@ -513,8 +513,8 @@ OSStatus user_mqtt_send_plug_state(char plug_id) topic_buf = malloc(64); // if (send_buf != NULL && topic_buf != NULL) { - sprintf(topic_buf, "homeassistant/switch/%s/plug_%d/state", strMac, plug_id); - sprintf(send_buf, "{\"mac\":\"%s\",\"plug_%d\":{\"on\":%d}}", strMac, plug_id, user_config->plug[plug_id].on); + sprintf(topic_buf, "homeassistant/switch/%s/plug_%d/state", strMac, (int)plug_id); + sprintf(send_buf, "{\"mac\":\"%s\",\"plug_%d\":{\"on\":%d}}", strMac, plug_id, (int)user_config->plug[(int)plug_id].on); user_mqtt_send_topic(topic_buf, send_buf, 1); } if (send_buf) free(send_buf); @@ -524,7 +524,6 @@ OSStatus user_mqtt_send_plug_state(char plug_id) //hass mqtt鑷姩鍙戠幇鏁版嵁寮鍏冲彂閫 void user_mqtt_hass_auto(char plug_id) { - char i; char *send_buf = NULL; char *topic_buf = NULL; send_buf = malloc(512); // @@ -538,7 +537,7 @@ void user_mqtt_hass_auto(char plug_id) "\"cmd_t\":\"device/ztc1/set\"," "\"pl_on\":\"{\\\"mac\\\":\\\"%s\\\",\\\"plug_%d\\\":{\\\"on\\\":1}}\"," "\"pl_off\":\"{\\\"mac\\\":\\\"%s\\\",\\\"plug_%d\\\":{\\\"on\\\":0}}\"" - "}\0", + "}", plug_id, strMac + 8, strMac, plug_id, strMac, plug_id, strMac, plug_id); user_mqtt_send_topic(topic_buf, send_buf, 1); } @@ -561,8 +560,8 @@ void user_mqtt_hass_auto_name(char plug_id) "\"cmd_t\":\"device/ztc1/set\"," "\"pl_on\":\"{\\\"mac\\\":\\\"%s\\\",\\\"plug_%d\\\":{\\\"on\\\":1}}\"," "\"pl_off\":\"{\\\"mac\\\":\\\"%s\\\",\\\"plug_%d\\\":{\\\"on\\\":0}}\"" - "}\0", - user_config->plug[plug_id].name, strMac, plug_id, strMac, plug_id, strMac, plug_id); + "}", + user_config->plug[(int)plug_id].name, strMac, plug_id, strMac, plug_id, strMac, plug_id); user_mqtt_send_topic(topic_buf, send_buf, 0); } if (send_buf) @@ -573,7 +572,6 @@ void user_mqtt_hass_auto_name(char plug_id) //hass mqtt鑷姩鍙戠幇鏁版嵁鍔熺巼鍙戦 void user_mqtt_hass_auto_power(void) { - char i; char *send_buf = NULL; char *topic_buf = NULL; send_buf = malloc(512); // @@ -628,7 +626,6 @@ void user_mqtt_hass_auto_power_name(void) void user_mqtt_hass_power(void) { - char i; char *send_buf = NULL; char *topic_buf = NULL; send_buf = malloc(512); // @@ -636,7 +633,7 @@ void user_mqtt_hass_power(void) if (send_buf != NULL && topic_buf != NULL) { sprintf(topic_buf, "homeassistant/sensor/%s/power/state", strMac); - sprintf(send_buf, "{\"power\":\"%d.%d\"}", power / 10, power % 10); + sprintf(send_buf, "{\"power\":\"%d.%d\"}", (int)(power/10), (int)(power%10)); user_mqtt_send_topic(topic_buf, send_buf, 0); } if (send_buf) free(send_buf); diff --git a/TC1/user_rtc.c b/TC1/user_rtc.c index 571a77e..adc93f6 100644 --- a/TC1/user_rtc.c +++ b/TC1/user_rtc.c @@ -131,7 +131,7 @@ void rtc_thread(mico_thread_arg_t arg) mico_utc_time_t utc_time; - mico_utc_time_t utc_time_last; + mico_utc_time_t utc_time_last = 0; while (1) { //上电后连接了wifi才开始走时否则等待连接 micoWlanGetLinkStatus(&LinkStatus); @@ -184,11 +184,11 @@ void rtc_thread(mico_thread_arg_t arg) { char repeat = user_config->plug[i].task[j].repeat; - if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值 + if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值 rtc_time.sec == 0 && rtc_time.min == user_config->plug[i].task[j].minute && rtc_time.hr == user_config->plug[i].task[j].hour && ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1))) - ) + ) { if (user_config->plug[i].on != user_config->plug[i].task[j].action) { diff --git a/TC1/user_sntp.c b/TC1/user_sntp.c index c5d59dc..cbc00ee 100644 --- a/TC1/user_sntp.c +++ b/TC1/user_sntp.c @@ -4,6 +4,7 @@ #include "main.h" //#include "user_gpio.h" #include "user_sntp.h" +#include "sntp.h" /* Callback function when MiCO UTC time in sync to NTP server */ static void sntp_time_call_back(void) diff --git a/TC1/user_udp.c b/TC1/user_udp.c index 38b59f3..72bcdd1 100644 --- a/TC1/user_udp.c +++ b/TC1/user_udp.c @@ -104,7 +104,7 @@ void udp_thread(void *arg) require_string(p_send_msg, exit, "Wrong data point"); // send message to server - err = udp_msg_send(udp_fd, p_send_msg->data, p_send_msg->datalen); + err = udp_msg_send(udp_fd, (const unsigned char*)p_send_msg->data, p_send_msg->datalen); // require_noerr_string(err, MQTT_reconnect, "ERROR: udp publish data err"); os_log("udp send data success! msg=[%ld].\r\n", p_send_msg->datalen); diff --git a/TC1/user_wifi.h b/TC1/user_wifi.h index a9bdf7d..f9ea1f9 100644 --- a/TC1/user_wifi.h +++ b/TC1/user_wifi.h @@ -23,7 +23,7 @@ extern char wifi_status; extern void wifi_init(void); extern void ap_init(void); extern void wifi_start_easylink(void); - +extern void wifi_connect(char* wifi_ssid, char* wifi_key); #endif