mbed OS5に対応したMilkcocoaライブラリのテストバージョンです。

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
jksoft
Date:
Tue Jan 24 13:41:36 2017 +0000
Revision:
24:6ba1245bf049
??????????

Who changed what in which revision?

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