Connection to port 80 failing
Posted: Thu Aug 11, 2016 4:33 pm
I'm learning to use IFTTT, so I set up a simple sketch that connects to the site and triggers an event to send an e-mail. I'm still pretty new to this, so I'm basing my code off of the example here. (There's a lot of that code I don't use since I'm just sending an e-mail based off of some serial input and not connecting to the other components.) However, when I try to connect to port 80, it fails. The code itself isn't set up to give useful debug information, and I don't know how to correct that. I did try replacing the line
Here is my full code:
And here is the information from IFTTT on how to trigger the event (specific for my sending an e-mail event), for anyone not familiar with the site.
Can someone assist? Either help me figure out how to get more useful debug information so I actually have an error I can google search, or help me figure out what I'm doing wrong? Thank you.
Code: Select all
to if (!client.connect(host, httpPort)
Code: Select all
to see if it was because I was referencing something wrong, but I got the same result. Can someone assist? Either help me figure out how to get more useful debug information so I actually have an error I can google search, or help me figure out what I'm doing wrong? Thank you.if (!client.connect(maker.ifttt.com, 80)
Here is my full code:
Code: Select all
#include <ESP8266WiFi.h>
const char* ssid = "HelloSweetie-2.4";
const char* password = "---";
const char* host = "maker.ifttt.com";
const char* apiKey = "dtroLxkk-EmuH6M31vPC7K";
String input = "";
String messageBody = "Body of test message.";
void setup() {
Serial.begin(115200);
delay(100);
WiFi.begin(ssid,password);
}
void loop() {
if (Serial.available()) {
input = Serial.readString();
delay(1000);
if (input = "send") {
Serial.println("Confirmed");
Serial.print("Connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) { //this section seems to be my problem
Serial.println("Connection failed");
return;
}
String url = "/trigger/send/with/key/";
url += apiKey;
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("POST") + url + "HTTP/1.1\r\n" + "Host: " + host + "\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" + "Content-Length: 13\r\n\r\n" +
"value1=" + messageBody + "\r\n");
} else {
Serial.println("Invalid input. Try again.");
}
input = "";
}
}
And here is the information from IFTTT on how to trigger the event (specific for my sending an e-mail event), for anyone not familiar with the site.
Can someone assist? Either help me figure out how to get more useful debug information so I actually have an error I can google search, or help me figure out what I'm doing wrong? Thank you.