Hi everyone, sorry i need your help to solve my problem that am facing, i need to transfer data to the webserver using arduino mega 2560 and sim800l but i failed to manage it i don't know where might be the problem. Below is the code...
const char* server = "196.41.60.218";
const int port = 80;
// Sensor values
float volume = 1993.97;
float percentage = 67.58;
float water_height = 4.10;
float lat_val = -6.874645;
float lng_val = 39.465464;
// Device ID
String deviceID = "123456789";
void setup() {
Serial.begin(9600);
Serial3.begin(9600); // SIM800L connected to Serial3
delay(5000); // Give SIM800L module time to start
Serial3.print("AT\r\n");
delay(2000);
Serial3.print("AT+CMGF=1\r\n");
delay(2000);
}
void loop() {
// Create the JSON payload with the sensor data and device ID
String payload = "{";
payload += "\"deviceID\":\"" + deviceID + "\",";
payload += "\"Volume\":" + String(volume) + ",";
payload += "\"percentage\":" + String(percentage) + ",";
payload += "\"height\":" + String(water_height) + ",";
payload += "\"Latitude\":" + String(lat_val, 6) + ",";
payload += "\"Longitude\":" + String(lng_val, 6);
payload += "}";
// Establish a TCP connection
Serial3.println("AT+CIPSTART=\"TCP\",\"" + String(server) + "\"," + String(port));
if (Serial3.find("OK")) {
Serial.println("TCP connection established.");
// Send the HTTP POST request
String postRequest = "POST /twlms/data2.php HTTP/1.1\r\n";
postRequest += "Host: " + String(server) + "\r\n";
postRequest += "Content-Type: application/json\r\n";
postRequest += "Content-Length: " + String(payload.length()) + "\r\n\r\n";
postRequest += payload;
Serial3.print("AT+CIPSEND=");
Serial3.println(postRequest.length());
delay(1000);
Serial3.println(postRequest);
delay(2000); // Wait for the server response
// Read and print the server response
while (Serial3.available()) {
char response = Serial3.read();
Serial.print(response);
}
Serial3.println("AT+CIPCLOSE");
Serial.println("TCP connection closed.");
}
delay(5000); // Delay between each data transmission
}
that's why i came here to need some helps from the people including you, so if you know where might the problem in that code please correct it please..
What can you look at on that server to determine if the data is getting transmitted to it ?
Is the Apache web server running on it . If not, what web server ?
There will be web server log files which should show the transmission attempts you are making from your sim800l/Mega and these are important for trouble shooting.
but this code is working fine with that server, the only problem is it has too much delays which is not fine when you want the arduino to perform multple tasts at the same time