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

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

Committer:
jksoft
Date:
Thu Jun 01 00:23:41 2017 +0000
Revision:
6:1b5ec3a15d67
Parent:
4:9cfd43d8de16
Child:
8:e2f15b1b4f70
???????????????????????????????

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