Guilhem Saurel / Mbed 2 deprecated niMQTT_example

Dependencies:   niMQTT mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "niMQTT.h"
00004 #include "EthernetInterface.h"
00005 
00006 EthernetInterface eth;
00007 
00008 DigitalOut led(LED1);
00009 DigitalIn pub(p14);
00010 
00011 void callback(const char *topic, const char *message) {
00012     printf("==== New PUBLISH received ====\r\n");
00013     printf(topic);
00014     printf("\r\n------------------------------\r\n");
00015     printf(message);
00016     printf("\r\n------------ end -------------\r\n");
00017 }
00018 
00019 int main() {
00020     printf("\r\n====================================================\r\n");
00021     eth.init();
00022     do printf("Connection...\r\n"); while (eth.connect() != 0);
00023     
00024     niMQTT client("10.41.51.53", callback);
00025     
00026     client.pub("mbed", "Hello World");
00027         
00028     client.sub("mbed", false);
00029     
00030     while(true) {
00031         if (pub) client.pub("mbed", "test");
00032         led = 0;
00033         wait(1);
00034         led = 1;
00035         wait(1);
00036     }
00037 }