Simple IoT Board用のIFTTTのMaker Channelに繋げるためのサンプルです。

Dependencies:   SimpleIoTBoardLib mbed

Committer:
jksoft
Date:
Sun Nov 15 13:44:04 2015 +0000
Revision:
0:8459cf3d30f7
??

Who changed what in which revision?

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