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.
Dependencies: EthernetInterface Milkcocoa_EthernetIF mbed-rtos mbed
Fork of MilkcocoaSample_Eth by
main.cpp
00001 #include "mbed.h" 00002 #include "MQTTEthernet.h" 00003 #include "MQTTClient.h" 00004 #include "Milkcocoa.h" 00005 #include "MClient.h" 00006 00007 // The default setting is for the Simple IoT Board(mbed LPC1114FN28) 00008 // Please change to fit the platform 00009 Serial pc(USBTX, USBRX); 00010 DigitalOut myled(LED1); 00011 AnalogIn ain(p15); 00012 00013 /************************* Your Milkcocoa Setup *********************************/ 00014 #define MILKCOCOA_APP_ID "...YOUR_MILKCOCOA_APP_ID..." 00015 #define MILKCOCOA_DATASTORE "sensor" 00016 00017 /************* Milkcocoa Setup (you don't need to change this!) ******************/ 00018 00019 #define MILKCOCOA_SERVERPORT 1883 00020 00021 /************ Global State (you don't need to change this!) ******************/ 00022 00023 const char MQTT_SERVER[] = MILKCOCOA_APP_ID ".mlkcca.com"; 00024 const char MQTT_CLIENTID[] = __TIME__ MILKCOCOA_APP_ID; 00025 00026 extern void onpush(MQTT::MessageData& md); 00027 00028 int main() { 00029 // void setup() { 00030 pc.baud(9600); 00031 00032 MQTTEthernet *ipstack = new MQTTEthernet(); 00033 MClient *client = new MClient(ipstack); 00034 Milkcocoa *milkcocoa = new Milkcocoa(client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID); 00035 00036 pc.printf("Milkcocoa mbed ver demo\n\r\n\r\n\r"); 00037 00038 milkcocoa->connect(); 00039 pc.printf("\n\rEther connected\n\r"); 00040 00041 // } 00042 while(1) { 00043 // void loop() { 00044 milkcocoa->loop(); 00045 00046 DataElement elem = DataElement(); 00047 00048 float tmp = (ain - 0.1818)/0.00303; 00049 elem.setValue("tmp", tmp); 00050 00051 milkcocoa->push(MILKCOCOA_DATASTORE, elem); 00052 wait(7.0); 00053 } 00054 }
Generated on Wed Jul 13 2022 20:00:06 by
1.7.2
