Hi guys. Huge newbie here. I am trying to insert string variables into a http.POST. My example script is below. My goal is to be able to randomly select a string variable and insert it into the POST message content. For the life of me I can work out how to make it work. I know that IFTTT requires the use of quotes to idenify the variables, I suspect this may be the issue. Could someone please point me in the right direction?
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>// -----------------------------------------------
// -----------------------------------------------const char *wifi_ssid = "Wifi";
const char *wifi_pass = "password";
String stringOne = "value1";
String stringTwo = "value2";// -----------------------------------------------
// -----------------------------------------------const char *ifttt_url = "some URL";
BearSSL::WiFiClientSecure client;
void setup() {
connectToWiFi(wifi_ssid, wifi_pass);
Serial.println(insult);
sendNotification();
Serial.println("Goodnight!");
ESP.deepSleep(0);
}void loop() {}
// =========================================================
// =========================================================void connectToWiFi(const char * ssid, const char * pass){
Serial.begin(115200);
WiFi.begin(ssid,pass);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("Connected!");
Serial.printf("Network: %s\n", wifi_ssid);
Serial.printf("IP: %s\n", WiFi.localIP().toString().c_str());
client.setInsecure();
}void sendNotification()
{
// should only be called when wanting to send a notification
HTTPClient http;
http.begin(client, ifttt_url);
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST("{stringOne:stringTwo}");
int r = http.GET();if (r < 0)
{
Serial.println(http.errorToString(r));
}
else
{
http.writeToStream(&Serial);
Serial.println();
}
http.end();
}