1

i'm working on an iot project with the ESP8266 wifi module. I've been able to successfully connect it to the internet and make an GET request to a html page using this tutorial provided by adafruit. but I seem to be having difficulties integrating it with the api endpoints that I have running on the google developer console.

Here's the potion of the code i'm having problems with

const char* Host = "www.my_app_id.appspot.com";
String PostData = "clientId=&fanId=&kueliiKey=";
String url = "/_ah/api/fan/v1/register?";
Serial.print("Requesting URL: ");
Serial.println(url);
//Connect to the client and make the api call
if (client.connect(Host, httpPort)) {
    client.println("POST " + url + " HTTP/1.1");
    client.println("Host: "+ (String)Host);
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(PostData.length());
    client.println();
    client.println(PostData);
    delay(500);
}
//Read all the lines of the reply from server and print them to Serial          
while (client.available()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
}

//Serial.println();
Serial.println("closing connection");

I'm able to connect but I keep on getting a 404 error

lloc\umm_malloc.c
HTTP/1.1 404 Not Found
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 22 Mar 2016 12:08:06 GMT
Vary: X-Origin
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Connection: close

Not Found
closing connection;

What I have in

String url = "/_ah/api/fan/v1/register?";

might be wrong, but I've double checked and using http://hurl.it and the api call works and returns what I want image of successful request any insight on this would be greatly appreciated.

Thanks.

Dolapo Toki
  • 362
  • 3
  • 13

1 Answers1

4

After a ton of tries i realized what was wrong and here's how i fixed it.

  1. I changed my url to https apparently endpoints highly favor https now

    www.my_app_id.appspot.com became https://my_app_id.appspot.com;

  2. Then i had to change my port to 443 and attach postdata to the calls with the POST header url path.

    client.println("POST " + url + " HTTP/1.1")->client.println("POST " + url + + Postdata +" HTTP/1.1");

  3. Finally i had to change from using WifiClient to WiFiClientSecure.

Hope this helps someone :)

Dolapo Toki
  • 362
  • 3
  • 13