Simpe IoT BoardにGrove温度センサを繋げてIFTTTにプッシュするプログラムです。

Dependencies:   mbed

Committer:
jksoft
Date:
Sat Nov 14 02:53:45 2015 +0000
Revision:
1:8a97f4bd9773
Parent:
0:26b07836cf44
IFTTT????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:26b07836cf44 1 /* mbed Microcontroller Library
jksoft 0:26b07836cf44 2 * Copyright (c) 2006-2013 ARM Limited
jksoft 0:26b07836cf44 3 *
jksoft 0:26b07836cf44 4 * Licensed under the Apache License, Version 2.0 (the "License");
jksoft 0:26b07836cf44 5 * you may not use this file except in compliance with the License.
jksoft 0:26b07836cf44 6 * You may obtain a copy of the License at
jksoft 0:26b07836cf44 7 *
jksoft 0:26b07836cf44 8 * http://www.apache.org/licenses/LICENSE-2.0
jksoft 0:26b07836cf44 9 *
jksoft 0:26b07836cf44 10 * Unless required by applicable law or agreed to in writing, software
jksoft 0:26b07836cf44 11 * distributed under the License is distributed on an "AS IS" BASIS,
jksoft 0:26b07836cf44 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jksoft 0:26b07836cf44 13 * See the License for the specific language governing permissions and
jksoft 0:26b07836cf44 14 * limitations under the License.
jksoft 0:26b07836cf44 15 */
jksoft 0:26b07836cf44 16 #ifndef IFTTT_H
jksoft 0:26b07836cf44 17 #define IFTTT_H
jksoft 0:26b07836cf44 18
jksoft 0:26b07836cf44 19 #include "mbed.h"
jksoft 0:26b07836cf44 20 #include "TCPSocketConnection.h"
jksoft 0:26b07836cf44 21
jksoft 0:26b07836cf44 22 #define IFTTT_FAIL -1
jksoft 0:26b07836cf44 23 #define IFTTT_SUCCESS 0
jksoft 0:26b07836cf44 24
jksoft 0:26b07836cf44 25 #define IFTTT_MAX_RETRY 5
jksoft 0:26b07836cf44 26 #define IFTTT_MAX_SIZE_SECRETKEY 50
jksoft 0:26b07836cf44 27 #define IFTTT_MAX_SIZE_EVENTNAME 50
jksoft 0:26b07836cf44 28 #define IFTTT_MAX_SIZE_STRING 512
jksoft 0:26b07836cf44 29
jksoft 1:8a97f4bd9773 30 #define IFTTT_IP "maker.ifttt.com"
jksoft 0:26b07836cf44 31 #define IFTTT_PORT 80
jksoft 0:26b07836cf44 32
jksoft 0:26b07836cf44 33 #define IFTTT_GET 0
jksoft 0:26b07836cf44 34 #define IFTTT_POST 1
jksoft 0:26b07836cf44 35
jksoft 0:26b07836cf44 36
jksoft 0:26b07836cf44 37 /**
jksoft 0:26b07836cf44 38 * The IFTTT class (if this then that)
jksoft 0:26b07836cf44 39 */
jksoft 0:26b07836cf44 40 class IFTTT
jksoft 0:26b07836cf44 41 {
jksoft 0:26b07836cf44 42
jksoft 0:26b07836cf44 43 public:
jksoft 0:26b07836cf44 44
jksoft 0:26b07836cf44 45 /**
jksoft 0:26b07836cf44 46 * Constructor, initialize the Event Name and Secret Key to be used
jksoft 0:26b07836cf44 47 *
jksoft 0:26b07836cf44 48 * @param event event name of trigger
jksoft 0:26b07836cf44 49 * @param key secret key provided by the maker channel for your event
jksoft 0:26b07836cf44 50 */
jksoft 0:26b07836cf44 51 IFTTT(const char * event, const char * key, TCPSocketConnection * s = NULL);
jksoft 0:26b07836cf44 52
jksoft 0:26b07836cf44 53 /**
jksoft 0:26b07836cf44 54 * Add ingredients (values) to be sent to maker.ifttt.com
jksoft 0:26b07836cf44 55 *
jksoft 0:26b07836cf44 56 * @param v1 value 1 to send
jksoft 0:26b07836cf44 57 * @param v2 value 2 to send
jksoft 0:26b07836cf44 58 * @param v3 value 3 to send
jksoft 0:26b07836cf44 59 *
jksoft 0:26b07836cf44 60 * @return true if successful, false if failed
jksoft 0:26b07836cf44 61 */
jksoft 0:26b07836cf44 62 bool addIngredients(char * v1 = NULL, char * v2 = NULL, char * v3 = NULL);
jksoft 0:26b07836cf44 63
jksoft 0:26b07836cf44 64 /**
jksoft 0:26b07836cf44 65 * Add ingredients (values) to be sent to maker.ifttt.com
jksoft 0:26b07836cf44 66 *
jksoft 0:26b07836cf44 67 * @param v1 value 1 to send
jksoft 0:26b07836cf44 68 * @param v2 value 2 to send
jksoft 0:26b07836cf44 69 * @param v3 value 3 to send
jksoft 0:26b07836cf44 70 *
jksoft 0:26b07836cf44 71 * @return true if successful, false if failed
jksoft 0:26b07836cf44 72 */
jksoft 0:26b07836cf44 73 bool addIngredients(int v1 = NULL, int v2 = NULL, int v3 = NULL);
jksoft 0:26b07836cf44 74
jksoft 0:26b07836cf44 75 /**
jksoft 0:26b07836cf44 76 * Send data via POST or GET to maker.ifttt.com
jksoft 0:26b07836cf44 77 *
jksoft 0:26b07836cf44 78 * @param iftttType specifies how to send the data. POST by default, GET optional.
jksoft 0:26b07836cf44 79 *
jksoft 0:26b07836cf44 80 * @return true if successful, false if failed
jksoft 0:26b07836cf44 81 */
jksoft 0:26b07836cf44 82 bool trigger(int triggerType = IFTTT_POST);
jksoft 0:26b07836cf44 83
jksoft 0:26b07836cf44 84 private:
jksoft 0:26b07836cf44 85
jksoft 0:26b07836cf44 86 /**
jksoft 0:26b07836cf44 87 * Send data to maker.ifttt.com via GET Query parameters
jksoft 0:26b07836cf44 88 *
jksoft 0:26b07836cf44 89 * @param name explanation
jksoft 0:26b07836cf44 90 *
jksoft 0:26b07836cf44 91 * @return true if successful, false if failed
jksoft 0:26b07836cf44 92 */
jksoft 0:26b07836cf44 93 bool get();
jksoft 0:26b07836cf44 94
jksoft 0:26b07836cf44 95 /**
jksoft 0:26b07836cf44 96 * Send data to maker.ifttt.com via POST payload, encoded as JSON
jksoft 0:26b07836cf44 97 *
jksoft 0:26b07836cf44 98 * @param name explanation
jksoft 0:26b07836cf44 99 *
jksoft 0:26b07836cf44 100 * @return true if successful, false if failed
jksoft 0:26b07836cf44 101 */
jksoft 0:26b07836cf44 102 bool post();
jksoft 0:26b07836cf44 103
jksoft 0:26b07836cf44 104 TCPSocketConnection * socket;
jksoft 0:26b07836cf44 105 char eventName[IFTTT_MAX_SIZE_EVENTNAME];
jksoft 0:26b07836cf44 106 char secretKey[IFTTT_MAX_SIZE_SECRETKEY];
jksoft 0:26b07836cf44 107 const char * v1;
jksoft 0:26b07836cf44 108 const char * v2;
jksoft 0:26b07836cf44 109 const char * v3;
jksoft 0:26b07836cf44 110 const char * host;
jksoft 0:26b07836cf44 111 int port;
jksoft 0:26b07836cf44 112
jksoft 0:26b07836cf44 113 };
jksoft 0:26b07836cf44 114
jksoft 0:26b07836cf44 115 #endif // IFTTT_H