![](/media/cache/profiles/be6b2f6b6e7d72e528c6123f2cd5568e.jpg.50x50_q85.jpg)
Example for AV_MQTT
main.cpp@1:3bb5708ae2b9, 2013-08-08 (annotated)
- Committer:
- Nim65s
- Date:
- Thu Aug 08 16:14:26 2013 +0000
- Revision:
- 1:3bb5708ae2b9
- Parent:
- 0:ab341e0e5a21
- Child:
- 2:b9b08c7d6e12
removing useless lines and parameters
Who changed what in which revision?
User | Revision | Line number | New 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 | void callback(char *topic, char *message) { |
Nim65s | 0:ab341e0e5a21 | 13 | printf("==== New PUBLISH received ====\r\n"); |
Nim65s | 0:ab341e0e5a21 | 14 | printf(topic); |
Nim65s | 0:ab341e0e5a21 | 15 | printf("\r\n------------------------------\r\n"); |
Nim65s | 0:ab341e0e5a21 | 16 | printf(message); |
Nim65s | 0:ab341e0e5a21 | 17 | printf("\r\n------------ end -------------\r\n"); |
Nim65s | 0:ab341e0e5a21 | 18 | } |
Nim65s | 0:ab341e0e5a21 | 19 | |
Nim65s | 0:ab341e0e5a21 | 20 | int main() { |
Nim65s | 0:ab341e0e5a21 | 21 | printf("\r\n====================================================\r\n"); |
Nim65s | 0:ab341e0e5a21 | 22 | eth.init(); |
Nim65s | 0:ab341e0e5a21 | 23 | do printf("Connection...\r\n"); while (eth.connect() != 0); |
Nim65s | 0:ab341e0e5a21 | 24 | |
Nim65s | 1:3bb5708ae2b9 | 25 | AV_MQTT client("10.41.240.6", callback, "MBED_MQTT_TEST", "mbed_password"); |
Nim65s | 0:ab341e0e5a21 | 26 | |
Nim65s | 0:ab341e0e5a21 | 27 | while(true) { |
Nim65s | 0:ab341e0e5a21 | 28 | |
Nim65s | 0:ab341e0e5a21 | 29 | if (down) client.pub("button", "1"); |
Nim65s | 0:ab341e0e5a21 | 30 | else if (left) client.pub("button", "2"); |
Nim65s | 0:ab341e0e5a21 | 31 | else if (center) client.pub("button", "3"); |
Nim65s | 0:ab341e0e5a21 | 32 | else if (up) client.pub("button", "4"); |
Nim65s | 0:ab341e0e5a21 | 33 | else if (right) client.pub("button", "5"); |
Nim65s | 0:ab341e0e5a21 | 34 | |
Nim65s | 0:ab341e0e5a21 | 35 | led = 0; |
Nim65s | 0:ab341e0e5a21 | 36 | wait(1); |
Nim65s | 0:ab341e0e5a21 | 37 | led = 1; |
Nim65s | 0:ab341e0e5a21 | 38 | wait(1); |
Nim65s | 0:ab341e0e5a21 | 39 | } |
Nim65s | 1:3bb5708ae2b9 | 40 | } |