iot_water_monitor_v2

Dependencies:   easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code

Revision:
50:5a19fc4b41d9
Parent:
48:a7ed665844cd
Child:
52:5546fa1b67b5
--- a/Simple-MQTT/SimpleMQTT.h	Sun Mar 18 04:30:18 2018 +0000
+++ b/Simple-MQTT/SimpleMQTT.h	Sun Mar 18 17:54:50 2018 +0000
@@ -62,7 +62,11 @@
 	uint8_t  CONFIG_Mode;
 	uint8_t  CONFIG_OxyThreshold;
 	uint8_t  CONFIG_TemperatureThreshold;
-	uint16_t CONFIG_UploadInterval;
+	uint16_t CONFIG_UploadInterval;              /* in second */
+	
+	uint32_t CONFIG_AlarmTime;
+    uint8_t  CONFIG_SetRelayState_1;
+    uint8_t  CONFIG_SetRelayState_2;	
 } UploadValue; 
  
 char       *projectName     = "WaterMonitor";
@@ -196,6 +200,27 @@
             	break;
             	
             	case 1: printf("Set relay alarm state\r\n");
+            			int AlarmTime, SetRelayState1, SetRelayState2;
+            			KeyIndex      = json.findKeyIndexIn("cmdID", 0);
+            			KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
+            			ret = json.tokenIntegerValue(KeyValueIndex, receiveCmdID); 
+            			
+            			KeyIndex      = json.findKeyIndexIn("AlarmTime", 0);
+            			KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
+            			ret = json.tokenIntegerValue(KeyValueIndex, AlarmTime); 
+            			
+            			KeyIndex      = json.findKeyIndexIn("SetRelayState1", 0);
+            			KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
+            			ret = json.tokenIntegerValue(KeyValueIndex, SetRelayState1);
+            			
+            			KeyIndex      = json.findKeyIndexIn("SetRelayState2", 0);
+            			KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
+            			ret = json.tokenIntegerValue(KeyValueIndex, SetRelayState2);
+            			
+            			DataStruct.CONFIG_AlarmTime       = AlarmTime;
+            			DataStruct.CONFIG_SetRelayState_1 = SetRelayState1;
+            			DataStruct.CONFIG_SetRelayState_2 = SetRelayState2;
+            			FP_SetAlarmValues(DataStruct.CONFIG_AlarmTime, DataStruct.CONFIG_SetRelayState_1, DataStruct.CONFIG_SetRelayState_2);            			
             	break;
             	
             	case 2: printf("Set relay state\r\n");
@@ -216,12 +241,14 @@
             			KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
             			ret = json.tokenIntegerValue(KeyValueIndex, relayState3);
             			
-            			DataStruct.RELAY_State_1 = relayState1;     
-            			DataStruct.RELAY_State_2 = relayState2;   
-            			DataStruct.RELAY_State_3 = relayState3;   
-            			
-            			FP_WriteRelayStates(DataStruct.RELAY_State_1, DataStruct.RELAY_State_2, DataStruct.RELAY_State_3);      		
-            			CE_HandleRelays(relayState1, relayState2, relayState3);
+            			if (DataStruct.CONFIG_Mode == 1) {
+	             			DataStruct.RELAY_State_1 = relayState1;     
+	            			DataStruct.RELAY_State_2 = relayState2;   
+	            			DataStruct.RELAY_State_3 = relayState3;     
+	            			FP_WriteRelayStates(DataStruct.RELAY_State_1, DataStruct.RELAY_State_2, DataStruct.RELAY_State_3);      		
+	            			CE_HandleRelays(relayState1, relayState2, relayState3);       				
+            			}
+  
             	break;
             	
             	case 3: printf("Set config values\r\n");