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: DHT MQTTforLecture WIZnetInterface mbed-src
Fork of w7500-paho-mqtt by
Revision 13:36456500fb7e, committed 2015-09-20
- Comitter:
- bangbh
- Date:
- Sun Sep 20 05:17:13 2015 +0000
- Parent:
- 12:794fa5058dc6
- Child:
- 14:2b30a541da82
- Commit message:
- This is for Wiznet Academy lecture.
Changed in this revision
--- a/MQTT.lib Mon Jun 29 02:10:24 2015 +0000 +++ b/MQTT.lib Sun Sep 20 05:17:13 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/bangbh/code/MQTT/#88f62eb29442 +https://developer.mbed.org/users/bangbh/code/MQTTforLecture/#85fefcf0b231
--- a/WIZnetInterface.lib Mon Jun 29 02:10:24 2015 +0000 +++ b/WIZnetInterface.lib Sun Sep 20 05:17:13 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#c830d2e7e0f5 +https://developer.mbed.org/users/bangbh/code/WIZnetInterface/#77b21be5d255
--- a/main.cpp Mon Jun 29 02:10:24 2015 +0000
+++ b/main.cpp Sun Sep 20 05:17:13 2015 +0000
@@ -33,7 +33,7 @@
MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
- char* hostname = "104.199.146.45";
+ char* hostname = "222.98.173.244";
int port = 1883;
int rc = ipstack.connect(hostname, port);
@@ -44,43 +44,56 @@
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
data.MQTTVersion = 3;
- data.clientID.cstring = "WIZwiki-W7500";
+ data.clientID.cstring = "WIZwiki-W7500a";
data.username.cstring = "testuser";
data.password.cstring = "testpassword";
if ((rc = client.connect(data)) != 0)
printf("rc from MQTT connect is %d\n", rc);
-
- if ((rc = client.subscribe(topic, MQTT::QOS1, messageArrived)) != 0)
- printf("rc from MQTT subscribe is %d\n", rc);
MQTT::Message message;
char buf[100];
int error = 0;
float hum = 0.0f, temp = 0.0f;
- while (true)
+ char i = 0;
+ while (true)
{
+ if(i > 100) i = 0;
error = sensor.readData();
if (0 == error) {
hum = sensor.ReadHumidity();
temp = sensor.ReadTemperature(CELCIUS);
}
- sprintf(buf, "%3.1f", hum);
message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
+
+ sprintf(buf, "%3.1f", hum);
message.payload = (void*)buf;
- message.payloadlen = strlen(buf)+1;
- rc = client.publish("wiznet/hum", message);
+ message.payloadlen = strlen(buf);
+ rc = client.publish("Wiznet/humidity", message);
+
sprintf(buf, "%3.1f", temp);
message.payload = (void*)buf;
- message.payloadlen = strlen(buf)+1;
- rc = client.publish("wiznet/temp", message);
- sprintf(buf, "%3.1f", ain.read()*100.0f);
+ message.payloadlen = strlen(buf);
+ rc = client.publish("Wiznet/temperature", message);
+
+ sprintf(buf, "%3.1f", (rand()%1000)/10.0);
+ message.payload = (void*)buf;
+ message.payloadlen = strlen(buf);
+ rc = client.publish("Wiznet/fluidgauge/A", message);
+
+ sprintf(buf, "%3.1f", (rand()%1000)/10.0);
message.payload = (void*)buf;
- message.payloadlen = strlen(buf)+1;
- rc = client.publish("wiznet/cds", message);
+ message.payloadlen = strlen(buf);
+ rc = client.publish("Wiznet/fluidgauge/B", message);
+
+ sprintf(buf, "%3.1f", (rand()%1000)/10.0);
+ message.payload = (void*)buf;
+ message.payloadlen = strlen(buf);
+ rc = client.publish("Wiznet/fluidgauge/C", message);
client.yield(1000);
+ //wait(100);
}
}
