Hi, I'm trying to get arduino to work with ESP8266, where ESP8266 receives HTTP GET request, parses it into float and sends it to arduino over serial. It's working as I wanted when i connect ESP module to RS232 to usb converter (ESP prints received data to serial), but when i connect it to arduino and send an HTTP request "123", ESP prints it correctly, but arduino receives something like this:
-1
-1
-1
-1
-1
49
50
51
13
10
49
13
10
-1
-1
-1
I don't know what's going on, here's the code:
arduino:
#include <SoftwareSerial.h>
SoftwareSerial esp(5, 6);
int a;
void setup() {
Serial.begin(9600);
esp.begin(9600);
}
void loop () {
while(Serial.available()) {
a= esp.read();
Serial.print(a);
}
}
ESP8266:
#include <ESP8266WiFi.h>
const char* ssid = "ssid";
const char* password = "password";
int incomingByte;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
int num = 1;
void setup() {
Serial.begin(9600);
delay(10);
WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, password);
server.begin();
Serial.println("Server started");
}
void loop() {
WiFiClient client = server.available();
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 'H') {
num = WiFi.softAPgetStationNum();
Serial.println(num);
}
}
if (!client) {
return;
}
while (!client.available()) {
delay(1);
}
int req = client.parseFloat();
Serial.println(req);
client.flush();
// Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val) ? "high" : "low";
s += "</html>\n";
// Send the response to the client
client.print(s);
delay(1);
}