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

Moderator: igrr

User avatar
By LOLotavio
#57774 Hi everyone, sorry my bad English, I'm using a ESP8266 NodeMcu Esp-12E to receive a JSON a website, I can connect to wifi and stay connected on it, but I can connect to my server only one time after compiling the code (I am using the arduino IDE and I'm not programming in LUA) after connecting the first time the server and receive JSON and can no longer connect to the server. You have no idea what might be happening? I thank you,Otávio.
User avatar
By LOLotavio
#57786 Thanks for the quick response . I put my code below and what appears on the serial port :

#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
User avatar
By LOLotavio
#57787 Thanks for the quick response . I put my code below and what appears on the serial port

#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