Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code
Revision 34:601effb7b7fe, committed 2018-02-14
- Comitter:
- DuyLionTran
- Date:
- Wed Feb 14 03:56:34 2018 +0000
- Parent:
- 33:5b90257d2d57
- Child:
- 35:fc800d35c1ba
- Commit message:
- * version 2.5 02-14-2017: 3rd relay is added
Changed in this revision
--- a/Application/CommandExecution.cpp Sun Jan 21 13:04:06 2018 +0000
+++ b/Application/CommandExecution.cpp Wed Feb 14 03:56:34 2018 +0000
@@ -3,8 +3,10 @@
DigitalOut relay1(RELAY_1_PIN);
DigitalOut relay2(RELAY_2_PIN);
+DigitalOut relay3(RELAY_3_PIN);
-void CE_HandleRelays(int Relay1State, int Relay2State) {
+void CE_HandleRelays(int Relay1State, int Relay2State, int Relay3State) {
relay1 = Relay1State;
relay2 = Relay2State;
+ relay3 = Relay3State;
}
--- a/Application/CommandExecution.h Sun Jan 21 13:04:06 2018 +0000 +++ b/Application/CommandExecution.h Wed Feb 14 03:56:34 2018 +0000 @@ -1,9 +1,10 @@ #ifndef __COMMANDEXECUTION_H__ #define __COMMANDEXECUTION_H__ -#define RELAY_1_PIN (D12) +#define RELAY_1_PIN (D10) #define RELAY_2_PIN (D11) +#define RELAY_3_PIN (D12) -void CE_HandleRelays(int Relay1State, int Relat2State); +void CE_HandleRelays(int Relay1State, int Relat2State, int Relat3State); #endif /* __COMMANDEXECUTION_H__ */ \ No newline at end of file
--- a/Application/main.cpp Sun Jan 21 13:04:06 2018 +0000
+++ b/Application/main.cpp Wed Feb 14 03:56:34 2018 +0000
@@ -1,4 +1,9 @@
-// For receiving message handles, search "Message Handles" in SimpleMQTT.h
+/**
+ * Revision
+ * version 1.0
+ * ....
+ * version 2.5 02-14-2017: 3rd relay is added
+ */
/***************************************************************
* Includes
@@ -37,6 +42,8 @@
static Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
+DigitalOut espEn(D2);
+DigitalOut espRs(D7);
Timer UploadTimer;
/***************************************************************
@@ -54,6 +61,7 @@
DataStruct.SENSOR_D0Val = 18.9;
DataStruct.RELAY_State_1 = FP_ReadValue(RELAY1_ADDRESS);
DataStruct.RELAY_State_2 = FP_ReadValue(RELAY2_ADDRESS);
+ DataStruct.RELAY_State_2 = FP_ReadValue(RELAY3_ADDRESS);
DataStruct.CONFIG_Mode = FP_ReadValue(MODE_ADDRESS);
DataStruct.CONFIG_MinOxi = FP_ReadValue(MIN_OXI_ADDRESS);
DataStruct.CONFIG_MaxOxi = FP_ReadValue(MAX_OXI_ADDRESS);
@@ -61,7 +69,7 @@
printf("All values: %d %d %d %d %d %d\r\n", DataStruct.RELAY_State_1, DataStruct.RELAY_State_2,
DataStruct.CONFIG_Mode, DataStruct.CONFIG_MinOxi,
DataStruct.CONFIG_MaxOxi, DataStruct.CONFIG_UploadInterval);
- CE_HandleRelays(DataStruct.RELAY_State_1, DataStruct.RELAY_State_2);
+ CE_HandleRelays(DataStruct.RELAY_State_1, DataStruct.RELAY_State_2, DataStruct.RELAY_State_3);
}
/***************************************************************
@@ -70,8 +78,10 @@
int main() {
pc.baud(115200);
UploadTimer.start();
+ espEn = 1;
+ espRs = 1;
lastRead = 0;
-// set_time(1515453021);
+// set_time(1517270400);
pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n");
pc.printf("\r\nconnecting to AP\r\n");
--- a/Flash/flash_programming.cpp Sun Jan 21 13:04:06 2018 +0000
+++ b/Flash/flash_programming.cpp Wed Feb 14 03:56:34 2018 +0000
@@ -38,7 +38,7 @@
return ReturnValue;
}
-int FP_WriteRelayStates(uint8_t RelayState1, uint8_t RelayState2) {
+int FP_WriteRelayStates(uint8_t RelayState1, uint8_t RelayState2, uint8_t RelayState3) {
uint8_t CurrentPage = FP_GetPage(RELAY_BASE_ADDRESS);
uint32_t CurrentAddress = RELAY1_ADDRESS;
@@ -53,7 +53,8 @@
HAL_FLASH_Unlock();
if ((FP_ReadValue(RELAY1_ADDRESS) == RelayState1) &&
- (FP_ReadValue(RELAY2_ADDRESS) == RelayState2)) {
+ (FP_ReadValue(RELAY2_ADDRESS) == RelayState2) &&
+ (FP_ReadValue(RELAY3_ADDRESS) == RelayState3)) {
printf("Relay values don't change, no need to write\r\n");
HAL_FLASH_Lock();
return PASSED;
@@ -61,7 +62,7 @@
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PageError) != HAL_OK) {
printf("Erase error, error num %d\r\n", HAL_FLASH_GetError());
}
- while (CurrentAddress < (RELAY2_ADDRESS + STEP_ADDRESS)) {
+ while (CurrentAddress < (RELAY3_ADDRESS + STEP_ADDRESS)) {
switch (CurrentAddress) {
case (RELAY1_ADDRESS): if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CurrentAddress, RelayState1) == HAL_OK) {
printf("Write Relay 1 State OK\r\n");
@@ -76,6 +77,12 @@
else {
printf("Write Relay 2 State failed, error num %d\r\n", HAL_FLASH_GetError());
}
+ case (RELAY3_ADDRESS): if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, CurrentAddress, RelayState3) == HAL_OK) {
+ printf("Write Relay 3 State OK\r\n");
+ }
+ else {
+ printf("Write Relay 3 State failed, error num %d\r\n", HAL_FLASH_GetError());
+ }
break;
default: break;
}
@@ -83,7 +90,7 @@
}
CurrentAddress = RELAY1_ADDRESS;
- while (CurrentAddress < (RELAY2_ADDRESS + STEP_ADDRESS)) {
+ while (CurrentAddress < (RELAY3_ADDRESS + STEP_ADDRESS)) {
switch (CurrentAddress) {
case (RELAY1_ADDRESS): if (FP_ReadValue(CurrentAddress) == RelayState1) {
printf("Read back Relay 1 State: %d\r\n", FP_ReadValue(CurrentAddress));
@@ -103,6 +110,15 @@
return FAILED;
}
break;
+ case (RELAY3_ADDRESS): if (FP_ReadValue(CurrentAddress) == RelayState3) {
+ printf("Read back Relay 3 State: %d\r\n", FP_ReadValue(CurrentAddress));
+ }
+ else {
+ printf("Write Relay 3 State failed, wrong read back value\r\n");
+ HAL_FLASH_Lock();
+ return FAILED;
+ }
+ break;
default: break;
}
CurrentAddress = CurrentAddress + STEP_ADDRESS;
--- a/Flash/flash_programming.h Sun Jan 21 13:04:06 2018 +0000 +++ b/Flash/flash_programming.h Wed Feb 14 03:56:34 2018 +0000 @@ -140,6 +140,7 @@ #define RELAY1_ADDRESS (RELAY_BASE_ADDRESS + STEP_ADDRESS) #define RELAY2_ADDRESS (RELAY1_ADDRESS + STEP_ADDRESS) +#define RELAY3_ADDRESS (RELAY2_ADDRESS + STEP_ADDRESS) #define MODE_ADDRESS (CONF_BASE_ADDRESS + STEP_ADDRESS) #define MIN_OXI_ADDRESS (MODE_ADDRESS + STEP_ADDRESS) @@ -170,9 +171,10 @@ * @brief Write the states of relays into the flash memory * @param RelayState1: Relay 1 state * @param RelayState2: Relay 2 state + * @param RelayState3: Relay 3 state * @retval FLASH result */ -int FP_WriteRelayStates(uint8_t RelayState1, uint8_t RelayState2); +int FP_WriteRelayStates(uint8_t RelayState1, uint8_t RelayState2, uint8_t RelayState3); /** * @brief Write the time to activate an event into the flash memory
--- a/Simple-MQTT/SimpleMQTT.h Sun Jan 21 13:04:06 2018 +0000
+++ b/Simple-MQTT/SimpleMQTT.h Wed Feb 14 03:56:34 2018 +0000
@@ -49,7 +49,8 @@
uint8_t RELAY_State_1;
uint8_t RELAY_State_2;
-
+ uint8_t RELAY_State_3;
+
uint32_t CONFIG_Time;
uint8_t CONFIG_Mode;
@@ -184,7 +185,7 @@
printf("Command Type: %d, error %d\r\n", CommandType, ret);
switch (CommandType) {
- case 3: int relayState1, relayState2;
+ case 3: int relayState1, relayState2, relayState3;
KeyIndex = json.findKeyIndexIn("cmdID", 0);
KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
ret = json.tokenIntegerValue(KeyValueIndex, receiveCmdID);
@@ -197,10 +198,16 @@
KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
ret = json.tokenIntegerValue(KeyValueIndex, relayState2);
+ KeyIndex = json.findKeyIndexIn("relayState3", 0);
+ KeyValueIndex = json.findChildIndexOf(KeyIndex, 0);
+ ret = json.tokenIntegerValue(KeyValueIndex, relayState3);
+
DataStruct.RELAY_State_1 = relayState1;
DataStruct.RELAY_State_2 = relayState2;
- FP_WriteRelayStates(DataStruct.RELAY_State_1, DataStruct.RELAY_State_2);
- CE_HandleRelays(relayState1, 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 4: int mode, minOxiVal, maxOxiVal, uploadInterval;