mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-14 14:08:19 +08:00
add:定时任务数据放回
add:关闭系统led灯 add:上电初始化继电器状态
This commit is contained in:
@@ -106,8 +106,11 @@ int application_start( void )
|
|||||||
}
|
}
|
||||||
|
|
||||||
MicoGpioInitialize( (mico_gpio_t) MICO_GPIO_5, OUTPUT_PUSH_PULL );
|
MicoGpioInitialize( (mico_gpio_t) MICO_GPIO_5, OUTPUT_PUSH_PULL );
|
||||||
user_led_set( 0 );
|
for ( i = 0; i < Relay_NUM; i++ )
|
||||||
|
{
|
||||||
|
user_relay_set(i,user_config->plug[i].on);
|
||||||
|
}
|
||||||
|
MicoSysLed(0);
|
||||||
if ( user_config->version != USER_CONFIG_VERSION || user_config->plug[0].task[0].hour < 0 || user_config->plug[0].task[0].hour > 23 )
|
if ( user_config->version != USER_CONFIG_VERSION || user_config->plug[0].task[0].hour < 0 || user_config->plug[0].task[0].hour > 23 )
|
||||||
{
|
{
|
||||||
os_log( "WARNGIN: user params restored!" );
|
os_log( "WARNGIN: user params restored!" );
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
|||||||
cJSON *p_cmd = cJSON_GetObjectItem( pJsonRoot, "cmd" );
|
cJSON *p_cmd = cJSON_GetObjectItem( pJsonRoot, "cmd" );
|
||||||
if ( p_cmd && cJSON_IsString( p_cmd ) && strcmp( p_cmd->valuestring, "device report" ) == 0 )
|
if ( p_cmd && cJSON_IsString( p_cmd ) && strcmp( p_cmd->valuestring, "device report" ) == 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
cJSON *pRoot = cJSON_CreateObject( );
|
cJSON *pRoot = cJSON_CreateObject( );
|
||||||
cJSON_AddStringToObject( pRoot, "name", sys_config->micoSystemConfig.name );
|
cJSON_AddStringToObject( pRoot, "name", sys_config->micoSystemConfig.name );
|
||||||
cJSON_AddStringToObject( pRoot, "mac", strMac );
|
cJSON_AddStringToObject( pRoot, "mac", strMac );
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "sntp.h"
|
#include "sntp.h"
|
||||||
#include "user_sntp.h"
|
#include "user_sntp.h"
|
||||||
|
#include "cJSON/cJSON.h"
|
||||||
|
|
||||||
void rtc_thread( mico_thread_arg_t arg );
|
void rtc_thread( mico_thread_arg_t arg );
|
||||||
|
|
||||||
@@ -107,6 +108,7 @@ OSStatus user_rtc_init( void )
|
|||||||
void rtc_thread( mico_thread_arg_t arg )
|
void rtc_thread( mico_thread_arg_t arg )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
char task_flag[PLUG_NUM] = { -1, -1, -1, -1, -1, -1 }; //<2F><>¼ÿ<C2BC><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
OSStatus err = kUnknownErr;
|
OSStatus err = kUnknownErr;
|
||||||
LinkStatusTypeDef LinkStatus;
|
LinkStatusTypeDef LinkStatus;
|
||||||
mico_rtc_time_t rtc_time;
|
mico_rtc_time_t rtc_time;
|
||||||
@@ -131,7 +133,6 @@ void rtc_thread( mico_thread_arg_t arg )
|
|||||||
|
|
||||||
while ( 1 )
|
while ( 1 )
|
||||||
{
|
{
|
||||||
|
|
||||||
mico_time_get_utc_time( &utc_time );
|
mico_time_get_utc_time( &utc_time );
|
||||||
utc_time += 28800;
|
utc_time += 28800;
|
||||||
struct tm * currentTime = localtime( (const time_t *) &utc_time );
|
struct tm * currentTime = localtime( (const time_t *) &utc_time );
|
||||||
@@ -164,9 +165,30 @@ void rtc_thread( mico_thread_arg_t arg )
|
|||||||
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
user_relay_set( i, user_config->plug[i].task[j].action );
|
if ( user_config->plug[i].on = user_config->plug[i].task[j].action )
|
||||||
|
{
|
||||||
|
user_relay_set( i, user_config->plug[i].task[j].action );
|
||||||
|
update_user_config_flag = 1;
|
||||||
|
|
||||||
|
//<2F><><EFBFBD><EFBFBD>domoticz״̬
|
||||||
|
if ( user_config->plug[i].idx >= 0 )
|
||||||
|
{
|
||||||
|
uint8_t *buf = NULL;
|
||||||
|
buf = malloc( 32 ); //idxΪ1λʱ<CEBB><CAB1><EFBFBD><EFBFBD>Ϊ24
|
||||||
|
if ( buf != NULL )
|
||||||
|
{
|
||||||
|
sprintf( buf, "{\"idx\":%d,\"nvalue\":%d}", user_config->plug[i].idx, user_config->plug[i].on );
|
||||||
|
if ( !user_mqtt_isconnect( ) )
|
||||||
|
user_udp_send( buf ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
else
|
||||||
|
user_mqtt_send( buf );
|
||||||
|
free( buf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( repeat == 0x00 )
|
if ( repeat == 0x00 )
|
||||||
{
|
{
|
||||||
|
task_flag[i] = j;
|
||||||
user_config->plug[i].task[j].on = 0;
|
user_config->plug[i].task[j].on = 0;
|
||||||
update_user_config_flag = 1;
|
update_user_config_flag = 1;
|
||||||
}
|
}
|
||||||
@@ -178,8 +200,51 @@ void rtc_thread( mico_thread_arg_t arg )
|
|||||||
//<2F><><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>¶<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
//<2F><><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>¶<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
if ( update_user_config_flag == 1 )
|
if ( update_user_config_flag == 1 )
|
||||||
{
|
{
|
||||||
|
os_log("update_user_config_flag");
|
||||||
mico_system_context_update( sys_config );
|
mico_system_context_update( sys_config );
|
||||||
update_user_config_flag = 0;
|
update_user_config_flag = 0;
|
||||||
|
|
||||||
|
cJSON *json_send = cJSON_CreateObject( );
|
||||||
|
cJSON_AddStringToObject( json_send, "mac", strMac );
|
||||||
|
|
||||||
|
for ( i = 0; i < PLUG_NUM; i++ )
|
||||||
|
{
|
||||||
|
char strTemp1[] = "plug_X";
|
||||||
|
strTemp1[5] = i + '0';
|
||||||
|
cJSON *json_send_plug = cJSON_CreateObject( );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug, "on", user_config->plug[i].on );
|
||||||
|
|
||||||
|
if ( task_flag[i] >= 0 )
|
||||||
|
{
|
||||||
|
cJSON *json_send_plug_setting = cJSON_CreateObject( );
|
||||||
|
|
||||||
|
j = task_flag[i];
|
||||||
|
char strTemp2[] = "task_X";
|
||||||
|
strTemp2[5] = j + '0';
|
||||||
|
cJSON *json_send_plug_task = cJSON_CreateObject( );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug_task, "hour", user_config->plug[i].task[j].hour );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug_task, "minute", user_config->plug[i].task[j].minute );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug_task, "repeat", user_config->plug[i].task[j].repeat );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug_task, "action", user_config->plug[i].task[j].action );
|
||||||
|
cJSON_AddNumberToObject( json_send_plug_task, "on", user_config->plug[i].task[j].on );
|
||||||
|
cJSON_AddItemToObject( json_send_plug_setting, strTemp2, json_send_plug_task );
|
||||||
|
|
||||||
|
cJSON_AddItemToObject( json_send_plug, "setting", json_send_plug_setting );
|
||||||
|
|
||||||
|
task_flag[i]=-1;
|
||||||
|
}
|
||||||
|
cJSON_AddItemToObject( json_send, strTemp1, json_send_plug );
|
||||||
|
}
|
||||||
|
|
||||||
|
char *json_str = cJSON_Print( json_send );
|
||||||
|
if ( !user_mqtt_isconnect( ) )
|
||||||
|
user_udp_send( json_str ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
else
|
||||||
|
user_mqtt_send( json_str );
|
||||||
|
|
||||||
|
free( json_str );
|
||||||
|
cJSON_Delete( json_send );
|
||||||
|
os_log("cJSON_Delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
//SNTP<54><50><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
//SNTP<54><50><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿСʱУһ<D7BC><D2BB>
|
||||||
|
|||||||
Reference in New Issue
Block a user