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

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

Revision:
0:0a2f634d3324
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MQTT/MQTTSocket.h	Thu Feb 09 07:26:57 2017 +0000
@@ -0,0 +1,65 @@
+#if !defined(MQTTSOCKET_H)
+#define MQTTSOCKET_H
+
+#include "MQTTmbed.h"
+#include "TCPSocket.h"
+
+class MQTTSocket
+{
+public:
+	int open(NetworkInterface* nif)
+	{
+		return socket.open(nif);
+	}
+	
+    int connect(char* hostname, int port, int timeout=1000)
+    {
+		socket.set_blocking (false);
+		socket.set_timeout(timeout);
+		_mutex.lock();
+        int ret = (int)socket.connect(hostname, port);
+		_mutex.unlock();
+		
+		return ret;
+    }
+
+    int read(unsigned char* buffer, int len, int timeout)
+    {
+		socket.set_blocking (false);
+		socket.set_timeout(timeout);
+		_mutex.lock();
+        int ret = (int)socket.recv((char*)buffer, len);
+		_mutex.unlock();
+		
+		return ret;
+    }
+    
+    int write(unsigned char* buffer, int len, int timeout)
+    {
+		socket.set_blocking (false);
+		socket.set_timeout(timeout); 
+		_mutex.lock();
+        int ret = (int)socket.send((char*)buffer, len);
+		_mutex.unlock();
+		
+		return ret;
+    }
+    
+    int disconnect()
+    {
+		_mutex.lock();
+    	int ret = (int)socket.close();
+		_mutex.unlock();
+		
+		return ret;
+    }
+    
+private:
+	Mutex _mutex;
+    TCPSocket socket;
+    
+};
+
+
+
+#endif