Send https request to trigger webhook

Hello everyone!

I'm trying to trigger a webhook of IFTTT from my Arduino MKR 1010 with a simple https request.

I'm using Wifinina example to send a google request. Wich definitly works. I've tested my webhook link wich works. But I cannot find any example of code that would send a https link to trigger a webhook.

Here is the Wifinina Client exemple code:

 if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  }

That I tried to adapt to a webhook adress such as:

 if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /trigger/{MYPROJECT}/with/key/{MYKEY} HTTP/1.1");
    client.println("Host: maker.ifttt.com");
    client.println("Connection: close");
    client.println();
  }

But clearly I'm missing a point here and I'm not sure what I don't understand.

Thank you guys for your patience and help,

Cheers

That code triggers a http hook but not a https hook you probably intended. The https port is 443 but that's not the only detail you have to change to enable TLS encryption. As you failed unfortunately to post complete code (as we request in the sticky post at the top of the forum) we cannot help you further.

Not sure it's relevant, but you might want to look at my code for my mailbox notifier, which triggers a webhooks event via IFTTT. It's a secure connection, but uses an option to ignore all the certificate stuff. But note that it's for a Lolin D1 Mini (ESP8266).

https://github.com/gbhug5a/Mailbox-Notifier

I'm sorry you're right I should posted the whole code.

/*

This example creates a client object that connects and transfers

data using always SSL.

It is compatible with the methods normally related to plain

connections, like client.connect(host, port).

Written by Arturo Guadalupi

last revision November 2015

*/

#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "www.google.com";    // name address for Google (using DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):

WiFiSSLClient client;

void setup() {

  //Initialize serial and wait for port to open:

  Serial.begin(9600);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for native USB port only

  }

  // check for the WiFi module:

  if (WiFi.status() == WL_NO_MODULE) {

    Serial.println("Communication with WiFi module failed!");

    // don't continue

    while (true);

  }

  String fv = WiFi.firmwareVersion();

  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {

    Serial.println("Please upgrade the firmware");

  }

  // attempt to connect to WiFi network:

  while (status != WL_CONNECTED) {

    Serial.print("Attempting to connect to SSID: ");

    Serial.println(ssid);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:

    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:

    delay(10000);

  }

  Serial.println("Connected to wifi");

  printWiFiStatus();

  Serial.println("\nStarting connection to server...");

  // if you get a connection, report back via serial:

if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /trigger/{MYPROJECT}/with/key/{MYKEY} HTTP/1.1");
    client.println("Host: maker.ifttt.com");
    client.println("Connection: close");
    client.println();
  }
}

void loop() {

  // if there are incoming bytes available

  // from the server, read them and print them:

  while (client.available()) {

    char c = client.read();

    Serial.write(c);

  }

  // if the server's disconnected, stop the client:

  if (!client.connected()) {

    Serial.println();

    Serial.println("disconnecting from server.");

    client.stop();

    // do nothing forevermore:

    while (true);

  }
}

void printWiFiStatus() {

  // print the SSID of the network you're attached to:

  Serial.print("SSID: ");

  Serial.println(WiFi.SSID());

  // print your board's IP address:

  IPAddress ip = WiFi.localIP();

  Serial.print("IP Address: ");

  Serial.println(ip);

  // print the received signal strength:

  long rssi = WiFi.RSSI();

  Serial.print("signal strength (RSSI):");

  Serial.print(rssi);

  Serial.println(" dBm");p
}

I indeed correct the port 443 but I feel I'm not on the right track here.

My C++ skills are pretty basic, but does C++ let you include the stuff in curly braces inside quote marks in a println? Or does it just print "{MYPROJECT}" literally?

I don't think you've said how far your code gets or where it errors out.

I'm sorry from the begining my question is not clear.

Here is here what happen to the serial monitor:

16:29:11.907 -> Attempting to connect to SSID: SFR_4600
16:29:23.741 -> Connected to WiFi
16:29:23.741 -> SSID: SFR_4600
16:29:23.741 -> IP Address: 192.168.1.22
16:29:23.787 -> signal strength (RSSI):-59 dBm
16:29:23.787 -> 
16:29:23.787 -> Starting connection to server...
16:29:40.580 -> 
16:29:40.580 -> disconnecting from server.

And Here is the code uploaded on my Arduino MKR 1010
(I only tried to change the information from the Wifinina SSL client example with my webhook https link)

/*
This example creates a client object that connects and transfers
data using always SSL.

It is compatible with the methods normally related to plain
connections, like client.connect(host, port).

Written by Arturo Guadalupi
last revision November 2015

*/

#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
char server[] = "maker.ifttt.com";    //

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiSSLClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to WiFi");
  printWiFiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 443)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /trigger/{hidden_project-name}/with/key/{hiddenkey} HTTP/1.1");
    client.println("Host: maker.ifttt.com");
    client.println("Connection: close");
    client.println();


  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}


void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

I feel it's more complicated than what I'm doing but I'm stucked...

Thanks for your patience !!

So you're connecting to www.google.com on port 80 (standard HTTP port) using an SSL client (which expects an SSL or TLS server) but the request is made for an ifttt.com server.

Do you see where the problem is?

BTW, HTTPS is on port 443.

I hope in your code you actually compiled and uploaded you got the values in curly braces replaced by your real application keys.

If just seen that you get that right in the later version of the code.
If that connection fails, you might have to upload the server's certificate to the module.

It looks like he isn't even getting to the client.println. He should be getting "connected to server", but isn't. I don't know why.

I also posted about the curly braces. If that works, I'm going to steal it.

No, he won't if the certificate is not accepted. The connect method of the WiFiSSLClient class isn't just opening the TCP connection but also establishes a secure TLS tunnel. If it cannot do that it will return 0.

Well, as stated in my post #3, there's a way to establish the encrypted connection on 443 while ignoring the certificate checking. But that was in the ESP8266 library. I don't know how you would do that with this library.

I wonder if the original example works connecting to Google instead of IFTTT. That might tell us something.

Hi everyone.

I solved the problem by switching my Webhook to Make.com

I did try to upload the IFTTT SSL certificate following the link you gave. But it failed to uplaoad dispite reseting the board.

Therefore here is the code that is working here for me:

/*
This example creates a client object that connects and transfers
data using always SSL.

It is compatible with the methods normally related to plain
connections, like client.connect(host, port).

Written by Arturo Guadalupi
last revision November 2015

*/

#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h" 
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "hook.eu1.make.com";   

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiSSLClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to WiFi");
  printWiFiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  if (client.connect(server, 443)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println("GET /{my_project-key} HTTP/1.1");
    client.println("Host: hook.eu1.make.com");
    client.println("Connection: close");
    client.println();

  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting from server.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}


void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Thank you all for your help !

Ok, so the curly braces were just for posting the code here without revealing the key. Should that have been obvious? I guess so.

Well, I'll have to dig out my mailbox notifier and see if it still works with IFTTT. Edit: It still does.

If you take a look at the WiFiNINA library you'll see that there is no such call.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.