thanks for your reply @sandeepmistry ![]()
For information, here is another sketch with a custom PUT Implementation, without using ArduinoHttpClient library, as was done in the code linked in the previous message from my friend @Marcussacapuces91.
It seems that this custom implementation of PUT is working better, nevertheless, it is still freezing after a random number of request...
NOTE : I am using a LIPO 18650 1S3P 7800mAh
/* adapted from M. sibert May 2018 */
# define DEBUG(x) do { Serial.print(x); } while(0)
#include <MKRGSM.h>
#define PIN_CODE "0000"
#define APN_NAME "soracom.io"
#define APN_USERNAME "sora"
#define APN_PASSWORD "sora"
const String GPRS_APN(F(APN_NAME));
const String GPRS_LOGIN(F(APN_USERNAME));
const String GPRS_PASSWORD(F(APN_PASSWORD));
GSM gsm;
GPRS gprs;
GSMClient gprsClient;
bool put( String path, String body) {
DEBUG("PUT "); DEBUG(path); DEBUG('\n');
GSMClient client;
String serverName = "httpbin.org";
if (!client.connect(serverName.c_str(), 80)) {
Serial.println(F("Erreur de connexion"));
return false;
}
client.print(F("PUT ")); client.print(path); client.println(F(" HTTP/1.0"));
client.print(F("Host: ")); client.println(serverName.c_str());
client.println(F("Content-Type: application/json"));
client.print(F("Content-Length: ")); client.println(body.length());
client.println(F("Connection: close"));
client.println();
String t = body;
while(t.length() > 0) {
const unsigned m = (t.length() >= 100 ? 100 : t.length());
client.print(t.substring(0, m));
t = t.substring(m);
}
String s;
const unsigned long start = millis();
while ((client.available() || client.connected()) && (millis() - start) < 30000) {
if (client.available() > 0) {
const int c = client.read();
if (c != -1) s += char(c);
}
}
Serial.println(s);
return true;
}
void setup() {
Serial.begin(9600);
MODEM.begin();
if (GSM_READY != gsm.begin(PIN_CODE)) {
Serial.println("No GSM conection!");
}
if (GPRS_READY != gprs.attachGPRS(GPRS_APN.c_str(), GPRS_LOGIN.c_str(), GPRS_PASSWORD.c_str())) {
Serial.println("No GPRS connection!");
}
}
void loop() {
Serial.println("Making PUT request");
const String Path = "/put";
const String putData = "{ \"name\": \"light\", \"age\": 46 }";
put(Path, putData);
Serial.println("Wait five seconds");
delay(5000);
}