I'm using a NodeMCU as a data logger, or at least trying to. When I try to upload data using a URL (with variables in the URL) I get a 301 error.
The error includes the correct URL which is identical to the one used. I output the URL used to serial, and if I copy it into a browser it works.
I feel like I'm missing something simple but I just can't see it. It's not https.
Here's the relevant bit of code (I've removed my domain):
void uploadValues() {
Serial.println("Uploading data to server...");
WiFiClient client;
HTTPClient http; //Declare object of class HTTPClient
String postData;
byte rain = map(analogRead(A0), 1024, 0, 0, 100);
//Post Data
postData = "http:// -={ MY DOMAIN }=- /shed/up.php?BMEtemp='" + String(bme.readTemperature(), 2);
postData += "'&humidity='" + String(bme.readHumidity(), 2);
postData += "'&INTtemp='" + String(sensors.getTempCByIndex(0), 2);
postData += "'&EXTtemp='" + String(sensors.getTempCByIndex(1), 2);
postData += "'&LASERtemp='0'";
postData += "&pressure='" + String(bme.readPressure() / 100.0F, 2);
postData += "'&RAINstatus='";
if (digitalRead(D6) == LOW) {
postData += "1";
} else {
postData += "0";
}
postData += "'&RAINvalue='" + String(rain) + "'";
http.begin(client, postData);
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end(); //Close connection
Serial.println("===================");
Serial.println(postData);
Serial.println("===================");
Serial.println(" ");
}