データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリを使ったサンプルです。 EthernetIF版 https://mlkcca.com/

Dependencies:   EthernetInterface Milkcocoa_EthernetIF mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
jksoft
Date:
Fri Dec 18 04:43:09 2015 +0000
Child:
1:a45427394577
Child:
3:fce801478ba1
Commit message:
??

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
Milkcocoa.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Dec 18 04:43:09 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Milkcocoa.lib	Fri Dec 18 04:43:09 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/jksoft/code/Milkcocoa_EthernetIF/#a174c8a8d53e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 18 04:43:09 2015 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "MQTTEthernet.h"
+#include "MQTTClient.h"
+#include "Milkcocoa.h"
+#include "MClient.h"
+
+// The default setting is for the Simple IoT Board(mbed LPC1114FN28)
+// Please change to fit the platform
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+
+/************************* Your Milkcocoa Setup *********************************/
+
+#define MILKCOCOA_APP_ID      "...YOUR_MILKCOCOA_APP_ID..."
+#define MILKCOCOA_DATASTORE   "esp8266"
+
+/************* 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() {
+// void setup() {
+    pc.baud(9600);
+
+    MQTTEthernet *ipstack = new MQTTEthernet();
+	MClient *client = new MClient(ipstack);
+	Milkcocoa *milkcocoa = new Milkcocoa(client, MQTT_SERVER, MILKCOCOA_SERVERPORT, MILKCOCOA_APP_ID, MQTT_CLIENTID);
+
+    pc.printf("Milkcocoa mbed ver demo\n\r\n\r\n\r");
+	
+	milkcocoa->connect();
+	pc.printf("\n\rEther connected\n\r");
+	
+	pc.printf("%d\n\r",milkcocoa->on(MILKCOCOA_DATASTORE, "push", onpush));
+	
+// }
+	while(1) {
+// void loop() {
+		milkcocoa->loop();
+		
+		DataElement elem = DataElement();
+		elem.setValue("v", 1);
+		
+		milkcocoa->push(MILKCOCOA_DATASTORE, elem);
+		wait(7.0);
+	}
+}
+
+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-rtos.lib	Fri Dec 18 04:43:09 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 18 04:43:09 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file