2018年2月6日 星期二

RFID Card Data send TO LINE Thru IFTTT

RFID Card Data send TO LINE Thru IFTTT

/************************************************************
ESP8266_NodeMCU_IFTTT_Maker.ino
IFTTT Channel Maker Posting Example
Andres Sabas @ The Inventor's House
Original Creation Date: Jan 10, 2016
This example demonstrates how to use the TCP client
functionality of the ESP8266 WiFiSecure library to post
to a IFTTT event on
https://ifttt.com
Development environment specifics:
  IDE: Arduino 1.6.5
  Hardware Platform:
  ESP8266 HUZZAH Adafruit
  or NodeMCU: 1.0
This code is beerware; if you see me (or any other The Inventor's House
member) at the local, and you've found our code helpful,
please buy us a round!
Distributed as-is; no warranty is given.
************************************************************/
//Include that library first:
#include <ESP8266WiFi.h>
// Include the ESP8266 WiFiSecure library:
#include <WiFiClientSecure.h>

//////////////////////////////
// WiFi Network Definitions //
//////////////////////////////
// Replace these two character strings with the name and
// password of your WiFi network.
const char mySSID[] = "PTS-2F";
const char myPSK[] = "";

/////////////////////
// IFTTT Constants //
/////////////////////
// IFTTT destination server:
const char* IFTTTServer = "maker.ifttt.com";
// IFTTT https por:
const int httpsPort = 443;
// IFTTT Event:
const String MakerIFTTT_Event = "button";
// IFTTT private key:
const String MakerIFTTT_Key = "zaHdzsOGgZ71vZT1Y1FA6";

String httpHeader = "POST /trigger/"+MakerIFTTT_Event+"/with/key/"+MakerIFTTT_Key +" HTTP/1.1\r\n" +
                    "Host: " + IFTTTServer + "\r\n" +
                    "Content-Type: application/x-www-form-urlencoded\r\n\r\n";

void setup()
{
  int status;
  Serial.begin(115200);
  Serial.println();
  Serial.print(F("connecting to "));
  Serial.println(mySSID);
  WiFi.begin(mySSID, myPSK);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address is: "));
  Serial.println(WiFi.localIP());
 
  Serial.println(F("Press any key to post to IFTTT!"));
}

void loop()
{
  // If a character has been received over serial:
  if (Serial.available())
  {
    // !!! Make sure we haven't posted recently
    // Post to IFTTT!
    postToIFTTT();
    // Then clear the serial buffer:
    while (Serial.available())
      Serial.read();
  }
}

void postToIFTTT()
{
  // Create a client, and initiate a connection
  WiFiClientSecure client;
 
  if (client.connect(IFTTTServer, httpsPort) <= 0)
  {
    Serial.println(F("Failed to connect to server."));
    return;
  }
  Serial.println(F("Connected."));

  Serial.println(F("Posting to IFTT Event!"));
 
  client.print(httpHeader);

  // available() will return the number of characters
  // currently in the receive buffer.
  while (client.available())
    Serial.write(client.read()); // read() gets the FIFO char
 
  // connected() is a boolean return value - 1 if the
  // connection is active, 0 if it's closed.
  if (client.connected())
    client.stop(); // stop() closes a TCP connection.
}














沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...