-->
Page 1 of 3

Client.print to POST request to web URL fails

PostPosted: Mon Jan 25, 2016 5:25 pm
by DaniloFix
Hi

I have a ESP8266 connected to my network and serving a webpage. That part is working just fine.
I want to add a function: void sendMessage() that will post to ifttt.com but I can't get it working right.

I tried this:

Code: Select all    WiFiClient Client;

    // IFTTT message setting
    String ifttt_url = "/trigger/temperatur_for_lav/with/key/d7i**********lThq2DB2i";
    String ifttt_host = "maker.ifttt.com";
   
    sensors.requestTemperatures(); // Send the command to get temperatures
   
    sensor1_temp = sensors.getTempCByIndex(0);
 
    if ( sensor1_temp > 28 ) {
      Client.print(String("POST ") + ifttt_url + "&headers=false" + " HTTP/1.1\r\n" + "Host: " + ifttt_host + "\r\n" + "Connection: close\r\n\r\n");
    }


But it doesn't work... the IFTTT recipe is not being triggered.
Any help is appreciated.

Thanks

Re: Client.print to POST request to web URL fails

PostPosted: Mon Jan 25, 2016 5:35 pm
by martinayotte
At which position (line/column) ?

Re: Client.print to POST request to web URL fails

PostPosted: Mon Jan 25, 2016 5:38 pm
by DaniloFix
martinayotte wrote:At which position (line/column) ?

I've just edited my post - was missing WiFiClient Client; in my function. Now it compiles, but ifttt recipe is not being triggered. Not sure why

Re: Client.print to POST request to web URL fails

PostPosted: Mon Jan 25, 2016 5:41 pm
by DaniloFix
If I print to serial the code I'm trying to execute through Client.print, I get this:

Code: Select allPOST /trigger/temperatur_for_lav/with/key/d7i62**********hq2DB2i&headers=false HTTP/1.1
Host: maker.ifttt.com
Connection: close