use Dussolved_oxygen_sensor_on_wifi
Dependencies: watersenor_and_temp_code MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed
Fork of DS1820_IDW01M1 by
Diff: main.cpp
- Revision:
- 6:54965cdc7955
- Parent:
- 5:42113ea1b319
--- a/main.cpp Mon Nov 06 15:04:43 2017 +0000 +++ b/main.cpp Wed Nov 08 05:49:24 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 "5" #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; @@ -78,7 +78,7 @@ LOG("Nucleo IP ADDRESS: %s\n\r", WiFi.get_ip_address()); LOG("Nucleo MAC ADDRESS: %s\n\r", WiFi.get_mac_address()); LOG("Server Hostname: %s port: %d\n\r", hostname, MQTT_PORT); - LOG("Topic1: %s\n\r", TOPIC); + LOG("Topic: %s\n\r", TOPIC); //need subscrie LOG("=====================================\n\r"); netConnecting = true; @@ -147,7 +147,6 @@ MQTT::Message message; char *pubTopic = TOPIC; char buf[MQTT_MAX_PAYLOAD_SIZE]; - printf("Dissolved oxygen = %d\n", data); sprintf(buf,"%d",data); message.qos = MQTT::QOS0; message.retained = false; @@ -155,7 +154,6 @@ message.payload = (void*)buf; message.payloadlen = strlen(buf); - printf("Publishing %s\n\r", buf); return client->publish(pubTopic, message); } @@ -180,15 +178,51 @@ serial.printf("ASCIIChangeInteger databuffer1 : %d \n", databuffer1); 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 TxRxdata6) { 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(TxRxdata1 == 13) + { + if(TxRxdata3 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata2); + return databuffer; + } + else if(TxRxdata4 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata2)*10 + ASCIIChangeInteger(TxRxdata3); + return databuffer; + } + else + { + serial.printf("13 in TxRxdata1 : data Fail\n"); + return 0; + } + } + else if(TxRxdata3 == 13) + { + if(TxRxdata6 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata4)*10 + ASCIIChangeInteger(TxRxdata5); + return databuffer; + } + else if(TxRxdata5 == 0x2E) + { + databuffer = ASCIIChangeInteger(TxRxdata2); + return databuffer; + } + else + { + serial.printf("13 in TxRxdata3 : data Fail\n"); + return 0; + } + } + else + { + serial.printf("all data fail\n"); + } } int main() { @@ -223,7 +257,9 @@ 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)); + databuffer3 = Conversionfunction(BME280.datareadfuiction(0),BME280.datareadfuiction(1),BME280.datareadfuiction(2),BME280.datareadfuiction(3),BME280.datareadfuiction(4),BME280.datareadfuiction(5)); + serial.printf("databuffer3 : %d\n",databuffer3); if (++count == 3) { // Publish a message every second if (publish(&client, &ipstack,databuffer3) != 0)