MQTT test project.
Dependencies: EthernetInterface MQTT RHT03 mbed-rtos mbed
Revision 0:5939450e4bef, committed 2014-04-07
- Comitter:
- charliebsimms
- Date:
- Mon Apr 07 12:13:07 2014 +0000
- Commit message:
- To test mqtt using a temperature sensor and using wifi connection to send the information to a mqtt server.
Changed in this revision
diff -r 000000000000 -r 5939450e4bef EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#6a67d2bddc7c
diff -r 000000000000 -r 5939450e4bef MQTT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT.lib Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jwende/code/MQTT/#ca855d29545b
diff -r 000000000000 -r 5939450e4bef RHT03.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RHT03.lib Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tristanjph/code/RHT03/#153e20f26d54
diff -r 000000000000 -r 5939450e4bef main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "PubSubClient.h" + +Serial pc(USBTX, USBRX); + +char* serverIpAddr = "192.168.2.111"; /*Sever ip address*/ +int port = 1883; /*Sever Port*/ + +void callback(char* topic, char* payload, unsigned int len); /*Callback function prototype*/ +PubSubClient mqtt(serverIpAddr, port, callback); +EthernetInterface eth; + +void callback(char* topic, char* payload, unsigned int len) +{ + //Send incoming payloads back to topic "/mbed". + mqtt.publish("mbed", payload, len); +} + +int main() { + + eth.init(); //Use DHCP + eth.connect(); + pc.printf("IP Address is %s\n", eth.getIPAddress()); + + pc.printf("MQTTClient Tester"); + + + char clientID[] = "mbed"; /*Client nanme show for MQTT server*/ + char pub_topic[] = "mbed"; /*Publish to topic : "/mbed" */ + char sub_topic[] = "mirror"; /*Subscribe to topic : "/mirror" */ + + if(!mqtt.connect(clientID)){ + pc.printf("\r\nConnect to server failed ..\r\n"); + return -1; + } + + pc.printf("\r\nConnect to server sucessed ..\r\n"); + + mqtt.publish(pub_topic, "Hello here is mbed..."); + mqtt.subscribe(sub_topic); + + + pc.printf("#### End of the test.. ####"); + + //eth.disconnect(); + + while(1) { + mqtt.loop(); + } +} \ No newline at end of file
diff -r 000000000000 -r 5939450e4bef mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#cb1d43beeb70
diff -r 000000000000 -r 5939450e4bef mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 07 12:13:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7d30d6019079 \ No newline at end of file