mirror of
https://github.com/luc-github/ESP3D.git
synced 2025-10-31 11:56:48 -07:00
Added support for IFTTT Webhook integration (#708)
* first push * modified post to work with IFTTT * working but returning wrong error code * command successfully being sent to, IFTTT * resolved issue with ESP600 returing "Wrong Command
This commit is contained in:
@@ -59,6 +59,10 @@ typedef WiFiClientSecure TSecureClient;
|
||||
#define LINESERVER "notify-api.line.me"
|
||||
#define LINEPORT 443
|
||||
|
||||
#define IFTTTTIMEOUT 5000
|
||||
#define IFTTTSERVER "maker.ifttt.com"
|
||||
#define IFTTTPORT 443
|
||||
|
||||
#define EMAILTIMEOUT 5000
|
||||
|
||||
NotificationsService notificationsservice;
|
||||
@@ -132,6 +136,8 @@ const char * NotificationsService::getTypeString()
|
||||
return "Email";
|
||||
case ESP_LINE_NOTIFICATION:
|
||||
return "Line";
|
||||
case ESP_IFTTT_NOTIFICATION:
|
||||
return "IFTTT";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -154,6 +160,9 @@ bool NotificationsService::sendMSG(const char * title, const char * message)
|
||||
case ESP_LINE_NOTIFICATION :
|
||||
return sendLineMSG(title,message);
|
||||
break;
|
||||
case ESP_IFTTT_NOTIFICATION :
|
||||
return sendIFTTTMSG(title,message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -189,6 +198,7 @@ bool NotificationsService::sendPushoverMSG(const char * title, const char * mess
|
||||
data += message;
|
||||
data += "&device=";
|
||||
data += wifi_config.get_hostname();
|
||||
|
||||
//build post query
|
||||
postcmd = "POST /1/messages.json HTTP/1.1\r\nHost: api.pushover.net\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
@@ -329,6 +339,47 @@ bool NotificationsService::sendLineMSG(const char * title, const char * message)
|
||||
Notificationclient.stop();
|
||||
return res;
|
||||
}
|
||||
//IFTTT
|
||||
bool NotificationsService::sendIFTTTMSG(const char * title, const char * message)
|
||||
{
|
||||
String data;
|
||||
String postcmd;
|
||||
bool res;
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
TSecureClient Notificationclient;
|
||||
#pragma GCC diagnostic pop
|
||||
#if defined(ARDUINO_ARCH_ESP8266) && !defined(USING_AXTLS)
|
||||
Notificationclient.setInsecure();
|
||||
#endif //ARDUINO_ARCH_ESP8266 && !USING_AXTLS
|
||||
if (!Notificationclient.connect(_serveraddress.c_str(), _port)) {
|
||||
//log_esp3d("Error connecting server %s:%d", _serveraddress.c_str(), _port);
|
||||
return false;
|
||||
}
|
||||
|
||||
//build data for post
|
||||
|
||||
data ="value1=";
|
||||
data += title;
|
||||
data += "&value2=";
|
||||
data += message;
|
||||
data += "&value3=";
|
||||
data += wifi_config.get_hostname();
|
||||
|
||||
//build post query
|
||||
postcmd = "POST /trigger/" + _token1 + "/with/key/" + _token2 + " HTTP/1.1\r\nHost: maker.ifttt.com\r\nConnection: close\r\nCache-Control: no-cache\r\nUser-Agent: ESP3D\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ";
|
||||
postcmd += data.length();
|
||||
postcmd +="\r\n\r\n";
|
||||
postcmd +=data;
|
||||
|
||||
//log_esp3d("Query: %s", postcmd.c_str());
|
||||
//send query
|
||||
Notificationclient.print(postcmd);
|
||||
res = Wait4Answer(Notificationclient, "Congratulations", "Congratulations", IFTTTTIMEOUT);
|
||||
Notificationclient.stop();
|
||||
return res;
|
||||
}
|
||||
|
||||
//Email#serveraddress:port
|
||||
bool NotificationsService::getPortFromSettings()
|
||||
{
|
||||
@@ -386,7 +437,6 @@ bool NotificationsService::getEmailFromSettings()
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool NotificationsService::begin()
|
||||
{
|
||||
bool res = true;
|
||||
@@ -416,6 +466,17 @@ bool NotificationsService::begin()
|
||||
_port = LINEPORT;
|
||||
_serveraddress = LINESERVER;
|
||||
break;
|
||||
case ESP_IFTTT_NOTIFICATION:
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||
_token1 = sbuf;
|
||||
}
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN2, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||
_token2 = sbuf;
|
||||
}
|
||||
_port = IFTTTPORT;
|
||||
_serveraddress = IFTTTSERVER;
|
||||
break;
|
||||
|
||||
case ESP_EMAIL_NOTIFICATION:
|
||||
if (CONFIG::read_string (ESP_NOTIFICATION_TOKEN1, sbuf, MAX_NOTIFICATION_TOKEN_LENGTH) ) {
|
||||
_token1 = base64::encode(sbuf);
|
||||
@@ -462,4 +523,5 @@ void NotificationsService::handle()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif //NOTIFICATION_FEATURE
|
||||
|
||||
Reference in New Issue
Block a user