ワークショップ用のサンプルプログラムです。

Dependencies:   DHT mbed

Committer:
jksoft
Date:
Fri Apr 29 21:07:24 2016 +0000
Revision:
0:a967c8649563
??

Who changed what in which revision?

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