【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/

Dependents:   mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn

Revision:
1:8e4149b53a8a
Parent:
0:0a2f634d3324
Child:
2:63228ec79756
Child:
3:cddf81a87de3
--- a/Milkcocoa.cpp	Thu Feb 09 07:26:57 2017 +0000
+++ b/Milkcocoa.cpp	Wed Feb 15 02:15:55 2017 +0000
@@ -98,7 +98,8 @@
 	strcpy(password,app_id);
 	setLoopCycle(5000);
 	
-	cycleThread.start(Milkcocoa::threadStarter,this);
+	cycleThread1.start(Milkcocoa::threadStarter1,this);
+	cycleThread2.start(Milkcocoa::threadStarter2,this);
 }
 
 Milkcocoa::Milkcocoa(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session){
@@ -112,7 +113,8 @@
 	strcpy(password,app_id);
 	setLoopCycle(5000);
 	
-	cycleThread.start(Milkcocoa::threadStarter,this);
+	cycleThread1.start(Milkcocoa::threadStarter1,this);
+	cycleThread2.start(Milkcocoa::threadStarter2,this);
 }
 
 Milkcocoa* Milkcocoa::createWithApiKey(NetworkInterface* nif, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret) {
@@ -212,16 +214,30 @@
 }
 
 void Milkcocoa::start() {
-	cycleThread.signal_set(START_THREAD);
+	cycleThread1.signal_set(START_THREAD);
+	cycleThread2.signal_set(START_THREAD);
 }
 
-void Milkcocoa::cycle_Thread(void) {
-	cycleThread.signal_wait(START_THREAD);
+void Milkcocoa::cycle_Thread1(void) {
+	cycleThread1.signal_wait(START_THREAD);
 	while(1) {
     	Timer timer;
 		timer.start();
 		connect();
+				
+		client->yield(RECV_TIMEOUT);
 		
+		int sub_time = loop_cycle - timer.read();
+		if( sub_time > 0 ){
+			 Thread::wait(sub_time);
+		}
+		timer.stop();
+	}
+}
+void Milkcocoa::cycle_Thread2(void) {
+	cycleThread2.signal_wait(START_THREAD);
+	while(1) {
+
         osEvent evt = message_box.get();
         if (evt.status == osEventMail) {
         	milkcocoa_message_t *message = (milkcocoa_message_t*)evt.value.p;
@@ -238,19 +254,18 @@
 			client->publish(message->topic, mq_message);
 			
 			message_box.free(message);
-        }
-		
-		client->yield(RECV_TIMEOUT);
-		
-		timer.stop();
-		
-		if( timer.read() < loop_cycle ) Thread::wait(loop_cycle - timer.read());
+		}
+		Thread::wait(1000);
 	}
 }
 
-void Milkcocoa::threadStarter(void const *p) {
+void Milkcocoa::threadStarter1(void const *p) {
   Milkcocoa *instance = (Milkcocoa*)p;
-  instance->cycle_Thread();
+  instance->cycle_Thread1();
+}
+void Milkcocoa::threadStarter2(void const *p) {
+  Milkcocoa *instance = (Milkcocoa*)p;
+  instance->cycle_Thread2();
 }
 
 MilkcocoaSubscriber::MilkcocoaSubscriber(GeneralFunction _cb) {