source: rtos_arduino/trunk/arduino_lib/libraries/Milkcocoa_Arduino_SDK/Milkcocoa.h@ 144

Last change on this file since 144 was 144, checked in by ertl-honda, 8 years ago

Milkcocoa用のMQTTライブラリの追加と,ESP8266用ライブラリの名称変更.

File size: 2.9 KB
Line 
1/*
2The MIT License (MIT)
3
4Copyright (c) 2015 Technical Rockstars
5Copyright (C) 2015 Embedded and Real-Time Systems Laboratory
6 Graduate School of Information Science, Nagoya Univ., JAPAN
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24*/
25#ifndef _MILKCOCOA_H_
26#define _MILKCOCOA_H_
27
28#include "Client.h"
29#include "include/Adafruit/Adafruit_MQTT.h"
30#include "include/Adafruit/Adafruit_MQTT_Client.h"
31#include "include/aJson/aJson.h"
32
33#define MILKCOCOA_SUBSCRIBERS 8
34
35class DataElement {
36 public:
37 DataElement();
38 DataElement(char *json_string);
39 ~DataElement();
40 void setValue(const char *key, const char *v);
41 void setValue(const char *key, int v);
42 void setValue(const char *key, double v);
43 char *toCharArray();
44 char *getString(const char *key);
45 int getInt(const char *key);
46 float getFloat(const char *key);
47
48 private:
49 aJsonObject *params;
50 aJsonObject *paJsonObj;
51};
52
53typedef void (*GeneralFunction) (DataElement *pelem);
54
55class MilkcocoaSubscriber {
56 public:
57 Adafruit_MQTT_Subscribe *mqtt_sub;
58 GeneralFunction cb;
59 char topic[100];
60 MilkcocoaSubscriber(GeneralFunction _cb);
61 void set_mqtt_sub(Adafruit_MQTT_Subscribe *_mqtt_sub);
62};
63
64class Milkcocoa {
65 public:
66 Milkcocoa(Client *client, const char *host, uint16_t port, const char *_app_id, const char *client_id);
67 Milkcocoa(Client *client, const char *host, uint16_t port, const char *_app_id, const char *client_id, const char *_session);
68 static Milkcocoa* createWithApiKey(Client *client, const char *host, uint16_t port, const char *app_id, const char *client_id, const char *key, const char *secret);
69 void connect();
70 void loop();
71 bool push(const char *path, DataElement *pdataelement);
72 bool send(const char *path, DataElement *pdataelement);
73 bool on(const char *path, const char *event, GeneralFunction cb);
74
75
76private:
77 const char *app_id;
78 char session[128];
79 Adafruit_MQTT_Client *mqtt;
80 MilkcocoaSubscriber *milkcocoaSubscribers[MILKCOCOA_SUBSCRIBERS];
81};
82
83
84#endif
Note: See TracBrowser for help on using the repository browser.