MQTT demo program for Nucleo F401RE and Seeedstudio W5200 Ethernet Shield which is based on Wiznet IBMIoTClientEthernetExample_W5500.
Dependencies: MQTT W5200Interface mbed DHT11
Fork of IBMIoTClientEthernetExample_W5500 by
I post description regarding this source code here.
http://developer.mbed.org/users/hillkim7/notebook/ibmiotclientethernetexample_w5200/
Revision 4:0c9bdee36e2a, committed 2014-12-26
- Comitter:
- hillkim7
- Date:
- Fri Dec 26 07:54:23 2014 +0000
- Parent:
- 3:64a7d39e423b
- Commit message:
- DHT11 module attached to update real temperature and humidity.
Changed in this revision
DHT11.lib | 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 |
diff -r 64a7d39e423b -r 0c9bdee36e2a DHT11.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT11.lib Fri Dec 26 07:54:23 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/s_inoue_mbed/code/DHT11/#e91c151d1798
diff -r 64a7d39e423b -r 0c9bdee36e2a main.cpp --- a/main.cpp Thu Dec 25 11:25:49 2014 +0000 +++ b/main.cpp Fri Dec 26 07:54:23 2014 +0000 @@ -32,6 +32,16 @@ #define QUICKSTARTMODE 1 +// It shows real temperature and humidity with DHT11. +#define DHT11_TEMPERATURE 0 + +#if DHT11_TEMPERATURE +#include "DHT11.h" + +DHT11 dht(D4); + +#endif + #if (QUICKSTARTMODE) // Configuration values needed to connect to IBM IoT Cloud #define ORG "quickstart" // For a registered connection, replace with your org @@ -156,9 +166,27 @@ char* pubTopic = "iot-2/evt/status/fmt/json"; char buf[250]; + double temp, humi; + +#if DHT11_TEMPERATURE + int s = dht.readData(); + if (s != DHT11::OK) { + printf("DHT11 Error: %d\r\n", s); + temp = humi = 0; + } + else { + printf("T:%d, H:%d\r\n", dht.readTemperature(), dht.readHumidity()); + temp = dht.readTemperature(); + humi = dht.readHumidity(); + } +#else + // simulate environment data + temp = (120+(rand()%100)) / 10.0; + humi = (200+(rand()%150)) / 10.0; +#endif sprintf(buf, - "{\"d\":{\"myName\":\"IoT mbed\",\"test_value\":%d}}", - 12+(rand()%10)); + "{\"d\":{\"myName\":\"IoT mbed\",\"temperature\":%.1f,\"humidity\":%.1f}}", + temp, humi); message.qos = MQTT::QOS0; message.retained = false; @@ -238,8 +266,8 @@ // or maybe just add the proper members to do this disconnect and call attemptConnect(...) } - if (++count == 100) - { // Publish a message every second + if (++count == 200) + { // Publish a message every two second if (publish(&client, &ipstack) != 0) { WARN("publish error\r\n");