Moderator: igrr
#include <ESP8266WiFi.h>
const char* ssid = "";
const char* password = "";
const char* host = "xxxxxxxx.com";
int ledPinWifiConnect = 13;
int porta = 80;
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPinWifiConnect, OUTPUT);
//Conectando Com o Wifi
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client;
// se tem conexão com a internet led azul aceso
if(WiFi.status() == WL_CONNECTED){
digitalWrite(ledPinWifiConnect,HIGH);
}
else{
digitalWrite(ledPinWifiConnect,LOW);
}
delay(5000);
Serial.print("connecting to ");
Serial.println(host);
// Usando o WiFiCliente para criar uma conexao TCP
if (!client.connect(host,porta)) {
Serial.println("connection failed");
return;
}
// criando um URL para o request
String url = "/arduino.php?loja=12";
Serial.print("Requesting URL: ");
Serial.println(url);
// ENVIANDO O GET PARA O REQUEST
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Lendo todas as linhas da resposta e printando na Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
//client.setNoDelay(true);
Serial.println();
Serial.println("closing connection");
}
e tem a seguinte resposta :
Connecting to NIGELVIADO
..
WiFi connected
IP address:
192.168.0.109
connecting to xxxxxx.com
Requesting URL: /arduino.php?loja=12
HTTP/1.1 200 OK
Date: Mon, 07 Nov 2016 19:58:36 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.17
Access-Control-Allow-Origin: *
Content-Length: 282
Connection: close
Content-Type: application/json; charset=utf-8
{"post_recebido":[],"get_recebido":{"loja":"12"},"pedido":[{"codigo":0,"string":"--------------\nLanch\u00e3o Sem Fim--------------\n\nValor: R$ 45\nEndere\u00e7o: X\n"},{"codigo":1,"string":"--------------\nLanch\u00e3o Sem Fim--------------\n\nValor: R$ 50\nEndere\u00e7o: X\n"}]}
closing connection
connecting to xxxxx.com
connection failed
connecting to xxxxxxx.com
connection failed
connecting to xxxxxxx.com
connection failed
connecting to xxxxxxxxx.com
connection failed
connecting to xxxxx.com
connection failed
connecting to xxxxxxxxx.com
connection failed
connecting to xxxxxxxxxx.com
connection failed
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const char* ssid = "";
const char* password = "";
const char* host = "xxxxxxxx.com";
int ledPinWifiConnect = 13;
int porta = 80;
void setup() {
Serial.begin(115200);
delay(10);
pinMode(ledPinWifiConnect, OUTPUT);
//Conectando Com o Wifi
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client;
// se tem conexão com a internet led azul aceso
if(WiFi.status() == WL_CONNECTED){
digitalWrite(ledPinWifiConnect,HIGH);
}
else{
digitalWrite(ledPinWifiConnect,LOW);
}
delay(5000);
Serial.print("connecting to ");
Serial.println(host);
// Usando o WiFiCliente para criar uma conexao TCP
if (!client.connect(host,porta)) {
Serial.println("connection failed");
return;
}
// criando um URL para o request
String url = "/arduino.php?loja=12";
Serial.print("Requesting URL: ");
Serial.println(url);
// ENVIANDO O GET PARA O REQUEST
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Lendo todas as linhas da resposta e printando na Serial
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
}
//client.setNoDelay(true);
Serial.println();
Serial.println("closing connection");
}
SERIAL :
Connecting to NIGELVIADO
..
WiFi connected
IP address:
192.168.0.109
connecting to xxxxx.com
Requesting URL: /arduino.php?loja=12
HTTP/1.1 200 OK
Date: Mon, 07 Nov 2016 19:58:36 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.17
Access-Control-Allow-Origin: *
Content-Length: 282
Connection: close
Content-Type: application/json; charset=utf-8
{"post_recebido":[],"get_recebido":{"loja":"12"},"pedido":[{"codigo":0,"string":"--------------\nLanch\u00e3o Sem Fim--------------\n\nValor: R$ 45\nEndere\u00e7o: X\n"},{"codigo":1,"string":"--------------\nLanch\u00e3o Sem Fim--------------\n\nValor: R$ 50\nEndere\u00e7o: X\n"}]}
closing connection
connecting to
connection failed
connecting to
connection failed
connecting to
connection failed
connecting to
connection failed
connecting to
connection failed
connecting to
connection failed
connecting to
connection failed