mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 13:08:13 +08:00
add:参数初始化
add:wifi未连接时不尝试连接mqtt服务器
This commit is contained in:
53
TC1/main.c
53
TC1/main.c
@@ -11,9 +11,34 @@ user_config_t * user_config;
|
||||
|
||||
mico_gpio_t Relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
||||
|
||||
/* MICO system callback: Restore default configuration provided by application */
|
||||
void appRestoreDefault_callback( void * const user_config_data, uint32_t size )
|
||||
{
|
||||
int i, j;
|
||||
UNUSED_PARAMETER( size );
|
||||
|
||||
sprintf( mico_system_context_get( )->micoSystemConfig.name, ZTC1_NAME );
|
||||
user_config_t* userConfigDefault = user_config_data;
|
||||
userConfigDefault->idx = -1;
|
||||
|
||||
for(i=0;i<PLUG_NUM;i++)
|
||||
{
|
||||
userConfigDefault->plug[i].idx=-1;
|
||||
sprintf( userConfigDefault->plug[i].name, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d",i );
|
||||
for(j=0;j<PLUG_TIME_TASK_NUM;j++)
|
||||
{
|
||||
userConfigDefault->plug[i].task[j].hour=0;
|
||||
userConfigDefault->plug[i].task[j].minute=0;
|
||||
userConfigDefault->plug[i].task[j].repeat=0x80;
|
||||
userConfigDefault->plug[i].task[j].on=0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int application_start( void )
|
||||
{
|
||||
|
||||
int i, j;
|
||||
os_log( "Start" );
|
||||
|
||||
OSStatus err = kNoErr;
|
||||
@@ -22,12 +47,25 @@ int application_start( void )
|
||||
sys_config = mico_system_context_init( sizeof(user_config_t) );
|
||||
user_config = ((system_context_t *) sys_config)->user_config_data;
|
||||
require_action( user_config, exit, err = kNoMemoryErr );
|
||||
os_log( "user config:%d",user_config->val );
|
||||
|
||||
err = mico_system_init( sys_config );
|
||||
require_noerr( err, exit );
|
||||
|
||||
os_log( "idx:%d",user_config->idx );
|
||||
for ( i = 0; i < PLUG_NUM; i++ )
|
||||
{
|
||||
os_log("plug_%d:",i);
|
||||
os_log("\tname:%s:",user_config->plug[i].name);
|
||||
os_log("\tidx:%d:",user_config->plug[i].idx);
|
||||
for ( j = 0; j < PLUG_TIME_TASK_NUM; j++ )
|
||||
{
|
||||
os_log("\t\ton:%d\t %02d:%02d repeat:0x%X",user_config->plug[i].task[j].on,
|
||||
user_config->plug[i].task[j].hour,user_config->plug[i].task[j].minute,
|
||||
user_config->plug[i].task[j].repeat);
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < Relay_NUM; i++ )
|
||||
for ( i = 0; i < Relay_NUM; i++ )
|
||||
{
|
||||
MicoGpioInitialize( Relay[i], OUTPUT_PUSH_PULL );
|
||||
//MicoGpioOutputHigh(Relay[i]);
|
||||
@@ -43,10 +81,17 @@ int application_start( void )
|
||||
MicoGpioInitialize( (mico_gpio_t) MICO_GPIO_5, OUTPUT_PUSH_PULL );
|
||||
led( 0 );
|
||||
|
||||
if ( user_config->plug[0].task[0].hour < 0 || user_config->plug[0].task[0].hour > 23 )
|
||||
{
|
||||
os_log( "WARNGIN: user params restored!" );
|
||||
err = mico_system_context_restore( sys_config );
|
||||
require_noerr( err, exit );
|
||||
}
|
||||
|
||||
wifi_init( );
|
||||
key_init( );
|
||||
user_mqtt_init( );
|
||||
// wifi_start_easylink();
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
// mico_thread_msleep(500);
|
||||
|
||||
30
TC1/main.h
30
TC1/main.h
@@ -4,6 +4,14 @@
|
||||
#include "mico.h"
|
||||
#include "MiCOKit_EXT.h"
|
||||
|
||||
#define ZTC1_NAME "zTC1"
|
||||
|
||||
#define PLUG_NAME_LENGTH 32
|
||||
#define PLUG_NUM 6 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define PLUG_TIME_TASK_NUM 5 //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD>鶨ʱ<E9B6A8><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
|
||||
|
||||
#define Led MICO_GPIO_5
|
||||
#define Button MICO_GPIO_23
|
||||
|
||||
@@ -13,12 +21,30 @@
|
||||
#define Relay_3 MICO_GPIO_9
|
||||
#define Relay_4 MICO_GPIO_10
|
||||
#define Relay_5 MICO_GPIO_18
|
||||
#define Relay_NUM 6
|
||||
#define Relay_NUM PLUG_NUM
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
char hour; //Сʱ
|
||||
char minute; //<2F><><EFBFBD><EFBFBD>
|
||||
uint8_t repeat; //bit7:һ<><D2BB> bit6-0:<3A><><EFBFBD><EFBFBD>-<2D><>һ
|
||||
char on; //<2F><><EFBFBD><EFBFBD>
|
||||
|
||||
} user_plug_task_config_t;
|
||||
|
||||
typedef struct {
|
||||
char name[PLUG_NAME_LENGTH];
|
||||
char idx;
|
||||
user_plug_task_config_t task[PLUG_TIME_TASK_NUM];
|
||||
|
||||
} user_plug_config_t;
|
||||
|
||||
//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
||||
typedef struct {
|
||||
char val;
|
||||
char idx;
|
||||
user_plug_config_t plug[PLUG_NUM];
|
||||
} user_config_t;
|
||||
|
||||
extern system_config_t * sys_config;
|
||||
|
||||
@@ -240,8 +240,16 @@ MQTT_start:
|
||||
#else
|
||||
ssl_settings.ssl_enable = false;
|
||||
#endif
|
||||
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
while( 1 ){
|
||||
|
||||
micoWlanGetLinkStatus(&LinkStatus);
|
||||
if(LinkStatus.is_connected!=1){
|
||||
mqtt_log("ERROR:WIFI not connection , waiting 3s for connecting and then connecting MQTT ", rc);
|
||||
mico_rtos_thread_sleep( 3 );
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = NewNetwork( &n, MQTT_SERVER, MQTT_SERVER_PORT, ssl_settings );
|
||||
if( rc == MQTT_SUCCESS ) break;
|
||||
mqtt_log("ERROR: MQTT network connection err=%d, reconnect after 3s...", rc);
|
||||
|
||||
Reference in New Issue
Block a user