Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface MQTT RHT03 mbed-rtos mbed
Revision 0:7c734e5f2c45, committed 2014-05-22
- Comitter:
- charliebsimms
- Date:
- Thu May 22 08:35:33 2014 +0000
- Commit message:
- The project aim is to develop a beehive environment monitoring system publishing data to a mqtt server.
Changed in this revision
diff -r 000000000000 -r 7c734e5f2c45 EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu May 22 08:35:33 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#097a9996f8d5
diff -r 000000000000 -r 7c734e5f2c45 MQTT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT.lib Thu May 22 08:35:33 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jwende/code/MQTT/#ca855d29545b
diff -r 000000000000 -r 7c734e5f2c45 RHT03.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RHT03.lib Thu May 22 08:35:33 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tristanjph/code/RHT03/#153e20f26d54
diff -r 000000000000 -r 7c734e5f2c45 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu May 22 08:35:33 2014 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "PubSubClient.h"
+#include "RHT03.h"
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <iomanip>
+
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+
+char* serverIpAddr = "192.168.1.2";
+int port = 1883;
+
+
+void callback(char* topic, char* payload, unsigned int len);
+PubSubClient mqtt(serverIpAddr, port, callback);
+EthernetInterface eth;
+
+void callback(char* topic, char* payload, unsigned int len)
+{
+ printf("Topic: %s\r\n", topic);
+ printf("Payload: %s\r\n\r\n", payload);
+
+ //Send incoming payloads back to topic.
+ //mqtt.publish("mbed/mybehive", payload, len);
+}
+
+int main() {
+
+ float temp,hum;
+ RHT03 humtemp(p24);
+ string var;
+
+ printf("\r\nMQTTClient Tester\r\n");
+ eth.init(); //Use DHCP
+ eth.connect();
+
+ printf("IP Address is %s\n\r", eth.getIPAddress());
+
+ char clientID[] = "charlie"; /*Client nanme show for MQTT server*/
+ char pub_topic[] = "mbed/mybehive"; /*Publish to topic : "/mbed" */
+
+
+ if(!mqtt.connect(clientID)){
+ pc.printf("\r\nConnect to server failed ..\r\n");
+ return -1;
+ }
+
+ printf("\r\nConnect to server sucessed ..\r\n");
+
+ while(1) {
+ mqtt.loop();
+ myled = 1;
+ wait(3);
+
+ pc.printf("Read temperature\n\r");
+ if(humtemp.readData() == RHT_ERROR_NONE)
+ {
+ //Gets the current temperature in centigrade
+ temp = humtemp.getTemperatureC();
+ //Gets the current humidity in percentage
+ hum = humtemp.getHumidity();
+
+ stringstream oss;
+ oss << "{" << "\"temperature\":" << std::setprecision(4) << temp << "," << "\"humidity\":" << std::setprecision(4) << hum << "}";
+
+ string data = oss.str();
+ pc.printf("temperature is %f\n\r", temp);
+ pc.printf("humidity is %f\n\r\n\r", hum);
+ pc.printf("environment is %s\n\r\n\r", data.c_str());
+ char * value = new char [37];
+ strcpy(value, data.c_str());
+ mqtt.publish(pub_topic, value);
+ }
+ myled = 0;
+ wait(3);
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r 7c734e5f2c45 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu May 22 08:35:33 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
diff -r 000000000000 -r 7c734e5f2c45 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 22 08:35:33 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877 \ No newline at end of file