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: ESP8266Interface MQTT mbed-rtos mbed
Fork of HelloMQTT by
Revision 18:76d0899bc3ce, committed 2015-06-09
- Comitter:
- mbedAustin
- Date:
- Tue Jun 09 17:57:43 2015 +0000
- Parent:
- 17:92a64d43ee61
- Commit message:
- double checked everything working. Pub/sub to same topic for self echoing.
Changed in this revision
ESP8266Interface.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 |
--- a/ESP8266Interface.lib Fri Jun 05 15:15:24 2015 +0000 +++ b/ESP8266Interface.lib Tue Jun 09 17:57:43 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#c180905b5b79 +http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#1f4dd0e91837
--- a/main.cpp Fri Jun 05 15:15:24 2015 +0000 +++ b/main.cpp Tue Jun 09 17:57:43 2015 +0000 @@ -30,19 +30,20 @@ int arrivedcount = 0; - -void messageArrived(MQTT::MessageData& md) +// callback for subscribe topic +void subscribeCallback(MQTT::MessageData& md) { MQTT::Message &message = md.message; - printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id); + printf("Message received: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id); printf("Payload %.*s\n", message.payloadlen, (char*)message.payload); ++arrivedcount; } +// main function that sets up the subscription and makes a couple publishes int main(int argc, char* argv[]) { printf("Starting\n"); - MQTTESP8266 ipstack(D1, D0, D10, "ssid", "password"); + MQTTESP8266 ipstack(D1, D0, D10, "demossid","passphrase"); // change to match your wifi access point float version = 0.47; char* topic = "mbed-sample"; @@ -50,7 +51,7 @@ MQTT::Client<MQTTESP8266, Countdown> client = MQTT::Client<MQTTESP8266, Countdown>(ipstack); - char* hostname = "192.168.1.20"; + char* hostname = "85.119.83.194"; // test.mosquitto.org int port = 1883; int rc = ipstack.connect(hostname, port); if (rc != 0) @@ -58,14 +59,14 @@ MQTTPacket_connectData data = MQTTPacket_connectData_initializer; data.MQTTVersion = 3; - data.clientID.cstring = "mbed-sample"; + data.clientID.cstring = "mbed-clientID"; 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("mbed-sample", MQTT::QOS1, messageArrived)) != 0) - printf("rc from MQTT subscribe is %d\n", rc); + if ((rc = client.subscribe(topic, MQTT::QOS1, subscribeCallback)) != 0) + printf("Recv'd from MQTT subscribe is %d\n", rc); MQTT::Message message;