Enthernet Code
DIIDevHeads IoT Integration Server
•Created by Enthernet Code on 7/4/2024 in #edge-networking
Troubleshooting HTTP POST Error on ESP32 with ADXL335 Accelerometer
Serial.println("Connected to WiFi");
}
void loop() {
// Read vibration sensor data
int xValue = analogRead(xPin);
int yValue = analogRead(yPin);
int zValue = analogRead(zPin);
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Specify content-type header
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare data for HTTP POST
String httpRequestData = "xValue=" + String(xValue) + "&yValue=" + String(yValue) + "&zValue=" + String(zValue);
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode); // Print return code
Serial.println(response); // Print response
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
} else {
Serial.println("Error in WiFi connection");
}
delay(10000); // Send a request every 10 seconds
}
Serial.println("Connected to WiFi");
}
void loop() {
// Read vibration sensor data
int xValue = analogRead(xPin);
int yValue = analogRead(yPin);
int zValue = analogRead(zPin);
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
// Specify content-type header
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare data for HTTP POST
String httpRequestData = "xValue=" + String(xValue) + "&yValue=" + String(yValue) + "&zValue=" + String(zValue);
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode); // Print return code
Serial.println(response); // Print response
} else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
} else {
Serial.println("Error in WiFi connection");
}
delay(10000); // Send a request every 10 seconds
}
6 replies