Guilhem Saurel
/
AV_MQTT_example
Example for AV_MQTT
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "AV_MQTT.h" 00004 #include "EthernetInterface.h" 00005 00006 EthernetInterface eth; 00007 00008 DigitalIn jdown(p12), jleft(p13), jcenter(p14), jup(p15), jright(p16); 00009 DigitalOut l1(LED1), l2(LED2), l3(LED3), l4(LED4); 00010 00011 void callback(const char *key, const char *value) { 00012 int led = atoi(value); 00013 l4 = (led & 4) >> 2; 00014 l3 = (led & 2) >> 1; 00015 l2 = led & 1; 00016 } 00017 00018 int main() { 00019 printf("\r\n====================================================\r\n"); 00020 eth.init(); 00021 do printf("Connection...\r\n"); while (eth.connect() != 0); 00022 00023 AV_MQTT client("10.41.240.6", callback, "MBED_MQTT_EXAMPLE", "mbed_password", "id", 1883, false); 00024 00025 00026 while(true) { 00027 00028 if (jdown) client.pub("button", "1"); 00029 else if (jleft) client.pub("button", "2"); 00030 else if (jcenter) client.pub("button", "3"); 00031 else if (jup) client.pub("button", "4"); 00032 else if (jright) client.pub("button", "5"); 00033 00034 l1 = 0; 00035 wait(1); 00036 l1 = 1; 00037 wait(1); 00038 } 00039 }
Generated on Tue Aug 23 2022 02:36:20 by 1.7.2