Actually did the job but caused more problems....the idea is that I am serializing some data from gps then I send it as Json to Api and this happens every 1 min. Now the first time I send it everything works ok after that nothing happens. It's like there is memory issue or something....
void loop() {
while (Serial2.available() > 0){
gps.encode(Serial2.read());
if (gps.location.isUpdated()){
float curr_latitude = gps.location.lat();
float curr_longitude = gps.location.lng();
float curr_altitude = gps.altitude.meters();
float curr_speed = gps.speed.kmph();
String result;
DynamicJsonDocument doc(200);
doc["latitude"] = curr_latitude;
doc["longitude"] = curr_longitude;
doc["altitude"] = curr_altitude;
doc["speed"] = curr_speed;
doc["deviceId"] = "867372057405818";
serializeJson(doc, result);
delay(2000);
// Making an HTTP POST request
SerialMon.println("Performing HTTP POST request...");
//Send the actual HTTP POST request to API
client.print(String("POST ") + "http://something/api" + " HTTP/1.1\r\n");
client.print(String("Host: ") + "http://something" + "\r\n");
client.println("Connection: close");
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(result.length());
client.println();
client.println(result);
unsigned long timeout = millis();
while (client.connected() && millis() - timeout < 10000L) {
// Print available data (HTTP response from server)-have to be 201 Created
while (client.available()) {
char c = client.read();
SerialMon.print(c);
timeout = millis();
}
}
SerialMon.println();
}
}
Actually although it's buggy the code works from time to time Problem is that I'm trying to combine 2 or 3 sources into one and there are most likely a lot of mistakes.... So I'll try to rewrite it tommorow and see what happens then and if I can solve it will ask for help in the forum again. Thanks for the help!