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

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

Committer:
jksoft
Date:
Mon Mar 26 04:49:20 2018 +0000
Revision:
13:61e0cc093180
Parent:
12:6eafbe763882
???????????

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 12:6eafbe763882 43 Milkcocoa(NetworkInterface* nif);
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 12:6eafbe763882 47 void set_network_settinng(const char *host, uint16_t port, const char *_app_id, const char *client_id);
jksoft 0:0a2f634d3324 48 void connect();
jksoft 0:0a2f634d3324 49 void loop();
jksoft 12:6eafbe763882 50 void send_massage();
jksoft 8:e2f15b1b4f70 51 void close();
jksoft 0:0a2f634d3324 52 bool push(const char *path, DataElement dataelement);
jksoft 3:cddf81a87de3 53 bool push(const char *path, char *data);
jksoft 0:0a2f634d3324 54 bool send(const char *path, DataElement dataelement);
jksoft 3:cddf81a87de3 55 bool send(const char *path, char *data);
jksoft 0:0a2f634d3324 56 bool on(const char *path, const char *event, GeneralFunction cb);
jksoft 6:1b5ec3a15d67 57 #ifdef __MILKCOCOA_THREAD
jksoft 0:0a2f634d3324 58 void setLoopCycle(int cycle);
jksoft 0:0a2f634d3324 59 void start();
jksoft 6:1b5ec3a15d67 60 #endif
jksoft 0:0a2f634d3324 61 private:
jksoft 0:0a2f634d3324 62 char servername[64];
jksoft 0:0a2f634d3324 63 int16_t portnum;
jksoft 0:0a2f634d3324 64 char _clientid[64];
jksoft 0:0a2f634d3324 65 char username[32];
jksoft 0:0a2f634d3324 66 char password[32];
jksoft 4:9cfd43d8de16 67 char app_id[32];
jksoft 6:1b5ec3a15d67 68 char _message[256];
jksoft 0:0a2f634d3324 69 int16_t loop_cycle;
jksoft 0:0a2f634d3324 70
jksoft 0:0a2f634d3324 71 MQTTInterface* ipstack;
jksoft 0:0a2f634d3324 72 MClient *client;
jksoft 0:0a2f634d3324 73 GeneralFunction _cb;
jksoft 0:0a2f634d3324 74 MilkcocoaSubscriber *milkcocoaSubscribers[MILKCOCOA_SUBSCRIBERS];
jksoft 6:1b5ec3a15d67 75
jksoft 6:1b5ec3a15d67 76 #ifdef __MILKCOCOA_THREAD
jksoft 1:8e4149b53a8a 77 Thread cycleThread1;
jksoft 1:8e4149b53a8a 78 Thread cycleThread2;
jksoft 1:8e4149b53a8a 79 void cycle_Thread1(void);
jksoft 1:8e4149b53a8a 80 void cycle_Thread2(void);
jksoft 1:8e4149b53a8a 81 static void threadStarter1(void const *p);
jksoft 1:8e4149b53a8a 82 static void threadStarter2(void const *p);
jksoft 6:1b5ec3a15d67 83 #endif
jksoft 0:0a2f634d3324 84 typedef struct {
jksoft 12:6eafbe763882 85 char message[192];
jksoft 12:6eafbe763882 86 char topic[64];
jksoft 0:0a2f634d3324 87 } milkcocoa_message_t;
jksoft 13:61e0cc093180 88 Mail<milkcocoa_message_t, 4> message_box;
jksoft 8:e2f15b1b4f70 89 int connectting;
jksoft 8:e2f15b1b4f70 90 int mqtt_connectting;
jksoft 6:1b5ec3a15d67 91
jksoft 0:0a2f634d3324 92 };
jksoft 0:0a2f634d3324 93
jksoft 0:0a2f634d3324 94 #endif