Hello,
I'm quite a beginner in Arduino, but I successfully establish a IoTCloud connection to send temperature datas from a MKR GSM 1400 board.
But in order to limit the amount of data sent during a day (since my SIM card data plan is not unlimited ! ), I would like to upgrade my sketch in order to make periodically connections/disconnections to the IoTCloud, let's say every 15min for example. And between 2 connections I would like the GSM modem to be off, in order to be sure that no data will be send/receive.
Does exist a function or example that would allow me to turn off the modem or the IoTCloud connection periodically ?
I have no power save issue in my application, so the deepsleep mode is not mandatory for me.
Thanks for your help !
Antoine
Currently my code is:
/*
Sketch generated by the Arduino IoT Cloud Thing "AIM2"
https://create.arduino.cc/cloud/things/be5ccee4-7416-421a-8f41-838939f15397
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudElectricCurrent amp;
CloudTemperatureSensor temp;
bool led2;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// Example creating a thermocouple instance with hardware SPI on a given CS pin.
#define MAXCS 4
Adafruit_MAX31855 thermocouple(MAXCS);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// wait for MAX chip to stabilize
delay(10000); // On attend que la connexion au cloud soit Ă©tablie avant de lancer les acquisitions
Serial.print("Initializing temperature sensor...");
if (!thermocouple.begin()) {
Serial.println("ERROR temperature sensor.");
while (1) delay(10);
}
Serial.println("DONE temperature sensor.");
}
void loop() {
ArduinoCloud.update();
// Your code here
sensors_get_data();
delay(100);
}
void sensors_get_data() {
// Température (MAX 31855)
double c = thermocouple.readCelsius();
if (isnan(c)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.print("C = ");
Serial.println(c);
}
temp = c;
// Courant (ACS712 30A)
float SensorRead = analogRead(A1)*(3.3 / 1023.0); //We read the sensor output
SensorRead = SensorRead*1.36; // Prise en compte du pont diviseur sur la sortie
float Current = (SensorRead-2.5)/0.066; //Calculate the current value
Serial.print("Current: ");
Serial.println(Current,3);
amp = Current;
}
/*
Since Led2 is READ_WRITE variable, onLed2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed2Change() {
// Add your code here to act upon Led2 change
Serial.print("led2: " + led2);
digitalWrite(LED_BUILTIN, led2);
}