模組化,中斷服務

Dependencies:   EthernetInterface MQTT RHT03 mbed-rtos mbed

Fork of MyTempuratureMqtt by Charlie Simms

Files at this revision

API Documentation at this revision

Comitter:
bruceyang
Date:
Thu May 21 07:40:43 2015 +0000
Parent:
0:5939450e4bef
Commit message:
Finish V0.0.1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5939450e4bef -r 8b5f77770753 main.cpp
--- a/main.cpp	Mon Apr 07 12:13:07 2014 +0000
+++ b/main.cpp	Thu May 21 07:40:43 2015 +0000
@@ -3,9 +3,11 @@
 #include "PubSubClient.h"
 
 Serial pc(USBTX, USBRX);
+DigitalOut led(LED1);
+DigitalIn button(p21);
 
-char* serverIpAddr = "192.168.2.111";  /*Sever ip address*/
-int port = 1883; /*Sever Port*/
+char* serverIpAddr = "128.199.127.110";  /*Sever ip address*/
+int port = 443; /*Sever Port*/
 
 void callback(char* topic, char* payload, unsigned int len); /*Callback function prototype*/
 PubSubClient mqtt(serverIpAddr, port, callback);
@@ -47,5 +49,16 @@
     
     while(1) {
     mqtt.loop();
+     if (button) {
+            mqtt.publish(pub_topic, "ON!!");
+            mqtt.publish("control", "ffffff");
+            
+            led = 1;
+        } else {
+            mqtt.publish(pub_topic, "OFF");
+            mqtt.publish("control", "000000");
+            led = 0;
+        }
+        wait(0.4); // simple debouncing
     }
 }
\ No newline at end of file