Example for AV_MQTT

Dependencies:   AV_MQTT mbed

Committer:
Nim65s
Date:
Thu Aug 08 16:11:52 2013 +0000
Revision:
0:ab341e0e5a21
Child:
1:3bb5708ae2b9
First commit of the AV_MQTT usage example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nim65s 0:ab341e0e5a21 1 #include "mbed.h"
Nim65s 0:ab341e0e5a21 2 #include "rtos.h"
Nim65s 0:ab341e0e5a21 3 #include "AV_MQTT.h"
Nim65s 0:ab341e0e5a21 4 #include "EthernetInterface.h"
Nim65s 0:ab341e0e5a21 5
Nim65s 0:ab341e0e5a21 6 EthernetInterface eth;
Nim65s 0:ab341e0e5a21 7
Nim65s 0:ab341e0e5a21 8 DigitalOut led(LED1);
Nim65s 0:ab341e0e5a21 9
Nim65s 0:ab341e0e5a21 10 DigitalIn down(p12), left(p13), center(p14), up(p15), right(p16);
Nim65s 0:ab341e0e5a21 11
Nim65s 0:ab341e0e5a21 12 char BUFFER[150];
Nim65s 0:ab341e0e5a21 13
Nim65s 0:ab341e0e5a21 14 void callback(char *topic, char *message) {
Nim65s 0:ab341e0e5a21 15 printf("==== New PUBLISH received ====\r\n");
Nim65s 0:ab341e0e5a21 16 printf(topic);
Nim65s 0:ab341e0e5a21 17 printf("\r\n------------------------------\r\n");
Nim65s 0:ab341e0e5a21 18 printf(message);
Nim65s 0:ab341e0e5a21 19 printf("\r\n------------ end -------------\r\n");
Nim65s 0:ab341e0e5a21 20 }
Nim65s 0:ab341e0e5a21 21
Nim65s 0:ab341e0e5a21 22 int main() {
Nim65s 0:ab341e0e5a21 23 printf("\r\n====================================================\r\n");
Nim65s 0:ab341e0e5a21 24 eth.init();
Nim65s 0:ab341e0e5a21 25 do printf("Connection...\r\n"); while (eth.connect() != 0);
Nim65s 0:ab341e0e5a21 26
Nim65s 0:ab341e0e5a21 27 //niMQTT client("10.41.240.6", callback, "mbed", 1883, "MBED_MQTT_TEST", "mbed_password");
Nim65s 0:ab341e0e5a21 28 AV_MQTT client("10.41.240.6", callback, "MBED_MQTT_TEST", "mbed_password", "mbed", 1883, true);
Nim65s 0:ab341e0e5a21 29
Nim65s 0:ab341e0e5a21 30 while(true) {
Nim65s 0:ab341e0e5a21 31
Nim65s 0:ab341e0e5a21 32 if (down) client.pub("button", "1");
Nim65s 0:ab341e0e5a21 33 else if (left) client.pub("button", "2");
Nim65s 0:ab341e0e5a21 34 else if (center) client.pub("button", "3");
Nim65s 0:ab341e0e5a21 35 else if (up) client.pub("button", "4");
Nim65s 0:ab341e0e5a21 36 else if (right) client.pub("button", "5");
Nim65s 0:ab341e0e5a21 37
Nim65s 0:ab341e0e5a21 38 led = 0;
Nim65s 0:ab341e0e5a21 39 wait(1);
Nim65s 0:ab341e0e5a21 40 led = 1;
Nim65s 0:ab341e0e5a21 41 wait(1);
Nim65s 0:ab341e0e5a21 42 }
Nim65s 0:ab341e0e5a21 43 }
Nim65s 0:ab341e0e5a21 44
Nim65s 0:ab341e0e5a21 45