-
-
Save Marcussacapuces91/a8ec89a932eee359ac741e0ade9078ea to your computer and use it in GitHub Desktop.
Bug MKRGSM 1400 Hang after a few PUTs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#define PIN_CODE "0000" | |
#define APN_NAME "soracom.io" | |
#define APN_USERNAME "sora" | |
#define APN_PASSWORD "sora" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Simple PUT client for ArduinoHttpClient library | |
Connects to server once every five seconds, sends a PUT request | |
and a request body | |
created 14 Feb 2016 | |
by Tom Igoe | |
update by M. Sibert May 2018 | |
this example is in the public domain | |
*/ | |
#include <MKRGSM.h> | |
#include <ArduinoHttpClient.h> | |
#include "arduino_secrets.h" | |
const String serverName(F("httpbin.org")); | |
const unsigned serverPort = 80; | |
const String servicePath(F("/put")); | |
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; | |
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!"); | |
} | |
/* | |
if (!gprsClient.connect(serverName.c_str(), serverPort)) { | |
Serial.println("No TCP connection!"); | |
} | |
Serial.println("No TCP connection!"); | |
*/ | |
} | |
void loop() { | |
HttpClient client = HttpClient(gprsClient, serverName, serverPort); | |
Serial.println("Making PUT request"); | |
const String contentType = "application/json"; | |
const String putData = "{ \"name\": \"light\", \"age\": 46 }"; | |
client.put(servicePath.c_str(), contentType, putData); | |
// read the status code and body of the response | |
const int statusCode = client.responseStatusCode(); | |
const String response = client.responseBody(); | |
Serial.print("Status code: "); | |
Serial.println(statusCode); | |
Serial.print("Response: "); | |
Serial.println(response); | |
Serial.println("Wait five seconds"); | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment