Example MQTT implemented on the ESP8266
Dependencies: ESP8266Interface MQTT mbed-rtos mbed
Fork of HelloMQTT by
This is an example of how to run MQTT using the esp8266 as the network connection. This program will default to trying to talk to a public MQTT server (test.mosquitto.org). The example will subscribe to a topic and then publish to that topic. In this way it will effectively echo back to itself. You can alternatively use a private mqtt broker,[[TODO: |instructions here]]
Please note that the ESP8266 interface cannot translate hostnames to IP Addresses, it can only accept raw IP Addresses as input.
Diff: main.cpp
- Revision:
- 3:7a6a899de7cc
- Parent:
- 2:638c854c0695
- Child:
- 5:4a257f6ac09a
- Child:
- 6:e4c690c45021
diff -r 638c854c0695 -r 7a6a899de7cc main.cpp --- a/main.cpp Wed Apr 30 13:16:09 2014 +0000 +++ b/main.cpp Tue May 06 09:45:22 2014 +0000 @@ -153,13 +153,13 @@ lcd.printf("Version is %f\n", version); - MQTT::Client<IPStack, Countdown>client = MQTT::Client<IPStack, Countdown>(&ipstack); + MQTT::Client<IPStack, Countdown> client = MQTT::Client<IPStack, Countdown>(ipstack); + + client.setConnectionLostHandler(connect); MQTT::Client<IPStack, Countdown>::connectionLostInfo info = {&client, &ipstack}; int rc = connect(&info); - client.setConnectionLostHandler(connect); - rc = client.subscribe(topic, MQTT::QOS1, messageArrived); if (rc != 0) lcd.printf("rc from MQTT subscribe is %d\n", rc);