Hello, so i'm new to arduino and trying to build a code on arduino cloud, i have encounter a problem with time in the arduino cloud, i can't get the right gmt ouput ( i'm stuck with gtm0, i want -3 gtm), the time part seem to work on arduino ide tho, if someone can help me troubleshoot it
#include "thingProperties.h"
#include <WiFi.h>
#include "time.h"
#include <Servo.h>
#include <math.h>
const char* ssid =
const char* password =
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec =-3*3600;
const int daylightOffset_sec = 0;
static int activationHour = 0;
static int activationMin= 0;
static int weekendHour = 0;
static int weekendMin = 0;
static bool buttonActivated = false;
static const int servoPin = 13;
Servo servo1;
void setup(){
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Connect to Wi-Fi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
// Init and get the time
configTime(-3*3600,0,"pool.ntp.org");
printLocalTime();
makehour();
// 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();
}
void loop(){
ArduinoCloud.update();
// Your code here
delay(1000);
printLocalTime();
}
void printLocalTime(){
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
int currentHour = timeinfo.tm_hour;
int currentMin = timeinfo.tm_min;
int currentDay = timeinfo.tm_wday;
int currentSec = timeinfo.tm_sec;
// Vérifier si l'heure actuelle correspond à l'heure d'activation du servo-moteur
if (currentHour == activationHour && currentMin == activationMin && currentSec <=5 && currentDay != 5) {
activateServo();
} else if (currentDay == 6 && weekendHour == currentHour && weekendMin == currentMin) {
activateServo();
}
// Autres tâches à effectuer dans la boucle loop()
}
void makehour() {
static double x1 = week/100;
double entierweek;
double decimalweek = modf(x1, &entierweek);
static double x2 = weekend/100;
double entierweekend;
double decimalweekend = modf(x2, &entierweekend);
activationHour = entierweek;
activationMin = decimalweek * 100;
weekendHour = entierweekend;
weekendMin = decimalweekend * 100;
}
void activateServo() {
// Code pour activer le servo-moteur à l'heure souhaitée
for (int posDegrees = 0; posDegrees <= 180; posDegrees++) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
for (int posDegrees = 180; posDegrees >= 0; posDegrees--) {
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
delay(4000); // Pause de 4 secondes
}
void onSwitchonChange() {
if (!buttonActivated) {
buttonActivated = true;
activateManual();
}else if(buttonActivated){
// Réinitialiser la variable buttonActivated après l'activation
buttonActivated = false;}
}
void onSwitchoffChange() {
if (!buttonActivated) {
buttonActivated = true;
activateManual1();
}else if(buttonActivated){
// Réinitialiser la variable buttonActivated après l'activation
buttonActivated = false;}
}
void activateManual() {
for (int posDegrees = 0; posDegrees <= 180; posDegrees++)
{
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
delay(4000); // Pause de 4 secondes lorsque le servo atteint 180 degrés
for (int posDegrees = 180; posDegrees >= 0; posDegrees--)
{
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
}
void activateManual1() {
for (int posDegrees = 0; posDegrees <= 180; posDegrees++)
{
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
delay(8000); // Pause de 4 secondes lorsque le servo atteint 180 degrés
for (int posDegrees = 180; posDegrees >= 0; posDegrees--)
{
servo1.write(posDegrees);
Serial.println(posDegrees);
delay(20);
}
// Réinitialiser la variable buttonActivated après l'activation
}
void onWeekChange() {
makehour();
}
void onWeekendChange() {
makehour();
}
/*
Since Currenthour is READ_WRITE variable, onCurrenthourChange() is
executed every time a new value is received from IoT Cloud.
*/
`