Cytron ESP 8266 Shield HTTP GET

Bluetooth, XBee, RF......

Cytron ESP 8266 Shield HTTP GET

Postby jaden » Thu Nov 29, 2018 3:42 am

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();
jaden
Greenhorn
 
Posts: 2
Joined: Wed Nov 28, 2018 10:31 pm

Re: Cytron ESP 8266 Shield HTTP GET

Postby Idris » Thu Nov 29, 2018 4:06 pm

Hi jaden,

I'm not really familiar with HTTP. Anyway could you try this?

client.begin("192.168.100.100/abc.php", 5000);
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang

Re: Cytron ESP 8266 Shield HTTP GET

Postby jaden » Thu Nov 29, 2018 6:11 pm

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
jaden
Greenhorn
 
Posts: 2
Joined: Wed Nov 28, 2018 10:31 pm

Re: Cytron ESP 8266 Shield HTTP GET

Postby Idris » Wed Jan 02, 2019 9:02 am

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()
{

}
Cytron Technologies invest time and resources providing tutorial, training and support for STEM education and maker movement. We need your support by purchasing products from Cytron Technologies. Thanks.
http://www.cytron.com.my
User avatar
Idris
Moderator
 
Posts: 409
Joined: Thu Mar 22, 2012 5:28 pm
Location: Pulau Pinang


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 22 guests

cron