IFTTT IP -> URL

Dependents:   IFTTT_Ethernet_LM61

Fork of IFTTT by Austin Blackstone

ifttt.h

Committer:
mbedAustin
Date:
2015-07-10
Revision:
0:4f7b5d6048b3
Child:
3:c916e13a269a

File content as of revision 0:4f7b5d6048b3:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef IFTTT_H
#define IFTTT_H

#include "mbed.h"
#include "TCPSocketConnection.h"

#define IFTTT_FAIL -1
#define IFTTT_SUCCESS 0

#define IFTTT_MAX_RETRY 5
#define IFTTT_MAX_SIZE_SECRETKEY 50
#define IFTTT_MAX_SIZE_EVENTNAME 50
#define IFTTT_MAX_SIZE_STRING 512

#define IFTTT_IP "107.22.235.178"
#define IFTTT_PORT 80



/**
* The IFTTT class (if this then that)
*/
class IFTTT
{

public:

    /**
    * Constructor, initialize the Event Name and Secret Key to be used
    *
    * @param event event name of trigger
    * @param key secret key provided by the maker channel for your event
    */
    IFTTT(const char * event, const char * key, TCPSocketConnection * s = NULL);

    /**
    * Send data to maker.ifttt.com
    *
    * @param v1 value 1 to send
    * @param v2 value 2 to send
    * @param v3 value 3 to send
    *
    * @return true if successful, false if failed
    */
    bool sendMaker(char * v1 = NULL, char * v2 = NULL, char * v3 = NULL);

    /**
    * Send data to maker.ifttt.com
    *
    * @param v1 value 1 to send
    * @param v2 value 2 to send
    * @param v3 value 3 to send
    *
    * @return true if successful, false if failed
    */
    bool sendMaker(int v1 = NULL, int v2 = NULL, int v3 = NULL);

private:

    /**
    * Send data to maker.ifttt.com via GET Query parameters
    *
    * @param name explanation
    *
    * @return true if successful, false if failed
    */
    bool get();

    /**
    * Send data to maker.ifttt.com via POST payload, encoded as JSON
    *
    * @param name explanation
    *
    * @return true if successful, false if failed
    */
    bool post();

    TCPSocketConnection * socket;
    char eventName[IFTTT_MAX_SIZE_EVENTNAME];
    char secretKey[IFTTT_MAX_SIZE_SECRETKEY];
    const char * v1;
    const char * v2;
    const char * v3;
    const char * host;
    int port;
};

#endif // IFTTT_H