I have this code that I have used for a while to post data from an Arduino/WiFiBee vr1 shield with some sensors to a server with some simple PHP POST file that saves it to a mysql db.
I changed the part where the POST gets made, over to a GET in order to send the data to thingspeak where i have some other data stores. This is the part where the data send fails. I can post the entire code but I believe this is where the issue is. The block labeled Send Request is what I changed from the previous working code. I commented out the encoded form because that is for POST only.
In the SM I get the following:
Main Al⸮⸮⸮⸮ɩHj
Sampling UV
The UV voltage value:1207.27 mV
UVIndex is:
1853.16Sampling MQ2
MQ2 Sensor_volt = 0.05
RS_ratio = 101.40
Rs/R0 = 1267.50printing co2...
255 134 1 150 72 0 0 0 155
32
Temperature: 32 CO2: 406
Free memory: 245
Already joined network
DeviceID: Wifly-WebClient2
Reporting to cloud...open thingspeak.com 80
Connected to thingspeak.comPosted successfully
It seems to post successfully but the data doesnt get posted.
void reportToCloud() {
data = "";
Serial.println("Reporting to cloud...");
if (wifly.available() > 0) {
char ch = wifly.read();
Serial.write(ch);
if (ch == '\n') {
/* add a carriage return */
Serial.write('\r');
}
}
if (wifly.open(site, 80)) {
Serial.print("Connected to ");
Serial.println(site);
// Set data to send
static char outstr1[15];
static char outstr2[15];
static char outstr3[15];
static char outstr4[15];
String dataString1 = dtostrf(uvindex, 8, 2, outstr1);
String dataString2 = dtostrf(mq2ratio, 8, 2, outstr2);
String dataString3 = dtostrf(CO2PPM, 8, 2, outstr3);
String dataString4 = dtostrf(temperature, 8, 2, outstr4);
data = String("uvindex=" + dataString1 + "&mq2=" + dataString2 + "&age=" + dataString3 + "&name=" + dataString4);
Serial.print(data); //name = temp && age = co2
//Reset all values
uvindex = 0;
mq2ratio = 0;
CO2PPM = 0;
temperature = 0;
/* Send the request */
String getData = "GET"+ HOST + "/update.json?api_key="+ API + "&"+ field3 +"="+ dataString4 +"&"+ field4 +"="+dataString3 + "HTTP/1.0";
Serial.println(getData);
/* Send the request */
wifly.println(getData);
wifly.println("Host: thingspeak.com"); // SERVER ADDRESS HERE TOO
//wifly.println("Content-Type: application/x-www-form-urlencoded" );
wifly.print("Content-Length: ");
wifly.println(data.length());
wifly.println();
wifly.print(data);
Serial.println("Posted successfully");
} else {
Serial.println(">>Failed to connect");
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
wifly.close();
}