Insert string into webhook POST

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();
}

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

Please remove all > that indicate a blockquote.

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