Cytron ESP 8266 Shield HTTP GET
Posted:
Thu Nov 29, 2018 3:42 am
by jaden
ESP8266Client client;
client.connect("192.168.100.100", 5000, "/abc.php");
client.read();
client.stop();
my product does not have
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
the ESP8266Client does not have 3rd parameter
can anyone provide me example on how to GET"192.168.100:5000/abc.php"
please notice that i have already try out your examples.
Update--
my product does not have
#include <HTTPClient.h>
what i want is
HTTPClient http;
http.begin("192.168.100.100", 5000, "/abc.php");
http.GET();
http.end();
Re: Cytron ESP 8266 Shield HTTP GET
Posted:
Thu Nov 29, 2018 4:06 pm
by Idris
Hi jaden,
I'm not really familiar with HTTP. Anyway could you try this?
client.begin("192.168.100.100/abc.php", 5000);
Re: Cytron ESP 8266 Shield HTTP GET
Posted:
Thu Nov 29, 2018 6:11 pm
by jaden
it can't
the example cytron provide is...
if i going to 192.168.100.100:5000 it work
but i don't have example of 192.168.100.100:5000/abc.php
Re: Cytron ESP 8266 Shield HTTP GET
Posted:
Wed Jan 02, 2019 9:02 am
by Idris
Hi jaden,
I try to edit HTTPSClient example and fit your parameter inside.
Host: 192.168.100.100
Port: 5000
URL: "abc.php"
Please try. Hope this helps, thanks.
- CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
const char* ssid = "YourWiFiSSID";
const char* pass = "YourWiFiPassword";
const char* host = "192.168.100.100";
const int port = 5000;
void setup()
{
Serial.begin(9600);
while (!Serial);
if (!wifi.begin(2, 3)) {
Serial.println(F("Error talking to shield"));
}
Serial.println(F("Start wifi connection"));
if (!wifi.connectAP(ssid, pass)) {
Serial.println(F("Error connecting to WiFi"));
}
Serial.print(F("Connected to: ")); Serial.println(wifi.SSID());
Serial.print(F("IP address: ")); Serial.println(wifi.localIP());
ESP8266Client client;
Serial.print("Connecting to ");
Serial.println(host);
if (!client.secure_connect(host, port)) {
Serial.println(F("Failed to connect to server."));
client.stop();
return;
}
String url = "/abc.php";
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
//set 5 seconds timeout for response from server
int i = 5000;
while (client.available() <= 0 && i--) {
delay(1);
if (i == 1) {
Serial.println(F("Timeout"));
client.stop();
return;
}
}
if (client.available()) {
if (client.find("\r\n\r\n")) {
Serial.println(F("headers received"));
}
String line = client.readStringUntil('\n');
if (line.startsWith("{\"state\":\"success\"")) {
Serial.println(F("esp8266/Arduino CI successfull!"));
}
else {
Serial.println(F("esp8266/Arduino CI has failed"));
}
Serial.println(F("reply was:"));
Serial.println(F("=========="));
Serial.println(line);
Serial.println(F("=========="));
Serial.println(F("closing connection"));
//flush the rest of received data
while (client.available() > 0) {
client.flush();
}
}
client.stop();
}
void loop()
{
}