Ethernet

Dependencies:   MQTT

Dependents:   MilkcocoaSample_Eth_K64F

Fork of Milkcocoa_EthernetIF by Junichi Katsu

Committer:
jksoft
Date:
Fri Dec 18 04:30:59 2015 +0000
Revision:
1:4a634c06c5dc
Parent:
0:23e533c4b1ec
???EthernetIF???????????????????subscribe????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:23e533c4b1ec 1 #ifndef _MILKCOCOA_H_
jksoft 0:23e533c4b1ec 2 #define _MILKCOCOA_H_
jksoft 0:23e533c4b1ec 3
jksoft 0:23e533c4b1ec 4 #include "mbed.h"
jksoft 1:4a634c06c5dc 5 #include "MQTTmbed.h"
jksoft 0:23e533c4b1ec 6 #include "MQTTClient.h"
jksoft 1:4a634c06c5dc 7 #include "MClient.h"
jksoft 0:23e533c4b1ec 8
jksoft 0:23e533c4b1ec 9 #define RECV_TIMEOUT 500
jksoft 1:4a634c06c5dc 10 #define MILKCOCOA_SUBSCRIBERS 8
jksoft 0:23e533c4b1ec 11
jksoft 0:23e533c4b1ec 12 class DataElement {
jksoft 0:23e533c4b1ec 13 public:
jksoft 0:23e533c4b1ec 14 DataElement();
jksoft 0:23e533c4b1ec 15 DataElement(char *json_string);
jksoft 0:23e533c4b1ec 16 void setValue(const char *key, const char *v);
jksoft 0:23e533c4b1ec 17 void setValue(const char *key, int v);
jksoft 0:23e533c4b1ec 18 void setValue(const char *key, double v);
jksoft 0:23e533c4b1ec 19 char *toCharArray();
jksoft 0:23e533c4b1ec 20 char *getString(const char *key);
jksoft 0:23e533c4b1ec 21 int getInt(const char *key);
jksoft 0:23e533c4b1ec 22 float getFloat(const char *key);
jksoft 0:23e533c4b1ec 23
jksoft 0:23e533c4b1ec 24 private:
jksoft 0:23e533c4b1ec 25 char json_msg[256];
jksoft 0:23e533c4b1ec 26 };
jksoft 0:23e533c4b1ec 27
jksoft 0:23e533c4b1ec 28 typedef void (*GeneralFunction) (MQTT::MessageData& elem);
jksoft 0:23e533c4b1ec 29
jksoft 1:4a634c06c5dc 30 class MilkcocoaSubscriber {
jksoft 1:4a634c06c5dc 31 public:
jksoft 1:4a634c06c5dc 32 GeneralFunction cb;
jksoft 1:4a634c06c5dc 33 char topic[100];
jksoft 1:4a634c06c5dc 34 MilkcocoaSubscriber(GeneralFunction _cb);
jksoft 1:4a634c06c5dc 35 };
jksoft 1:4a634c06c5dc 36
jksoft 0:23e533c4b1ec 37 class Milkcocoa {
jksoft 0:23e533c4b1ec 38 public:
jksoft 0:23e533c4b1ec 39
jksoft 1:4a634c06c5dc 40 // Milkcocoa(const char *host, uint16_t port, const char *_app_id, const char *client_id);
jksoft 1:4a634c06c5dc 41 Milkcocoa(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id);
jksoft 1:4a634c06c5dc 42 Milkcocoa(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session);
jksoft 1:4a634c06c5dc 43 static Milkcocoa* createWithApiKey(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret);
jksoft 0:23e533c4b1ec 44 void connect();
jksoft 0:23e533c4b1ec 45 void loop();
jksoft 0:23e533c4b1ec 46 bool push(const char *path, DataElement dataelement);
jksoft 0:23e533c4b1ec 47 bool send(const char *path, DataElement dataelement);
jksoft 0:23e533c4b1ec 48 bool on(const char *path, const char *event, GeneralFunction cb);
jksoft 0:23e533c4b1ec 49
jksoft 0:23e533c4b1ec 50 private:
jksoft 0:23e533c4b1ec 51 char servername[64];
jksoft 0:23e533c4b1ec 52 int16_t portnum;
jksoft 0:23e533c4b1ec 53 char _clientid[64];
jksoft 0:23e533c4b1ec 54 char username[32];
jksoft 0:23e533c4b1ec 55 char password[32];
jksoft 0:23e533c4b1ec 56 const char *app_id;
jksoft 0:23e533c4b1ec 57
jksoft 1:4a634c06c5dc 58 MClient *client;
jksoft 0:23e533c4b1ec 59 GeneralFunction _cb;
jksoft 1:4a634c06c5dc 60 MilkcocoaSubscriber *milkcocoaSubscribers[MILKCOCOA_SUBSCRIBERS];
jksoft 0:23e533c4b1ec 61 };
jksoft 0:23e533c4b1ec 62
jksoft 0:23e533c4b1ec 63
jksoft 0:23e533c4b1ec 64 #endif