mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-10 12:08:14 +08:00
add:增加ota功能
add:增加bin文件
This commit is contained in:
@@ -32,7 +32,10 @@ $(NAME)_SOURCES := main.c\
|
||||
user_sntp.c\
|
||||
user_rtc.c\
|
||||
user_mqtt_client.c\
|
||||
user_tftp_ota.c\
|
||||
user_function.c
|
||||
|
||||
$(NAME)_COMPONENTS := protocols/SNTP\
|
||||
protocols/mqtt
|
||||
protocols/mqtt\
|
||||
daemons/ota_server
|
||||
|
||||
@@ -79,7 +79,7 @@ void appRestoreDefault_callback( void * const user_config_data, uint32_t size )
|
||||
int application_start( void )
|
||||
{
|
||||
int i;
|
||||
os_log( "Start v0.1" );
|
||||
os_log( "Start %s",VERSION );
|
||||
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "mico.h"
|
||||
#include "MiCOKit_EXT.h"
|
||||
|
||||
#define VERSION "v0.2"
|
||||
|
||||
#define TYPE 1
|
||||
#define TYPE_NAME "zTC1"
|
||||
|
||||
|
||||
@@ -134,11 +134,25 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
}
|
||||
cJSON_AddNumberToObject( json_send, "nvalue", p_nvalue->valueint );
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>汾
|
||||
cJSON *p_version = cJSON_GetObjectItem( pJsonRoot, "version" );
|
||||
if ( p_version )
|
||||
{
|
||||
os_log("version:%s",VERSION);
|
||||
cJSON_AddStringToObject( json_send, "version", VERSION );
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>setting-----------------------------------------------------------------
|
||||
cJSON *p_setting = cJSON_GetObjectItem( pJsonRoot, "setting" );
|
||||
if ( p_setting )
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD>ota
|
||||
cJSON *p_ota = cJSON_GetObjectItem( p_setting, "ota" );
|
||||
if ( p_ota )
|
||||
{
|
||||
if ( cJSON_IsString( p_ota ) )
|
||||
user_ota_start( p_ota->valuestring, NULL );
|
||||
}
|
||||
|
||||
cJSON *json_setting_send = cJSON_CreateObject( );
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>/deviceid
|
||||
cJSON *p_setting_name = cJSON_GetObjectItem( p_setting, "name" );
|
||||
@@ -330,7 +344,7 @@ bool json_plug_analysis( int udp_flag, char x, cJSON * pJsonRoot, cJSON * pJsonS
|
||||
}
|
||||
cJSON *p_nvalue = cJSON_GetObjectItem( pJsonRoot, "nvalue" );
|
||||
// if ( p_plug || p_nvalue )
|
||||
cJSON_AddNumberToObject( json_plug_send, "on", user_config->plug[x].on );
|
||||
cJSON_AddNumberToObject( json_plug_send, "on", user_config->plug[x].on );
|
||||
|
||||
cJSON_AddItemToObject( pJsonSend, plug_str, json_plug_send );
|
||||
return return_flag;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "mico.h"
|
||||
#include "MiCOKit_EXT.h"
|
||||
|
||||
void user_send( int udp_flag, char *s );
|
||||
void user_function_cmd_received(int udp_flag,uint8_t *pusrdata);
|
||||
unsigned char strtohex(char a, char b);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "user_mqtt_client.h"
|
||||
#include "user_udp.h"
|
||||
#include "cJSON/cJSON.h"
|
||||
#include "user_tftp_ota.h"
|
||||
|
||||
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ void mqtt_client_thread( mico_thread_arg_t arg )
|
||||
{
|
||||
sprintf(
|
||||
buf1,
|
||||
"{\"mac\":\"%s\",\"plug_0\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_1\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_2\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_3\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_4\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_5\":{\"on\":null,\"setting\":{\"name\":null}}}",
|
||||
"{\"mac\":\"%s\",\"version\":null,\"plug_0\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_1\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_2\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_3\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_4\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_5\":{\"on\":null,\"setting\":{\"name\":null}}}",
|
||||
strMac );
|
||||
user_function_cmd_received( 0, buf1 );
|
||||
|
||||
|
||||
40
TC1/user_tftp_ota.c
Normal file
40
TC1/user_tftp_ota.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#define os_log(format, ...) custom_log("OTA", format, ##__VA_ARGS__)
|
||||
|
||||
#include "mico.h"
|
||||
#include "ota_server.h"
|
||||
#include "main.h"
|
||||
#include "user_udp.h"
|
||||
#include "user_mqtt_client.h"
|
||||
#include "user_function.h"
|
||||
|
||||
static void ota_server_status_handler( OTA_STATE_E state, float progress )
|
||||
{
|
||||
char str[64]={0};
|
||||
switch ( state )
|
||||
{
|
||||
case OTA_LOADING:
|
||||
os_log("ota server is loading, progress %.2f%%", progress);
|
||||
break;
|
||||
case OTA_SUCCE:
|
||||
os_log("ota server daemons success");
|
||||
sprintf( str, "{\"mac\":\"%s\",\"ota_progress\":100}", strMac );
|
||||
break;
|
||||
case OTA_FAIL:
|
||||
os_log("ota server daemons failed");
|
||||
sprintf( str, "{\"mac\":\"%s\",\"ota_progress\":-1}", strMac );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(str[0]>0)
|
||||
{
|
||||
user_send(true,str);
|
||||
}
|
||||
}
|
||||
|
||||
void user_ota_start( char *url, char *md5 )
|
||||
{
|
||||
os_log("ready to ota:%s",url);
|
||||
ota_server_start( url, md5, ota_server_status_handler );
|
||||
}
|
||||
|
||||
7
TC1/user_tftp_ota.h
Normal file
7
TC1/user_tftp_ota.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __USER_TFTP_OTA_H_
|
||||
#define __USER_TFTP_OTA_H_
|
||||
|
||||
|
||||
void user_ota_start(char *url, char *md5);
|
||||
|
||||
#endif
|
||||
BIN
build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin
Normal file
BIN
build/TC1@MK3031@moc/binary/TC1@MK3031@moc.all.bin
Normal file
Binary file not shown.
BIN
build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin
Normal file
BIN
build/TC1@MK3031@moc/binary/TC1@MK3031@moc.ota.bin
Normal file
Binary file not shown.
Reference in New Issue
Block a user