Telemetry modul with PC client
Posted: Fri Mar 27, 2015 3:38 am
Hello!
I made my own telemetry module for RC models, but i have a problem with developing a client software on PC. I tried do it in C# and aslo in Java, but in both case, when I try to get HTTP response, I get error like "Invalid http protocol" or something like this. So I think that something is with configuration of my ESP8266.
In browser it shows up in good way, but in Java or C# it don't work.
Firmware of my ESP is:
AT+GMR
0018000902-AI03
Can you please look at it?
I made my own telemetry module for RC models, but i have a problem with developing a client software on PC. I tried do it in C# and aslo in Java, but in both case, when I try to get HTTP response, I get error like "Invalid http protocol" or something like this. So I think that something is with configuration of my ESP8266.
In browser it shows up in good way, but in Java or C# it don't work.
Firmware of my ESP is:
AT+GMR
0018000902-AI03
Can you please look at it?
Code: Select all
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <SoftwareSerial.h>
Adafruit_BMP085 sensorBMP180;
SoftwareSerial esp(8,9);
float tempC;
float pressure;
float altitude;
float initAltitude;
float realAltitude;
byte responseCode;
void setup(){
Serial.begin(38400); //turn on serial monitor
esp.begin(38400);
sendCommand("AT+RST\r\n",2000); // reset module
sendCommand("AT+CWMODE=2\r\n",1000); // configure as access point
sendCommand("AT+CIFSR\r\n",1000); // get ip address
sendCommand("AT+CIPMUX=1\r\n",1000); // configure for multiple connections
sendCommand("AT+CIPSERVER=1,80\r\n",1000); // turn on server on port 80
sensorBMP180.begin(); //initialize
initAltitude = sensorBMP180.readAltitude();
}
void loop() {
tempC = sensorBMP180.readTemperature();
pressure = sensorBMP180.readPressure();
altitude = sensorBMP180.readAltitude();
realAltitude = altitude - initAltitude;
if(esp.available()){
if(esp.find("+IPD,")){
delay(2000);
int connectionId = esp.read()-48;
String dataToSend = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
dataToSend += "<telemetry-values>\n<temp>";
String sVar = String(tempC);
dataToSend += sVar;
dataToSend += "</temp>\n";
dataToSend += "<pressure>";
sVar = String(pressure/100);
dataToSend += sVar;
dataToSend += "</pressure>\n";
dataToSend+="<altitude>";
sVar = String(altitude);
dataToSend += sVar;
dataToSend += "</altitude>\n";
dataToSend+="<alt-above-ground>";
sVar = String(realAltitude);
dataToSend += sVar;
dataToSend += "</alt-above-ground>\n</telemetry-values>";
String cmdCIPSEND = "AT+CIPSEND=";
cmdCIPSEND += connectionId;
cmdCIPSEND += ",";
cmdCIPSEND +=dataToSend.length();
cmdCIPSEND +="\r\n";
sendCommand(cmdCIPSEND,2000);
sendCommand(dataToSend,2000);
String closeCommand = "AT+CIPCLOSE=";
closeCommand+=connectionId;
closeCommand+="\r\n";
sendCommand(closeCommand,3000);
}
}
}
String sendCommand(String command, const int timeout){
String response = "";
esp.print(command);
long int time = millis();
while( (time+timeout) > millis()){
while(esp.available()){
char c = esp.read();
response+=c;
}
}
Serial.print(response);
return response;
}