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.
Dependents: MilkcocoaSample_Eth_tmp MilkcocoaSample_Eth uhuru_hallowin2
Fork of Milkcocoa by
Diff: Milkcocoa.h
- Revision:
- 0:23e533c4b1ec
- Child:
- 1:4a634c06c5dc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Milkcocoa.h Tue Dec 15 09:56:32 2015 +0000
@@ -0,0 +1,54 @@
+#ifndef _MILKCOCOA_H_
+#define _MILKCOCOA_H_
+
+#include "mbed.h"
+#include "MQTTESP8266.h"
+#include "MQTTClient.h"
+
+#define RECV_TIMEOUT 500
+
+class DataElement {
+ public:
+ DataElement();
+ DataElement(char *json_string);
+ void setValue(const char *key, const char *v);
+ void setValue(const char *key, int v);
+ void setValue(const char *key, double v);
+ char *toCharArray();
+ char *getString(const char *key);
+ int getInt(const char *key);
+ float getFloat(const char *key);
+
+ private:
+ char json_msg[256];
+};
+
+typedef void (*GeneralFunction) (MQTT::MessageData& elem);
+
+class Milkcocoa {
+ public:
+
+ Milkcocoa(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id);
+ Milkcocoa(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session);
+ static Milkcocoa* createWithApiKey(MQTTESP8266 *ipstack, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret);
+ void connect();
+ void loop();
+ bool push(const char *path, DataElement dataelement);
+ bool send(const char *path, DataElement dataelement);
+ bool on(const char *path, const char *event, GeneralFunction cb);
+
+private:
+ char servername[64];
+ int16_t portnum;
+ char _clientid[64];
+ char username[32];
+ char password[32];
+ const char *app_id;
+
+ MQTTESP8266 *_ipstack;
+ MQTT::Client<MQTTESP8266, Countdown> client;
+ GeneralFunction _cb;
+};
+
+
+#endif
