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 47:c3707a4f69a7, committed 2018-03-08
- Comitter:
- DuyLionTran
- Date:
- Thu Mar 08 14:19:48 2018 +0000
- Parent:
- 46:f545b8f7f242
- Child:
- 48:a7ed665844cd
- Commit message:
- * version 2.7.5a 03-08-2018: DS18B20 problem discovered at line 42th ReadSensor.cpp; Upload RTC time converted to epoch
Changed in this revision
| Application/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Simple-MQTT/SimpleMQTT.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Application/main.cpp Thu Mar 08 13:59:35 2018 +0000
+++ b/Application/main.cpp Thu Mar 08 14:19:48 2018 +0000
@@ -10,6 +10,7 @@
* version 2.7 03-04-2018: DO calibration complete. IWDG is added
* version 2.7.5 03-08-2018: DS18B20 & IWDG is being developed
* version 2.7.5a 03-08-2018: DS18B20 problem discovered at line 42th ReadSensor.cpp
+ Upload RTC time converted to epoch
*/
/***************************************************************
@@ -43,7 +44,7 @@
***************************************************************/
bool isUploading = false;
bool isSendingData = false;
-uint8_t uploadType = ADC_VALUE;
+uint8_t uploadType = SENSOR_VALUE;
uint8_t currentCalibMode = 1;
uint8_t calibStateCounter = 0;
@@ -92,10 +93,10 @@
* Unity function declarations
***************************************************************/
void ReadAllFlashValues() {
- DataStruct.ADC_TEMPVal = 0;
- DataStruct.ADC_DOVal = 0;
- DataStruct.SENSOR_TEMPVal = 0;
- DataStruct.SENSOR_DOVal = 0;
+ DataStruct.ADC_TEMPVal = 0;
+ DataStruct.ADC_DOVal = 0;
+ DataStruct.SENSOR_TEMPVal = 0;
+ DataStruct.SENSOR_DOVal = 0;
DataStruct.RELAY_State_1 = FP_ReadValue(RELAY1_ADDRESS);
DataStruct.RELAY_State_2 = FP_ReadValue(RELAY2_ADDRESS);
DataStruct.RELAY_State_3 = FP_ReadValue(RELAY3_ADDRESS);
@@ -110,24 +111,29 @@
}
void SensorRun() {
- for (uint8_t j = 0; j < SCOUNT; j++) {
- SENSOR_AnalogRead();
+ if (!isSendingData) {
+ for (uint8_t j = 0; j < SCOUNT; j++) {
+ SENSOR_AnalogRead();
+ }
+ SENSOR_GetDOValue();
+ DataStruct.SENSOR_DOVal = doValue;
+ DataStruct.SENSOR_TEMPVal = temperature;
+ if (isCalibrating) {
+ SENSOR_DoCalibration(currentCalibMode);
+ if (currentCalibMode == 3) {
+ currentCalibMode = 1;
+ isCalibrating = false;
+ }
+ calibStateCounter++;
+
+ /* Change calibration mode every PROCESS_SENSOR_VALUE_S*CALIB_STATE_CHANGE_PERIOD_S second(s) */
+ if ((calibStateCounter % CALIB_STATE_CHANGE_PERIOD_S) == 0) {
+ currentCalibMode++;
+ }
+ }
}
- SENSOR_GetDOValue();
- DataStruct.SENSOR_DOVal = doValue;
- DataStruct.SENSOR_TEMPVal = temperature;
- if (isCalibrating) {
- SENSOR_DoCalibration(currentCalibMode);
- if (currentCalibMode == 3) {
- currentCalibMode = 1;
- isCalibrating = false;
- }
- calibStateCounter++;
-
- /* Change calibration mode every PROCESS_SENSOR_VALUE_S*CALIB_STATE_CHANGE_PERIOD_S second(s) */
- if ((calibStateCounter % CALIB_STATE_CHANGE_PERIOD_S) == 0) {
- currentCalibMode++;
- }
+ else {
+ printf("No sensor reading because uploading data\r\n");
}
}
@@ -206,13 +212,13 @@
}
else {
if (intervalSecondCounter == INTERVAL_BETWEEN_EACH_UPLOAD_TYPE) {
-
+ isSendingData = true;
if (MQTT_PublishAll(&client, seconds, uploadType, DataStruct) == MQTT::SUCCESS) {
myled = 1;
uploadType++;
if (uploadType > CONFIG_VALUE) {
isUploading = false;
- uploadType = ADC_VALUE;
+ uploadType = SENSOR_VALUE;
commandID++;
UploadTimer.reset();
}
@@ -223,7 +229,8 @@
mqttNetwork.disconnect();
/* if we have lost the connection */
MQTT_AttemptConnect(&client, &mqttNetwork, network, DataStruct);
- }
+ }
+ isSendingData = false;
intervalSecondCounter = 0;
}
else {
--- a/Simple-MQTT/SimpleMQTT.h Thu Mar 08 13:59:35 2018 +0000
+++ b/Simple-MQTT/SimpleMQTT.h Thu Mar 08 14:19:48 2018 +0000
@@ -390,15 +390,15 @@
const char* pubTopic = MQTT_EVENT_TOPIC;
char buf[MQTT_MAX_PAYLOAD_SIZE];
- char timeBuf[50];
+// char timeBuf[50];
if (!client->isConnected()) {
printf ("---> MQTT DISCONNECTED\n\r"); return MQTT::FAILURE;
}
- strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
- sprintf(buf, "{\"type\":2,\"deviceId\":\"PROEVN\",\"time\":\"%s\",\"cmdId\":%d,\"temperature0\":%.2f,\"oxygen0\":%.2f}",
- timeBuf, commandID, TempVal ,DOVal);
+// strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
+ sprintf(buf, "{\"type\":2,\"deviceId\":\"PROEVN\",\"time\":\"%d\",\"cmdId\":%d,\"temperature0\":%.2f,\"oxygen0\":%.2f}",
+ inputTime, commandID, TempVal ,DOVal);
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
@@ -416,15 +416,15 @@
MQTT::Message message;
const char* pubTopic = MQTT_EVENT_TOPIC;
char buf[MQTT_MAX_PAYLOAD_SIZE];
- char timeBuf[50];
+// char timeBuf[50];
if (!client->isConnected()) {
printf ("---> MQTT DISCONNECTED\n\r");
return MQTT::FAILURE;
}
- strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
+// strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
sprintf(buf, "{\"type\":3,\"deviceId\":\"PROEVN\",\"time\":\"%s\",\"cmdId\":%d,\"relay1\":%d,\"relay2\":%d,\"relay3\":%d}",
- timeBuf, commandID, relay1, relay2, relay3);
+ inputTime, commandID, relay1, relay2, relay3);
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
@@ -443,15 +443,15 @@
MQTT::Message message;
const char* pubTopic = MQTT_EVENT_TOPIC;
char buf[MQTT_MAX_PAYLOAD_SIZE];
- char timeBuf[50];
+// char timeBuf[50];
if (!client->isConnected()) {
printf ("---> MQTT DISCONNECTED\n\r");
return MQTT::FAILURE;
}
- strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
+// strftime(timeBuf, 50, "%Y/%m/%d %H:%M:%S", localtime(&inputTime));
sprintf(buf, "{\"type\":4,\"deviceId\":\"PROEVN\",\"time\":\"%s\",\"cmdId\":%d,\"mode\":%d,\"OxygenThreshold\":%d,\"TemperatureThreshold\":%d,\"uploadInterval\":%d}",
- timeBuf, commandID, mode, OxyThreshold, TemperatureThreshold, UploadInterval);
+ inputTime, commandID, mode, OxyThreshold, TemperatureThreshold, UploadInterval);
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;