Dear ALL
If I run the simple demo script from the thinger Homepage for GSM1400, Im able to connect the platform, but after a while or after 1-2 min I loose the connection again (see debuging serial monitor below).
It seems that system wanted to built up a connection again, than the serial monitoring is hanging
…
Using secure TLS/SSL connection: yes . It seems something is quite instable
…
This is a problem appears when the MKR tries to make a reconnection and it fails. I understand that Arduino’s developers have been working on it, so we’ll see if we can come up with a better solution.
Does the problem appear after upload a new sketch? or was exactly the same compilation and library versions? have you tried updating mkr libraries? or using an old one?
By the moment, the only way to solve it is detecting the disconnection and making a reset but I don’t know if this works well for your case, if you need to hold real time variables or similar. If you are interested on this, answer me and I will send you the source code to make this.
Unfortunately, after looking for the code for a while I wasn’t able to find it. However, it is not difficult to implement using the client listener structure explained by @alvarolb on this post
something like this:
#include <ThingerMKRGSM.h>
#define USERNAME "your_user_name"
#define DEVICE_ID "your_device_id"
#define DEVICE_CREDENTIAL "your_device_credential"
#define PIN_NUMBER "your_pin"
#define GPRS_APN "your_apn_name"
#define GPRS_LOGIN "your_gprs_login"
#define GPRS_PASSWORD "your_gprs_password"
class ClientListener : public ThingerMKRGSM{
public:
ClientListener(const char* user, const char* device, const char* device_credential) :
ThingerMKRGSM(user, device, device_credential){}
protected:
virtual void thinger_state_listener(THINGER_STATE state){
// call current implementation (debug)
ThingerMKRGSM::thinger_state_listener(state);
switch(state){
case NETWORK_CONNECTING:
break;
case NETWORK_CONNECTED:
break;
case NETWORK_CONNECT_ERROR:
//RESET THE PROCESSOR HERE
break;
case SOCKET_CONNECTING:
break;
case SOCKET_CONNECTED:
break;
case SOCKET_CONNECTION_ERROR:
break;
case SOCKET_DISCONNECTED:
break;
case SOCKET_TIMEOUT:
break;
case THINGER_AUTHENTICATING:
break;
case THINGER_AUTHENTICATED:
break;
case THINGER_AUTH_FAILED:
break;
case THINGER_STOP_REQUEST:
break;
}
}
};
ClientListener thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void setup() {
Serial.begin(115200);
// optional set pin number
thing.set_pin(PIN_NUMBER);
// set APN
thing.set_apn(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);
// set builtin led to output
pinMode(LED_BUILTIN, OUTPUT);
// pin control example over internet (i.e. turning on/off a light, a relay, etc)
thing["led"] << digitalPin(LED_BUILTIN);
// resource output example (i.e. reading a sensor value, a variable, etc)
thing["millis"] >> outputValue(millis());
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}
I’m sure that if you execute a reset command (or wire up a gpio to RST pin to make reset when digitalWrite(pin,1); ) It should reset the PCB just when the connection is closed, but maybe this will produce a lot of resets if the PCB is moving between different antennas.
Hello Jorge. I’m having the same problem as Markus with and MKR1500, can you send me the code of to solve the disconnecting issue.
Best Regards
I’ll be incredible if you could help me or guide me.
An updated code for the MKRNB1500 could be like this:
Note: This code reboot the device everytime the network connection fails, which may not be the best depending the use case. It is worth to check in the log where the device is hanging.
#define THINGER_SERIAL_DEBUG
#include <ThingerMKRNB.h>
#include <ThingerMKRNBOTA.h>
#include "arduino_secrets.h"
ThingerMKRNB thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
// OTA seems to not work if no reset button pressed
ThingerMKRNBOTA ota(thing);
void setup() {
// enable serial for debugging
Serial.begin(115200);
// optional set pin number
thing.set_pin(PIN_NUMBER);
// set APN
thing.set_apn(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);
// set builtin led to output
pinMode(LED_BUILTIN, OUTPUT);
// pin control example over internet (i.e. turning on/off a light, a relay, etc)
thing["led"] << digitalPin(LED_BUILTIN);
// resource output example (i.e. reading a sensor value, a variable, etc)
thing["time"] >> [&](pson& out){
out = thing.getNB().getTime();
};
thing.set_state_listener([](ThingerClient::THINGER_STATE state){
switch(state){
case ThingerClient::NETWORK_CONNECTING:
break;
case ThingerClient::NETWORK_CONNECTED:
break;
case ThingerClient::NETWORK_CONNECT_ERROR:
//RESET THE PROCESSOR HERE
thing.reboot();
break;
case ThingerClient::SOCKET_CONNECTING:
break;
case ThingerClient::SOCKET_CONNECTED:
break;
case ThingerClient::SOCKET_CONNECTION_ERROR:
break;
case ThingerClient::SOCKET_DISCONNECTED:
break;
case ThingerClient::SOCKET_TIMEOUT:
break;
case ThingerClient::THINGER_AUTHENTICATING:
break;
case ThingerClient::THINGER_AUTHENTICATED:
break;
case ThingerClient::THINGER_AUTH_FAILED:
break;
case ThingerClient::THINGER_STOP_REQUEST:
break;
}
});
// more details at http://docs.thinger.io/arduino/
}
void loop() {
thing.handle();
}