Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By martinayotte
#27203
Mmiscool wrote:I find it hard to belive that there is not an existing function to do this. :?:


I'm not following you. The code above is quite straight forward, it is following the HTTP specs.
If you wish to "wrap" it into a function,of course, it can be done, as long as it handle the failures and success.
User avatar
By Mmiscool
#27204 The domain name and the rest of the url mjst be seperated thoug.

The client.connect and the get are diferent portions of the j
Url?
Client connect. "Google.com"
Get "/search=blablabla"

Cant just be one string used both places. Requires them to be seporated?
User avatar
By martinayotte
#27205 Unfortunately, we can't change the HTTP protocol, which is not ESP related.
The code above was a simple example to follow.
It is up to you to write handy helper function for you project.
Personally, I don't see much complex stuff in the above code.
User avatar
By Mmiscool
#27207 I am getting a error when I try and compile the following:
Using the staging version

Code: Select all#include "spiffs/spiffs.h"
#include <FS.h>
//#include <ESP8266mDNS.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>



String FetchWebUrl(String URLtoGet)
{
  String str;
  String ServerToConnectTo;
  String PageToGet;
  ServerToConnectTo = URLtoGet.substring(0, URLtoGet.indexOf("/"));
  PageToGet = URLtoGet.substring(URLtoGet.indexOf("/"));

  Serial.println(ServerToConnectTo);
  Serial.println(PageToGet);

  WiFiClient client;
  if (client.connect(ServerToConnectTo , 80))
  {
    client.print("GET /?format=json HTTP/1.1\r\nHost: api.ipify.org\r\n\r\n");
    delay(100);
    str = "";
    while (client.available()) {
      str += client.read();
    }
    return str;
  }
}


Error:
Code: Select allESP8266_BASIC_INTERPERTERv2.ino: In function 'String FetchWebUrl(String)':
ESP8266_BASIC_INTERPERTERv2.ino:1660:44: error: no matching function for call to 'WiFiClient::connect(String&, int)'
ESP8266_BASIC_INTERPERTERv2.ino:1660:44: note: candidates are:
In file included from C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/ESP8266WiFi.h:32:0,
                 from ESP8266_BASIC_INTERPERTERv2.ino:28:
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/WiFiClient.h:45:15: note: virtual int WiFiClient::connect(IPAddress, uint16_t)
   virtual int connect(IPAddress ip, uint16_t port);
               ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/WiFiClient.h:45:15: note:   no known conversion for argument 1 from 'String' to 'IPAddress'
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/WiFiClient.h:46:15: note: virtual int WiFiClient::connect(const char*, uint16_t)
   virtual int connect(const char *host, uint16_t port);
               ^
C:\Users\user\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-1044-g170995a\libraries\ESP8266WiFi\src/WiFiClient.h:46:15: note:   no known conversion for argument 1 from 'String' to 'const char*'
no matching function for call to 'WiFiClient::connect(String&, int)'