Last active
April 15, 2017 21:50
-
-
Save reginaldojunior/2e6a377784db8fe7c5bf74621c03b2e9 to your computer and use it in GitHub Desktop.
teste1.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ESP8266 e Banco de Dados - Requisições HTTP | |
* 2016 por José Cintra | |
* www.josecintra.com/blog | |
*/ | |
#include <ESP8266WiFi.h> | |
#include <WiFiClient.h> | |
// WiFi - Coloque aqui suas configurações de WI-FI | |
const char ssid[] = "dlink - palestra"; | |
const char psw[] = "445926156"; | |
// Site remoto - Coloque aqui os dados do site que vai receber a requisição GET | |
const char http_site[] = "http://api.trackcar.ciawn.com.br"; | |
const int http_port = 8080; | |
// Variáveis globais | |
WiFiClient client; | |
IPAddress server(192, 168, 0, 100); //Endereço IP do servidor - http_site | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("NodeMCU - Gravando dadios no BD via GET"); | |
Serial.println("Aguardando conexão"); | |
// Tenta conexão com Wi-fi | |
WiFi.begin(ssid, psw); | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay(100); | |
Serial.print("."); | |
} | |
Serial.print("\nWI-FI conectado com sucesso: "); | |
Serial.println(ssid); | |
} | |
void loop() { | |
Serial.println("Before GetPage()"); | |
getPage(); | |
Serial.println("After GetPage()"); | |
} | |
// Executa o HTTP GET request no site remoto | |
bool getPage() { | |
Serial.println("In GetPage()"); | |
//http://api.trackcar.ciawn.com.br/lat/314534564564/log/654564564564/user/1 | |
//String param = "/?temp=" + String(temp) + "&humid=" + String(humid); //Parâmetros com as leituras | |
//Serial.println(param); | |
client.println("GET /lat/314534564564/log/654564564564/user/1 HTTP/1.1"); | |
client.println("Host: "); | |
client.println(http_site); | |
client.println("Connection: close"); | |
client.println(); | |
client.println(); | |
Serial.println("==============="); | |
Serial.println(client.available()); | |
String line = client.readStringUntil('\r'); | |
Serial.print(line); | |
Serial.println("==============="); | |
// Informações de retorno do servidor para debug | |
while(client.available()){ | |
Serial.println("In While Call GetPage()"); | |
String line = client.readStringUntil('\r'); | |
Serial.print(line); | |
} | |
Serial.println("Sucess GetPage()"); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment