Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
main.cpp
00001 #include "mbed.h" 00002 #include "MQTTInterface.h" 00003 #include "MQTTClient.h" 00004 #include "Milkcocoa.h" 00005 #include "MClient.h" 00006 #include "EthernetInterface.h" 00007 00008 EthernetInterface eth; 00009 Serial pc(USBTX,USBRX); 00010 00011 /************************* Your Milkcocoa Setup *********************************/ 00012 00013 #define MILKCOCOA_APP_ID "teaidsirehz" 00014 #define MILKCOCOA_DATASTORE "mbed_lan" 00015 00016 /************* Milkcocoa Setup (you don't need to change this!) ******************/ 00017 00018 #define MILKCOCOA_SERVERPORT 1883 00019 00020 /************ Global State (you don't need to change this!) ******************/ 00021 const char MQTT_SERVER[] = MILKCOCOA_APP_ID ".mlkcca.com"; 00022 const char MQTT_CLIENTID[] = __TIME__ MILKCOCOA_APP_ID; 00023 00024 extern void onpush(MQTT::MessageData& md); 00025 00026 int main() { 00027 00028 pc.baud(9600); 00029 pc.printf("Milkcocoa mbed os ver demo\n\r\n\r\n\r"); 00030 00031 int ret = eth.connect(); 00032 if (ret != 0) { 00033 printf("\r\nConnection error\r\n"); 00034 return -1; 00035 } 00036 pc.printf("\n\rEthernet connected\n\r"); 00037 00038 MQTTInterface* ipstack = new MQTTInterface(ð); 00039 MClient* client = new MClient(ipstack); 00040 Milkcocoa* milkcocoa = new Milkcocoa(client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID); 00041 00042 milkcocoa->connect(); 00043 00044 pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush)); 00045 00046 milkcocoa->start(); 00047 00048 while(1) { 00049 00050 DataElement elem = DataElement(); 00051 elem.setValue("v", 1); 00052 00053 milkcocoa->push(MILKCOCOA_DATASTORE, elem); 00054 pc.printf("PUSH\n\r"); 00055 Thread::wait(500); 00056 00057 } 00058 } 00059 00060 void onpush(MQTT::MessageData& md) 00061 { 00062 MQTT::Message &message = md.message; 00063 DataElement de = DataElement((char*)message.payload); 00064 pc.printf("onpush\n\r"); 00065 pc.printf("%d\n\r",de.getInt("v")); 00066 }
Generated on Wed Jul 13 2022 21:16:17 by
