Unable to http post/get to thingspeak

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.16

Sampling MQ2
MQ2 Sensor_volt = 0.05
RS_ratio = 101.40
Rs/R0 = 1267.50

printing 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.com

Posted 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();
}

Try a space after the first quote. If that doesn’t help, compare your code very carefully with a known good example, say here: Arduino - HTTP Request | Arduino Tutorial

Edit:

Same here. A missing space

Ok so i made your suggested corrections and have been testing but even before getting to the actual HTTP post Im working on getting the string right. I started printing the string after building it and noticed it wasnt printing in the SM AT ALL. So I started debugging it and got this far:

String getData = "GET /update?api_key=15KW7SVKY7L97FSF&field3=44";//&field4=99";// HTTP/1.1";

where ive truncated it after the first data point because the moment I include &field4=99, i start getting that empty Serial.println(getData). And if that string is blank then the HTTP request will obviously fail.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.