Closed eduardcabanas closed 6 years ago
HI, Any news from this issue? I have my units out of service due this problem thnk's
Hi @eduardcabanas, i had try your sketch it works, i have removed the stop condition in the for in setup:(while(true)), i have also imposed in the in the loop() this condition:
if (gsmAccess.begin() == GSM_READY && gprsAccess.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY) {
because if you call thegsmAccess.shutdown();
you have also to reconnect the module to the GSM network, for stop the connection you have to manage the problem from sketch, what you do in the loop() function, is repeated as if is in a while(true) loop, then you could simply impose if the module are not able to connect in 'n' tentative it stop to work and go in loop or imposing a condition that inhibit , the condition.
about the
+CREG: 0,0```
for the MKR GSM have you a battery pack connected to the board?
Maybe we need a timeout mechanism for the connection?
I'm not too keen to set a default timeout, as sometimes the modem can takes minutes to track a signal.
Maybe a new API like GSMAccess::setConnectionTimeout(long timeout)
, where timeout is a value in milliseconds, and -1 (which is the default) = no timeout.
Hi @sandeepmistry , I like the approach of GSMAccess::setConnectionTimeout(long timeout). Let me know if I could help.
@sandeepmistry yes i think that could be a good solution
@eduardcabanas @FrancMunoz @Rocketct there's a pull request for the set timeout API in https://github.com/arduino-libraries/MKRGSM/pull/53 - feedback welcome :)
@sandeepmistry tested the PR https://github.com/arduino-libraries/MKRGSM/pull/53, unplugging the antenna and setting the timeoput, the changes works fine, the software wait the timeout and after turn back on the loop function in the sketch, now i have to rewrite the sketch of @eduardcabanas and test with it
tested also with the @eduardcabanas sketch, i have add the setTimeout before the gsm begin and it works, the sketch is the following:
#include <MKRGSM.h>
#include <ArduinoHttpClient.h>
const char PINNUMBER[] = "";
const char GPRS_APN[] = "APN";
const char GPRS_LOGIN[] = "";
const char GPRS_PASSWORD[] = "";
const char* device_secret_key = "*********************";
GSMClient client;
GPRS gprsAccess;
GSM gsmAccess(true);
// Thebluedots API parameters
char server[] = "****";
char path[] = "***";
int port = 80;
HttpClient httpClient = HttpClient(client, server, port);
String response = "";
String okmsg = "ok";
String errormsg = "error";
void setup() {
delay(3000);
Serial.begin(115200);
int i;
//setted a timeout of 180 s for the GPRS and GSM operation
gprsAccess.setTimeout(180000);
gsmAccess.setTimeout(180000);
for (i = 0; i < 5; i++) {
Serial.print("Connecting GSM network...");
if ((gsmAccess.begin() != GSM_READY) &&
(gprsAccess.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) != GPRS_READY)) {
Serial.println(errormsg);
Serial.println(i);
} else {
Serial.println(okmsg);
break;
}
delay(1000);
if (gsmAccess.status() != GSM_READY) {
while (true);
}
}
}
void loop() {
Serial.print("Connecting GSM network...");
if (Serial) Serial.println("Attaching to GPRS with your APN...");
if ((gsmAccess.begin() != GSM_READY) &&
(gprsAccess.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) != GPRS_READY)) {
if (Serial) {
Serial.println(errormsg);
}
gsmAccess.shutdown();
} else {
if (Serial) {
Serial.println(okmsg);
}
float h = 80.88;
float t;
t = 25.80;
String PostData = "{\"Temperature\":" + String(t) + ",\"Humidity\":" + String(h) + "}";
if (Serial) Serial.print("Connecting and sending POST request to THEBLUEDOTS.io...");
int res_connect;
res_connect = client.connect(server, port);
if (res_connect) {
httpClient.beginRequest();
httpClient.post(path);
httpClient.sendHeader("Content-Type", "application/json");
httpClient.sendHeader("Authorization", "Bearer " + String(device_secret_key));
httpClient.beginBody();
httpClient.print(PostData);
httpClient.endRequest();
if (Serial) Serial.println(okmsg);
if (Serial) Serial.print("Receiving response...");
boolean test = true;
while (test) {
if (client.available()) {
char c = client.read();
if (Serial) Serial.print(c);
}
if (!client.connected()) {
if (Serial) Serial.println("Shuttign down GSM connection: disconnected");
client.stop();
test = false;
}
}
} else {
if (Serial) Serial.println(errormsg);
}
}
gsmAccess.shutdown();
Serial.println("sleeping");
delay(60000);
}
void dummy() {
volatile int aaa = 0;
Nice!!!
Closing in favour of https://github.com/arduino-libraries/MKRGSM/pull/53
Closing in favour of https://github.com/arduino-libraries/MKRGSM/pull/53
Hi,
I'm using the following sketch to send some info to my server. I would like to put the arduino in sleep mode after sending data to save battery (not implemented in the current sketch) If everything goes ok, no problem but the problem comes when for example the antenna is broken (the unit is outside). When the GSM access(if (gsmAccess.begin() != GSM_READY) {) wants to connect due the antenna is broken there is no possibility to connect because the Arduino is trying and trying to connect forever.
How could I stop the connection? this is the response
Thank you very much for your help I'm really stuck with this issue