diff --git a/README.md b/README.md
index 4548b5c..6db01bd 100644
--- a/README.md
+++ b/README.md
@@ -196,7 +196,7 @@ SmartConfig是安信可提供的一种快捷配网方式,将esp8266设置为
- “关联延时”:该定时任务执行完成后会自动启动关联的延时任务。
-- “重复”:若周一到周日都没选择则该任务只执行一次。
+- “重复”:若周一到周日都没选择则该任务只执行一次。(新加功能:智能跳过节假日,从互联网获取节假日信息只在法定节假日生效。)
![](media/6a8322aed50869bf983582514a592960.png)
@@ -423,7 +423,7 @@ SmartConfig是安信可提供的一种快捷配网方式,将esp8266设置为
无
-**响应码:**200:成功,其他:失败
+**响应码:** 200:成功,其他:失败
**响应:**
diff --git a/html/index.html b/html/index.html
index 345f57d..3aca535 100644
--- a/html/index.html
+++ b/html/index.html
@@ -710,6 +710,7 @@
定时
+
diff --git a/html/index.js b/html/index.js
index ce1be0d..f0bd980 100644
--- a/html/index.js
+++ b/html/index.js
@@ -496,6 +496,9 @@ function weekConversionString( week ) {
if ( week == 96 ){
return "周末";
}
+ if ( week == 128 ){
+ return "跳过节假日";
+ }
var str="";
for ( var i = 0; i < 7; i++ ){
@@ -522,6 +525,7 @@ function stringConversionWeek() {
if( $("#week5").is(':checked') ){week=week|(1<<4)}
if( $("#week6").is(':checked') ){week=week|(1<<5)}
if( $("#week7").is(':checked') ){week=week|(1<<6)}
+ if( $("#week8").is(':checked') ){week=week|(1<<7)}
return week;
}
@@ -1014,7 +1018,7 @@ function tabTimerSubmit(){
$("#timerCascodeNum").val(data[0].CascodeNum);
$("#timerCascodeEnable").attr('checked',data[0].Cascode);
var week= parseInt(data[0].Week);
- for ( var i = 0; i < 7; i++ ){
+ for ( var i = 0; i < 8; i++ ){
switch(i){
case 0: $("#week1").prop('checked',week&(1<eWeek & (1 << (ucWeek-1)) )
+
+ // ڼ
+ if ( pstTimer->eWeek == REPET_AUTO )
+ {
+ ucHoliday = PLUG_Isholiday();
+ if ( ucHoliday == DAY_Weekends ||
+ ucHoliday == DAY_Festivals ||
+ ucHoliday == DAY_BUFF )
+ {
+ // ĩ
+ continue;
+ }
+
+ PLUG_SetRelayOn( TRUE );
+ bIsJudged = TRUE;
+ }
+ else if ( pstTimer->eWeek & (1 << (ucWeek-1)) )
{
PLUG_SetRelayOn( TRUE );
bIsJudged = TRUE;
@@ -2362,7 +2380,22 @@ static VOID PLUG_JudgeTimer( VOID )
pstTimer->stOffTime.iMinute == stDate.iMinute &&
FALSE == bIsJudged)
{
- if ( pstTimer->eWeek & (1 << (ucWeek-1)) )
+ if ( pstTimer->eWeek == REPET_AUTO )
+ {
+ // ڼ
+ ucHoliday = PLUG_Isholiday();
+ if ( ucHoliday == DAY_Weekends ||
+ ucHoliday == DAY_Festivals ||
+ ucHoliday == DAY_BUFF )
+ {
+ // ĩ
+ continue;
+ }
+
+ PLUG_SetRelayOff( TRUE );
+ bIsJudged = TRUE;
+ }
+ else if ( pstTimer->eWeek & (1 << (ucWeek-1)) )
{
PLUG_SetRelayOff( TRUE );
bIsJudged = TRUE;
@@ -2650,4 +2683,132 @@ VOID PLUG_StartJudgeTimeHanderTimer( VOID )
}
}
+typedef struct tagParseHolidayPara{
+ HTTP_CLIENT_S* pstCli;
+ UINT8 uiHoliday;
+}MQTT_ParseHolidayPara_S;
+
+
+UINT8 PLUG_Isholiday()
+{
+ HTTP_CLIENT_S* pstCli = NULL;
+ CHAR szBuf[120] = {0};
+ UINT uiRet = 0;
+ UINT8 uiRetry = 0;
+ PLUG_DATE_S stDate;
+ MQTT_ParseHolidayPara_S stHolidayPara;
+
+ if ( WIFI_GetWifiConnStatus() != STATION_GOT_IP )
+ {
+ LOG_OUT(LOGOUT_ERROR, "not connect wifi");
+ return DAY_BUFF;
+ }
+
+retry:
+ if ( uiRetry >= 3 )
+ {
+ LOG_OUT(LOGOUT_ERROR, "HTTP_ClientDoRequest timeout, retry exceeds maximum");
+ goto end;
+ }
+
+ PLUG_GetDate( &stDate );
+ sprintf(szBuf, "/api/holiday/info/%d-%02d-%02d", stDate.iYear, stDate.iMonth, stDate.iDay);
+ pstCli = HTTP_NewClient("GET", "timor.tech", szBuf, "", 0);
+ if ( pstCli == NULL )
+ {
+ LOG_OUT(LOGOUT_ERROR, "HTTP_NewClient failed");
+ goto end;
+ }
+
+ uiRet = HTTP_ClientDoRequest(pstCli);
+ if ( uiRet != 0 )
+ {
+ LOG_OUT(LOGOUT_ERROR, "HTTP_ClientDoRequest failed");
+ goto end;
+ }
+
+ stHolidayPara.pstCli = pstCli;
+ stHolidayPara.uiHoliday = DAY_BUFF;
+ uiRet = HTTP_ClientDoResponse(pstCli, PLUG_ParseHolidayToday, (VOID*)&stHolidayPara);
+ if ( uiRet == -1 )
+ {
+ LOG_OUT(LOGOUT_ERROR, "HTTP_ClientDoRequest failed");
+ goto end;
+ }
+ // ճʱ
+ else if ( uiRet == -2 )
+ {
+ LOG_OUT(LOGOUT_ERROR, "HTTP_ClientDoRequest timeout, retry...");
+ HTTP_DestoryClient(pstCli);
+ goto retry;
+ }
+
+end:
+ HTTP_DestoryClient(pstCli);
+ return stHolidayPara.uiHoliday;
+}
+
+
+UINT PLUG_ParseHolidayToday( VOID* pData )
+{
+ cJSON *pJsonRoot = NULL;
+ cJSON *pJsonIteam = NULL;
+ MQTT_ParseHolidayPara_S *stHolidayPara = pData;
+ HTTP_CLIENT_S *pstCli = NULL;
+ UINT uiRet = OK;
+
+ if ( stHolidayPara == NULL )
+ {
+ LOG_OUT(LOGOUT_ERROR, "stHolidayPara is NULL");
+ return FAIL;
+ }
+
+ pstCli = stHolidayPara->pstCli;
+ if ( pstCli == NULL )
+ {
+ LOG_OUT(LOGOUT_ERROR, "pstCli:%p", pstCli);
+ return FAIL;
+ }
+
+ if (pstCli->stReson.eHttpCode != HTTP_CODE_Ok )
+ {
+ LOG_OUT(LOGOUT_ERROR, "get response code: %s", szHttpCodeMap[pstCli->stReson.eHttpCode]);
+ return FAIL;
+ }
+
+ pJsonRoot = cJSON_Parse( pstCli->stReson.pcBody );
+ if ( pJsonRoot == NULL )
+ {
+ LOG_OUT(LOGOUT_ERROR, "cJSON_Parse failed, pcBody:%s", pstCli->stReson.pcBody);
+ uiRet = FAIL;
+ goto exit;
+ }
+
+ pJsonIteam = cJSON_GetObjectItem(pJsonRoot, "code");
+ if (pJsonIteam && pJsonIteam->type == cJSON_Number && pJsonIteam->valueint != 0 )
+ {
+ LOG_OUT(LOGOUT_ERROR, "expect 0 but got %d", pJsonIteam->valueint);
+ uiRet = FAIL;
+ goto exit;
+ }
+
+ pJsonIteam = cJSON_GetObjectItem(pJsonRoot, "type");
+ if (pJsonIteam && pJsonIteam->type == cJSON_Object )
+ {
+ pJsonIteam = cJSON_GetObjectItem(pJsonIteam, "type");
+ if (pJsonIteam && pJsonIteam->type == cJSON_Number )
+ {
+ stHolidayPara->uiHoliday = pJsonIteam->valueint;
+ uiRet = OK;
+ }
+ }
+
+ LOG_OUT(LOGOUT_INFO, "holiday type %d", stHolidayPara->uiHoliday);
+
+exit:
+ cJSON_Delete(pJsonRoot);
+ return uiRet;
+}
+
+
diff --git a/plug2.0/app/user/user_wifi.c b/plug2.0/app/user/user_wifi.c
index 8fa4283..fe6dc6d 100644
--- a/plug2.0/app/user/user_wifi.c
+++ b/plug2.0/app/user/user_wifi.c
@@ -904,29 +904,8 @@ UINT WIFI_DeviceInfoMarshalJson( CHAR* pcBuf, UINT uiBufLen)
return strlen(pcBuf);
}
-UINT WIFI_TemperatureMarshalJson( CHAR* pcBuf, UINT uiBufLen)
+UINT WIFI_GetWifiConnStatus()
{
- cJSON *pJson = NULL;
- CHAR *pJsonStr = NULL;
- CHAR szBuf[20];
-
- pJson = cJSON_CreateObject();
-
- cJSON_AddNumberToObject( pJson, "Temperature", PLUG_GetRunTime());
-
- pJsonStr = cJSON_PrintUnformatted(pJson);
- if ( pJsonStr != NULL )
- {
- strncpy(pcBuf, pJsonStr, uiBufLen);
- }
- else
- {
- snprintf(pcBuf, uiBufLen, "{}");
- }
-
- cJSON_Delete(pJson);
- FREE_MEM(pJsonStr);
-
- return strlen(pcBuf);
+ return uiCurStatus;
}