Hi
I'm Triying to sleep the MKR but I did not reach it.
After sending the info (that we received perfect) the unit did not go to sleep. I used the same routine in a Sigfox MKRFOX but did not work in gsm
Could somebody help to me?
Thank's
///////////////////////////////////////////////////////////////Libraries definition//////////////////////////////////////////////////////
#include <ArduinoLowPower.h>
#include <ArduinoHttpClient.h>
#include <MKRGSM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ArduinoJson.h>
int rebootTime = 15;
float BatteryLevel = 0;
///////////////////////////////////////////////////////////////PIN definition//////////////////////////////////////////////////////
//Define Pin for Dallas sensors
OneWire ourWire1(6); //Se establece el pin 6 como bus OneWire
//OneWire ourWire2(7); //Se establece el pin 7 como bus OneWire
DallasTemperature dallas1(&ourWire1); //Se declara una variable u objeto para nuestro sensor1
//DallasTemperature dallas2(&ourWire2); //Se declara una variable u objeto para nuestro sensor2
// PIN Number
const char PINNUMBER[] = ""; //blank if no pin
// APN data: check settings on mobile for sim provider or contact carrier for network settings
const char GPRS_APN[] = "internet.easym2m.eu";
const char GPRS_LOGIN[] = "";
const char GPRS_PASSWORD[] = "";
// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "*************";
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// Wia API parameters
char server[] = "***********.io";
char path[] = "/api/v2/gprs";
int port = ********;
StaticJsonBuffer<512> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject& root = jsonBuffer.createObject();
String response;
int statusCode = 0;
String dataStr;
void setup() {
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
///////////////////GSM CONNECTION STATE///////////////////////////
Serial.println("Starting GSM connection to Wia!.");
// connection state
boolean connected = false;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (!connected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
///////////////////////////////////////////////////////////////Initzializating libraries//////////////////////////////////////////////////////
//**************Dallas sensors**************
dallas1.begin(); //Se inicia el sensor temperatura tierra 1
delay(500);
//**************Wire**************
Wire.begin();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////Reading Dallas temperature///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
dallas1.requestTemperatures(); //Se envía el comando para leer la temperatura
float captemp21 = (dallas1.getTempCByIndex(0)) * 10; //Se obtiene la temperatura en ºC del sensor 1
int8_t captemp21_trans = convertoFloatToInt8(captemp21 * 1.f, MAX_CAP_TEMP, MIN_CAP_TEMP);
// dallas2.requestTemperatures(); //Se envía el comando para leer la temperatura
// float tempfrozen= dallas2.getTempCByIndex(0); //Se obtiene la temperatura en ºC del sensor 2
delay(500);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////GSM SENDING MESSAGE///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
root["name40"] = "40";
root["data40"] = captemp21;
postToTBD(root);
///////////////////////////////////////////////////////////////POWER OFF////////////////////////////////////////////////////////////////////////////////////
Serial.println("power off");
digitalWrite(7, LOW);
//delay(300);
Serial.println("sleeping");
//Sleep for 15 minutes
LowPower.sleep(3 * 60 * 1000);
Serial.println("sleeping out");
}
void reboot() {
NVIC_SystemReset();
while (1) ;
}
void postToTBD(JsonObject& data) {
data.printTo(dataStr);
httpClient.beginRequest();
httpClient.post(path);
httpClient.sendHeader("Content-Type", "application/json");
httpClient.sendHeader("Content-Length", data.measureLength());
httpClient.sendHeader("Authorization", "Bearer " + String(device_secret_key));
httpClient.beginBody();
httpClient.print(dataStr);
httpClient.endRequest();
}
void dummy() {
volatile int aaa = 0;
}