I am trying to connect arduino uno to ifttt server to trigger a philip lightbulb. I done some research
and found out this I followed it advise and
made this code
#include "WiFiEsp.h"
#define USE_JSON_FOR_IFTTT true
#include "HttpClient.h"
#define HTTP_CODE_OK 200 // Good HTTP return code
//#include "MY_IFTTT_CREDENTIALS.h"
#define MY_IFTTT_KEY "included" // from Webhooks doc in IFTTT when you have an IFTTT account
#define MY_IFTTT_APPLET MY_IFTTT_SONOFF_APPLET // from IFTTT Applet which consumes the webhook POST
// Very helpful article on HTTP GET and POST
// https://randomnerdtutorials.com/esp32-http-get-post-arduino/#http-post
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "xxx"; // your network SSID (name)
char pass[] = "xxx"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
void postToIFTTT ( const String& message )
{
Serial.println ( "\npostToIFTTT called with message <" + message + ">" );
// Set up an HTTP client object for the IFTTT POST
HttpClient IFTTTpost;
// Server name URL
String IFTTTserverName = "https://maker.ifttt.com/trigger/" + String ( MY_IFTTT_APPLET ) + "/with/key/" + String ( MY_IFTTT_KEY );
long elapsed = millis();
#if ESP32
IFTTTpost.begin ( IFTTTserverName ); //Specify request destination, open HTTP connecction
#elif ESP8266
WiFiClientSecure client;
IFTTTpost.begin ( client, IFTTTserverName ); //Specify request destination, open HTTP connecction
#endif
Serial.print ( " IFTTT ServerName <" ); Serial.print ( IFTTTserverName ); Serial.println ( ">" );
#if USE_JSON_FOR_IFTTT
IFTTTpost.addHeader ( "Content-Type", "application/json" );
// IFTTT's JSON payload is { "value1" : "xx", "value2" : "mm", "value3" : "gg" }
// IFTTTrequest = "{ \"value1\" : \"Yo_Bud\", \"value2\" : \"mm\", \"value3\" : \"gg" }";
String IFTTTrequest = "{ \"value1\" : \"" + String ( message ) + "\" }"; // spaces permitted !
Serial.print ( " JSON POST is <" ); Serial.print ( IFTTTrequest ); Serial.println ( ">" );
#else
//IFTTTpost.addHeader ( "Content-Type", "text/plain" );
IFTTTpost.addHeader ( "Content-Type", "application/x-www-form-urlencoded" );
// IFTTT's text payload is "?&value1=val1&value2=val2&value3=val3"
String IFTTTrequest = "?&value1=Hey_Man-text-POST"; // no spaces allowed
Serial.print ( " text POST is <" ); Serial.print ( IFTTTrequest ); Serial.println ( ">" );
#endif
int IFTTTreturnCode = IFTTTpost.POST ( IFTTTrequest ); // POST the request to IFTTT
Serial.print ( " elapsed time in ms = " ); Serial.println ( millis() - elapsed );
Serial.print ( " return code: " ); Serial.println ( IFTTTreturnCode );
if ( IFTTTreturnCode > 0 ) //Check the returning code (200 is AOK)
{
String payload = IFTTTpost.getString(); //Get the request response payload
Serial.println ( " response string: <" + payload + ">" );
}
IFTTTpost.end(); //Close HTTP connection
} // end postToIFTTT
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(115200);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for a second
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
delay(2000);
}
however, it told me no matching function for call to 'HttpClient::HttpClient()' when i try to compile it.
Arduino: 1.8.15 (Windows 10), Board: "Arduino Uno"
C:\Users\user\Documents\Arduino\wifi8266\wifi8266.ino: In function 'void postToIFTTT(const String&)':
wifi8266:30:14: error: no matching function for call to 'HttpClient::HttpClient()'
HttpClient IFTTTpost;
^~~~~~~~~
In file included from C:\Users\user\Documents\Arduino\wifi8266\wifi8266.ino:4:0:
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:53:5: note: candidate: HttpClient::HttpClient(Client&, const IPAddress&, uint16_t)
HttpClient(Client& aClient, const IPAddress& aServerAddress, uint16_t aServerPort = kHttpPort);
^~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:53:5: note: candidate expects 3 arguments, 0 provided
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:52:5: note: candidate: HttpClient::HttpClient(Client&, const String&, uint16_t)
HttpClient(Client& aClient, const String& aServerName, uint16_t aServerPort = kHttpPort);
^~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:52:5: note: candidate expects 3 arguments, 0 provided
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:51:5: note: candidate: HttpClient::HttpClient(Client&, const char*, uint16_t)
HttpClient(Client& aClient, const char* aServerName, uint16_t aServerPort = kHttpPort);
^~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:51:5: note: candidate expects 3 arguments, 0 provided
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:41:7: note: candidate: HttpClient::HttpClient(const HttpClient&)
class HttpClient : public Client
^~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:41:7: note: candidate expects 1 argument, 0 provided
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:41:7: note: candidate: HttpClient::HttpClient(HttpClient&&)
C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:41:7: note: candidate expects 1 argument, 0 provided
wifi8266:10:25: error: 'MY_IFTTT_SONOFF_APPLET' was not declared in this scope
#define MY_IFTTT_APPLET MY_IFTTT_SONOFF_APPLET // from IFTTT Applet which consumes the webhook POST
^
C:\Users\user\Documents\Arduino\wifi8266\wifi8266.ino:34:74: note: in expansion of macro 'MY_IFTTT_APPLET'
String IFTTTserverName = "https://maker.ifttt.com/trigger/" + String ( MY_IFTTT_APPLET ) + "/with/key/" + String ( MY_IFTTT_KEY );
^~~~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\wifi8266\wifi8266.ino:10:25: note: suggested alternative: 'MY_IFTTT_APPLET'
#define MY_IFTTT_APPLET MY_IFTTT_SONOFF_APPLET // from IFTTT Applet which consumes the webhook POST
^
C:\Users\user\Documents\Arduino\wifi8266\wifi8266.ino:34:74: note: in expansion of macro 'MY_IFTTT_APPLET'
String IFTTTserverName = "https://maker.ifttt.com/trigger/" + String ( MY_IFTTT_APPLET ) + "/with/key/" + String ( MY_IFTTT_KEY );
^~~~~~~~~~~~~~~
wifi8266:48:13: error: 'class HttpClient' has no member named 'addHeader'; did you mean 'sendHeader'?
IFTTTpost.addHeader ( "Content-Type", "application/json" );
^~~~~~~~~
sendHeader
wifi8266:65:35: error: 'class HttpClient' has no member named 'POST'
int IFTTTreturnCode = IFTTTpost.POST ( IFTTTrequest ); // POST the request to IFTTT
^~~~
wifi8266:73:32: error: 'class HttpClient' has no member named 'getString'; did you mean 'readString'?
String payload = IFTTTpost.getString(); //Get the request response payload
^~~~~~~~~
readString
wifi8266:77:13: error: 'class HttpClient' has no member named 'end'; did you mean 'read'?
IFTTTpost.end(); //Close HTTP connection
^~~
read
Multiple libraries were found for "HttpClient.h"
Used: C:\Users\user\Documents\Arduino\libraries\ArduinoHttpClient
Not used: C:\Program Files (x86)\Arduino\libraries\Bridge
exit status 1
no matching function for call to 'HttpClient::HttpClient()'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.