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: libmDot mbed-rtos mbed
Fork of CardRead_20170216 by
Diff: main.cpp
- Revision:
- 9:cf45820af9b9
- Parent:
- 8:dfcee7a96019
- Child:
- 10:79124c0a5952
--- a/main.cpp Fri Aug 12 03:33:55 2016 +0000
+++ b/main.cpp Sat Aug 13 09:34:57 2016 +0000
@@ -4,35 +4,44 @@
#include <string>
#include <vector>
#include <algorithm>
-//#include "DHT.h"
-#include "LinearTemp.h"
+#include "AnalogPH.h"
+
+//defined for mDot SVB debug, comment it if applying for whole system
+#define NO_MULTITECH_GATEWAY
+
+//Define the number of channels
+#define NUM_OF_CH 4
-//DHT sensor(PB_1, DHT11);
-LinearTemp myPHSensor(PB_0, 0.005, -273.15);
+AnalogPHSensor CH0_PH(PB_0, 0.0, 0.0);
+
+#if (NUM_OF_CH >1)
+ AnalogPHSensor CH1_PH(PB_1, 0.0, 0.0);
+#endif
+
+#if (NUM_OF_CH >2)
+ AnalogPHSensor CH2_PH(PA_4, 0.0, 0.0);
+#endif
+#if (NUM_OF_CH >3)
+ AnalogPHSensor CH3_PH(PA_5, 0.0, 0.0);
+#endif
// these options must match the settings on your Conduit
// uncomment the following lines and edit their values to match your configuration
static std::string config_network_name = "chinaiot";
static std::string config_network_pass = "password";
-static uint8_t config_frequency_sub_band = 2;
int main() {
- int32_t ret;
+
mDot* dot;
std::vector<uint8_t> data;
- std::vector<uint8_t> send_data;
- float PhValue;
- std::string data_str = "T&H Sensors";
+ float phValue;
+ char _header[] = "PH Sensors";
char dataBuf[11];
-// int error = 0;
-// float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;
-// float h = 0.0f, c = 0.0f;
-
-
+ int i, k;
+
// get a mDot handle
dot = mDot::getInstance();
-
// print library version information
logInfo("version: %s", dot->getId().c_str());
@@ -43,7 +52,7 @@
dot->resetConfig();
dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
-
+#ifndef NO_MULTITECH_GATEWAY
// set up the mDot with our network information: frequency sub band, network name, and network password
// these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig()
@@ -97,32 +106,62 @@
}
// format data for sending to the gateway
- for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++)
- data.push_back((uint8_t) *it);
-
+ for( int i=0; i< strlen(_header); i++ )
+ data.push_back( _header[i] );
+
+ // send the data to the gateway
+ if ((ret = dot->send(data)) != mDot::MDOT_OK) {
+ logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
+ } else {
+ logInfo("successfully sent data to gateway");
+ }
+#else
+ logInfo("%s", _header);
+#endif
while (true) {
- // send the data to the gateway
- if ((ret = dot->send(data)) != mDot::MDOT_OK) {
- logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
- } else {
+
+ // Read the PH values
+ for(k=0; k<NUM_OF_CH; k++){
+ switch(k){
+ case 0: phValue = CH0_PH; break;
+ #if (NUM_OF_CH >1)
+ case 1: phValue = CH1_PH; break;
+ #endif
+ #if (NUM_OF_CH >2)
+ case 2: phValue = CH2_PH; break;
+ #endif
+ #if (NUM_OF_CH >3)
+ case 3: phValue = CH3_PH; break;
+ #endif
+ default:
+ break;
+ }
+ //for(i=0; i<1;i++) printf("3:[CH%d]", k);
+ sprintf(dataBuf, "CH%d:%5.4f", k, phValue);
+ //for(i=0; i<1;i++) printf("4:[%s]", dataBuf);
+ logInfo("%s", dataBuf);
+
+ #ifndef NO_MULTITECH_GATEWAY
+ //Send the data to Gateway
+ data.clear();
+ // probably not the most efficent way to do this
+ for( int i=0; i< strlen(dataBuf); i++ )
+ data.push_back( dataBuf[i] );
+
+ // send the data to the gateway
+ if ((ret = dot->send(data)) != mDot::MDOT_OK) {
+ logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());
+ } else {
logInfo("successfully sent data to gateway");
- }
-
+ }
+ #endif
+ } //for
// in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
+ #ifndef NO_MULTITECH_GATEWAY
osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs()));
-
- data.clear();
-
- // Read the PH value
- PhValue = myPHSensor;
-
- sprintf(dataBuf, "CH0:%5.4f", PhValue);
- logInfo("%s", dataBuf);
-
- // probably not the most efficent way to do this
- for( int i=0; i< strlen(dataBuf); i++ )
- data.push_back( dataBuf[i] );
-
+ #else
+ osDelay(1000);
+ #endif
}
}
