watersensor and temp

Dependencies:   MQTT NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed watersenor_and_temp_code

Fork of IDW01M1-MQTT by CHANG rozen

Revision:
4:426511536682
Parent:
3:30d9b8d9adc9
diff -r 30d9b8d9adc9 -r 426511536682 main.cpp
--- a/main.cpp	Fri Nov 03 01:57:41 2017 +0000
+++ b/main.cpp	Fri Nov 03 07:19:06 2017 +0000
@@ -23,6 +23,8 @@
 #define PASSW "tnta2355818"
 
 DigitalOut myled(LED1);
+DigitalIn  sensor_in(D4);
+
 BME280 bmpSensor;
 int connack_rc = 0;    // MQTT connack return code
 const char * ip_addr = "";
@@ -150,9 +152,8 @@
 }
 int publish (MQTT::Client<MQTTWiFi, Countdown, MQTT_MAX_PACKET_SIZE>* client,MQTTWiFi* ipstack,int data){
 	
-    
 	MQTT::Message message;
-	char *pubTopic = TOPIC1;
+	char *pubTopic = TOPIC2;
 	char buf[MQTT_MAX_PAYLOAD_SIZE];
 	printf("Temp = %d\n", data);
 	sprintf(buf,"%d",data);
@@ -188,7 +189,7 @@
 
 	MQTT::Client<MQTTWiFi, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
 	attemptConnect(&client, &ipstack);
-	ds1820.begin();	   
+	//ds1820.begin();	   
    int count = 0;    
 //    tyeld.start();    
     while (true)
@@ -210,8 +211,23 @@
 		//	serial.printf("No DS1820 sensor found!\r\n");
 		//	databuffer = 0;
     	//} 
-
-    	if (++count == 3)
+    	if(sensor_in == 0)
+        {
+            serial.printf("LED:ON\n");     
+            client.yield(10);
+            databuffer = 1; 
+        }
+        else
+        {
+        // LEDs are OFF
+        	
+			serial.printf("LED:OFF\n");
+	        client.yield(10);
+	        databuffer = 0;
+        }
+ 
+		
+    	if (++count == 100)
     	{               // Publish a message every second
     		if (publish(&client, &ipstack,databuffer) != 0) 
     		{