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.
Revision 0:885b53a42035, committed 2017-02-09
- Comitter:
- jksoft
- Date:
- Thu Feb 09 07:31:26 2017 +0000
- Child:
- 1:1ab9d9f92764
- Commit message:
- ??
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Milkcocoa-os.lib Thu Feb 09 07:31:26 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jksoft/code/Milkcocoa-os/#0a2f634d3324
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Feb 09 07:31:26 2017 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "MQTTInterface.h"
+#include "MQTTClient.h"
+#include "Milkcocoa.h"
+#include "MClient.h"
+#include "EthernetInterface.h"
+
+EthernetInterface eth;
+RawSerial pc(USBTX,USBRX);
+
+/************************* Your Milkcocoa Setup *********************************/
+
+#define MILKCOCOA_APP_ID "postite082h1"
+#define MILKCOCOA_DATASTORE "mbed_lan"
+
+/************* Milkcocoa Setup (you don't need to change this!) ******************/
+
+#define MILKCOCOA_SERVERPORT 1883
+
+/************ Global State (you don't need to change this!) ******************/
+const char MQTT_SERVER[] = MILKCOCOA_APP_ID ".mlkcca.com";
+const char MQTT_CLIENTID[] = __TIME__ MILKCOCOA_APP_ID;
+
+extern void onpush(MQTT::MessageData& md);
+
+int main() {
+
+ pc.baud(9600);
+ pc.printf("Milkcocoa mbed os ver demo\n\r\n\r\n\r");
+
+ int ret = eth.connect();
+ if (ret != 0) {
+ printf("\r\nConnection error\r\n");
+ return -1;
+ }
+ pc.printf("\n\rEthernet connected\n\r");
+
+ Milkcocoa* milkcocoa = new Milkcocoa(ð, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
+
+ milkcocoa->connect();
+
+ pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush));
+
+ milkcocoa->setLoopCycle(5000);
+ milkcocoa->start();
+
+ while(1) {
+ DataElement elem = DataElement();
+ elem.setValue("v", 1);
+
+ milkcocoa->push(MILKCOCOA_DATASTORE, elem);
+
+ Thread::wait(7000);
+
+ }
+}
+
+void onpush(MQTT::MessageData& md)
+{
+ MQTT::Message &message = md.message;
+ DataElement de = DataElement((char*)message.payload);
+ pc.printf("onpush\n\r");
+ pc.printf("%d\n\r",de.getInt("v"));
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Feb 09 07:31:26 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#34c1facf42a174f47fdf9002cd8c6bf10ac41744