turbid_sensor
Dependencies: watersenor_and_temp_code MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of Dissolved_oxygen_sensor_online by
Revision 7:8eaef8890eee, committed 2017-11-08
- Comitter:
- e58136782000
- Date:
- Wed Nov 08 06:22:19 2017 +0000
- Parent:
- 5:42113ea1b319
- Commit message:
- turbid sensor online;
Changed in this revision
BME280/BME280.hpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BME280/BME280.hpp Mon Nov 06 15:04:43 2017 +0000 +++ b/BME280/BME280.hpp Wed Nov 08 06:22:19 2017 +0000 @@ -2,7 +2,7 @@ #ifndef BME280_HPP #define BME280_HPP -#define BME280_size 5 +#define BME280_size 6 Serial sensor(PA_11,PA_12);// Tx,Rx Serial pc(USBTX,USBRX); @@ -59,7 +59,7 @@ pc.printf("start receive \n"); for(int i=0;i<BME280_size;i++) { - sensor.gets(buf,8); + sensor.gets(buf,9); } }
--- a/main.cpp Mon Nov 06 15:04:43 2017 +0000 +++ b/main.cpp Wed Nov 08 06:22:19 2017 +0000 @@ -10,16 +10,16 @@ #define MQTT_MAX_PACKET_SIZE 250 #define MQTT_MAX_PAYLOAD_SIZE 300 //Configuration value needed to connect Red-node -#define BROKER_URL "192.168.1.110"; +#define BROKER_URL "192.168.20.116"; #define MQTT_PORT 1883 //MQTT use Topic -#define TOPIC "1" +#define TOPIC "6" #define SUB_TOPIC "LED" //Wifi network -#define SSID "18-2F" -#define PASSW "062432779" +#define SSID "tnta" +#define PASSW "tnta2355818" Serial serial(USBTX, USBRX); DigitalOut myled(LED1); //BME280 bmpSensor; @@ -181,14 +181,38 @@ return databuffer1; } -int Conversionfunction(int Tensdigit, int Digits, int TheFirstDecimalPlace, int TheSecondDecimalPlace) +int Conversionfunction(int TxRxdata1, int TxRxdata2, int TxRxdata3, int TxRxdata4, int TxRxdata5) { int databuffer; - serial.printf("dataTensdigit: %d\n",Tensdigit); - serial.printf("Digits: %d\n",Digits); - databuffer = ASCIIChangeInteger(Tensdigit)*10 + ASCIIChangeInteger(Digits); - serial.printf("datanumber: %d\n",databuffer); - return databuffer; + serial.printf("dataTensdigit: %d\n",TxRxdata1); + serial.printf("Digits: %d\n",TxRxdata2); + if(TxRxdata2 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata1); + return databuffer; + } + else + { + if(TxRxdata3 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata1)*10 + ASCIIChangeInteger(TxRxdata2); + return databuffer; + } + else + { + if(TxRxdata5 == 13) + { + databuffer = ASCIIChangeInteger(TxRxdata1)*1000 + ASCIIChangeInteger(TxRxdata2)*100 + ASCIIChangeInteger(TxRxdata3)*10 + ASCIIChangeInteger(TxRxdata4); + return databuffer; + } + else + { + databuffer = ASCIIChangeInteger(TxRxdata1)*100 + ASCIIChangeInteger(TxRxdata2)*10 + ASCIIChangeInteger(TxRxdata3); + serial.printf("datanumber1: %d\n",databuffer); + return databuffer; + } + } + } } int main() { @@ -223,7 +247,17 @@ serial.printf("data 3 : %d\n",BME280.datareadfuiction(2)); serial.printf("data 4 : %d\n",BME280.datareadfuiction(3)); serial.printf("data 5 : %d\n",BME280.datareadfuiction(4)); - databuffer3 = Conversionfunction(BME280.datareadfuiction(3),BME280.datareadfuiction(4),BME280.datareadfuiction(0),BME280.datareadfuiction(1)); + serial.printf("data 6 : %d\n",BME280.datareadfuiction(5)); + + wait(10); + if(BME280.datareadfuiction(0) == 13) + { + databuffer3 = Conversionfunction(BME280.datareadfuiction(1),BME280.datareadfuiction(2),BME280.datareadfuiction(3),BME280.datareadfuiction(4),BME280.datareadfuiction(0)); + } + else + { + databuffer3 = Conversionfunction(BME280.datareadfuiction(3),BME280.datareadfuiction(4),BME280.datareadfuiction(5),BME280.datareadfuiction(0),BME280.datareadfuiction(1)); + } if (++count == 3) { // Publish a message every second if (publish(&client, &ipstack,databuffer3) != 0)