データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: MilkcocoaSample MilkcocoaSampleESP8266_LED MilkcocoaSampleESP8266 MilkcocoaSample_3G ... more
Milkcocoa.h
00001 #ifndef _MILKCOCOA_H_ 00002 #define _MILKCOCOA_H_ 00003 00004 #include "mbed.h" 00005 #include "MQTTmbed.h" 00006 #include "MQTTClient.h" 00007 #include "MClient.h" 00008 00009 #define RECV_TIMEOUT 500 00010 #define MILKCOCOA_SUBSCRIBERS 8 00011 00012 class DataElement { 00013 public: 00014 DataElement(); 00015 DataElement(char *json_string); 00016 void setValue(const char *key, const char *v); 00017 void setValue(const char *key, int v); 00018 void setValue(const char *key, double v); 00019 char *toCharArray(); 00020 char *getString(const char *key); 00021 int getInt(const char *key); 00022 float getFloat(const char *key); 00023 00024 private: 00025 char json_msg[256]; 00026 }; 00027 00028 typedef void (*GeneralFunction) (MQTT::MessageData& elem); 00029 00030 class MilkcocoaSubscriber { 00031 public: 00032 GeneralFunction cb; 00033 char topic[100]; 00034 MilkcocoaSubscriber(GeneralFunction _cb); 00035 }; 00036 00037 class Milkcocoa { 00038 public: 00039 00040 // Milkcocoa(const char *host, uint16_t port, const char *_app_id, const char *client_id); 00041 Milkcocoa(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id); 00042 Milkcocoa(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *_session); 00043 static Milkcocoa* createWithApiKey(MClient *_client, const char *host, uint16_t port, const char *_app_id, const char *client_id, char *key, char *secret); 00044 void connect(); 00045 void loop(); 00046 bool push(const char *path, DataElement dataelement); 00047 bool send(const char *path, DataElement dataelement); 00048 bool on(const char *path, const char *event, GeneralFunction cb); 00049 00050 private: 00051 char servername[64]; 00052 int16_t portnum; 00053 char _clientid[64]; 00054 char username[32]; 00055 char password[32]; 00056 const char *app_id; 00057 00058 MClient *client; 00059 GeneralFunction _cb; 00060 MilkcocoaSubscriber *milkcocoaSubscribers[MILKCOCOA_SUBSCRIBERS]; 00061 }; 00062 00063 00064 #endif
Generated on Thu Jul 14 2022 13:39:07 by 1.7.2