Trouble with ESP8266 + HTTP Request
Posted: Thu Aug 25, 2016 4:47 pm
Hi Guys!
I need a little help here.
My code doesn't work for receive Get Request from a Node.js hosted in my network.
Using this code below, they return on Receive random caracteres:
Recebi: v
Recebi: I
Recebi: v
Recebi: v
Recebi: 5
And my code in node.js is:
Whats i doing wrong? I think i need a other library for ESP, because AT Commands is so dumb.
Srry for the english
I need a little help here.
My code doesn't work for receive Get Request from a Node.js hosted in my network.
Using this code below, they return on Receive random caracteres:
Recebi: v
Recebi: I
Recebi: v
Recebi: v
Recebi: 5
And my code in node.js is:
Code: Select all
var express = require('express');
var app = express();
app.get('/teste', function(req, res) {
res.charset = 'UTF-8'
res.send('3');
});
var server = app.listen(3000, "192.168.0.108", function () {
var host = server.address().address;
var port = server.address().port;
console.log('Exemplo na URL http://%s:%s', host, port);
});
Code: Select all
#define SSID "ssid" //Insert your Wireless SSID Here
#define PASS "keypass" //Insert your Wireless Password Here
#define IP "192.168.0.108" // taurussystem.com
String GET = "GET /teste HTTP/1.0\r\n\r\n";
char resultado;
String conteudo = "";
void setup()
{
Serial1.begin(115200);
Serial.begin(9600);
sendDebug("AT");
delay(5000);
if (Serial1.find("OK"))
{
Serial.println("RECEIVED: OK");
connectWiFi();
}
}
void loop()
{
updateTaurus();
delay(4000);
}
void updateTaurus()
{
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += IP;
cmd += "\",3000";
sendDebug(cmd);
delay(2000);
if (Serial1.find("Error")) {
Serial.print("RECEIVED: Still Conected");
return;
}
cmd = GET;
cmd += "\r\n";
Serial1.print("AT+CIPSEND=");
Serial.print("AT+CIPSEND=");
Serial1.println(cmd.length());
Serial.println(cmd.length());
if (Serial1.find(">"))
{
Serial.print(">");
Serial.print(cmd);
Serial1.print(cmd);
} else {
sendDebug("AT+CIPCLOSE");
}
while (Serial1.available() > 0) {
resultado = Serial1.read();
conteudo += resultado;
delay(10);
}
Serial.print("Receive ");
Serial.println(resultado);
}
void sendDebug(String cmd)
{
Serial.print("SEND: ");
Serial.println(cmd);
Serial1.println(cmd);
}
boolean connectWiFi()
{
Serial1.println("AT+CIPMUX=0");
Serial1.println("AT+CWMODE=1");
delay(2000);
String cmd = "AT+CWJAP=\"";
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
sendDebug(cmd);
delay(5000);
if (Serial1.find("OK")) {
Serial.println("RECEIVED: OK");
return true;
} else {
Serial.println("RECEIVED: Error");
return false;
}
}
Whats i doing wrong? I think i need a other library for ESP, because AT Commands is so dumb.
Srry for the english