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

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

Committer:
jksoft
Date:
Wed Feb 15 02:15:55 2017 +0000
Revision:
1:8e4149b53a8a
Parent:
0:0a2f634d3324
Child:
3:cddf81a87de3
Milkcocoa?????????????????????????; (?????????????????????????????????); MQTT?????????? 100->256

Who changed what in which revision?

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