Simple IoT Board用のIFTTTのMaker Channelに繋げるためのサンプルです。
Dependencies: SimpleIoTBoardLib mbed
ifttt.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef IFTTT_H 00017 #define IFTTT_H 00018 00019 #include "mbed.h" 00020 #include "TCPSocketConnection.h" 00021 00022 #define IFTTT_FAIL -1 00023 #define IFTTT_SUCCESS 0 00024 00025 #define IFTTT_MAX_RETRY 5 00026 #define IFTTT_MAX_SIZE_SECRETKEY 50 00027 #define IFTTT_MAX_SIZE_EVENTNAME 50 00028 #define IFTTT_MAX_SIZE_STRING 512 00029 00030 #define IFTTT_IP "maker.ifttt.com" 00031 #define IFTTT_PORT 80 00032 00033 #define IFTTT_GET 0 00034 #define IFTTT_POST 1 00035 00036 00037 /** 00038 * The IFTTT class (if this then that) 00039 */ 00040 class IFTTT 00041 { 00042 00043 public: 00044 00045 /** 00046 * Constructor, initialize the Event Name and Secret Key to be used 00047 * 00048 * @param event event name of trigger 00049 * @param key secret key provided by the maker channel for your event 00050 */ 00051 IFTTT(const char * event, const char * key, TCPSocketConnection * s = NULL); 00052 00053 /** 00054 * Add ingredients (values) to be sent to maker.ifttt.com 00055 * 00056 * @param v1 value 1 to send 00057 * @param v2 value 2 to send 00058 * @param v3 value 3 to send 00059 * 00060 * @return true if successful, false if failed 00061 */ 00062 bool addIngredients(char * v1 = NULL, char * v2 = NULL, char * v3 = NULL); 00063 00064 /** 00065 * Add ingredients (values) to be sent to maker.ifttt.com 00066 * 00067 * @param v1 value 1 to send 00068 * @param v2 value 2 to send 00069 * @param v3 value 3 to send 00070 * 00071 * @return true if successful, false if failed 00072 */ 00073 bool addIngredients(int v1 = NULL, int v2 = NULL, int v3 = NULL); 00074 00075 /** 00076 * Send data via POST or GET to maker.ifttt.com 00077 * 00078 * @param iftttType specifies how to send the data. POST by default, GET optional. 00079 * 00080 * @return true if successful, false if failed 00081 */ 00082 bool trigger(int triggerType = IFTTT_POST); 00083 00084 private: 00085 00086 /** 00087 * Send data to maker.ifttt.com via GET Query parameters 00088 * 00089 * @param name explanation 00090 * 00091 * @return true if successful, false if failed 00092 */ 00093 bool get(); 00094 00095 /** 00096 * Send data to maker.ifttt.com via POST payload, encoded as JSON 00097 * 00098 * @param name explanation 00099 * 00100 * @return true if successful, false if failed 00101 */ 00102 bool post(); 00103 00104 TCPSocketConnection * socket; 00105 char eventName[IFTTT_MAX_SIZE_EVENTNAME]; 00106 char secretKey[IFTTT_MAX_SIZE_SECRETKEY]; 00107 const char * v1; 00108 const char * v2; 00109 const char * v3; 00110 const char * host; 00111 int port; 00112 00113 }; 00114 00115 #endif // IFTTT_H
Generated on Tue Jul 12 2022 18:14:19 by 1.7.2