Buongiorno a tutti,attualmente ho vari nodemcu installati nella mia abitazione, e su quasi tutti ho installato la funzionalità ntp, vorrei centralizzarla su un unico node e poi da questo inviare comandi centralizzati a tutti gli altri, inoltre ho trovato una libreria che gestisce l'ora legale e vorrei utilizzarla.
Il problema è che questo codice;
/*
This sketch shows an example of sending a reading to data.sparkfun.com once per day.
It uses the Sparkfun testing stream so the only customizing required is the WiFi SSID and password.
The Harringay Maker Space
License: Apache License v2
*/
#include <NTPtimeESP.h>
#define DEBUG_ON
NTPtime NTPch("ch.pool.ntp.org"); // Choose server pool as required
char *ssid = ""; // Set you WiFi SSID
char *password = ""; // Set you WiFi password
/*
* The structure contains following fields:
* struct strDateTime
{
byte hour;
byte minute;
byte second;
int year;
byte month;
byte day;
byte dayofWeek;
boolean valid;
};
*/
strDateTime dateTime;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Booted");
Serial.println("Connecting to Wi-Fi");
WiFi.mode(WIFI_STA);
WiFi.begin (ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("WiFi connected");
}
void loop() {
// first parameter: Time zone in floating point (for India); second parameter: 1 for European summer time; 2 for US daylight saving time; 0 for no DST adjustment; (contributed by viewwer, not tested by me)
dateTime = NTPch.getNTPtime(1.0, 1);
// check dateTime.valid before using the returned time
// Use "setSendInterval" or "setRecvTimeout" if required
if(dateTime.valid){
NTPch.printDateTime(dateTime);
byte actualHour = dateTime.hour;
byte actualMinute = dateTime.minute;
byte actualsecond = dateTime.second;
int actualyear = dateTime.year;
byte actualMonth = dateTime.month;
byte actualday =dateTime.day;
byte actualdayofWeek = dateTime.dayofWeek;
}
}
funziona, ma solo finché e collegata la wifi, appena la scollego non ho più data/ora.
Ho provato a passare i dati nel clock interno del node in questo modo ( e in molti altri)
time_t tempo_NODE;
dateTime = NTPch.getNTPtime(1.0, 1);
// check dateTime.valid before using the returned time
// Use "setSendInterval" or "setRecvTimeout" if required
if(dateTime.valid){
tempo_NODE.hour = dateTime.hour;
tempo_NODE.minute = dateTime.minute;
tempo_NODE.second = dateTime.second;
tempo_NODE.year = dateTime.year;
tempo_NODE.month = dateTime.month;
tempo_NODE.day =dateTime.day;
setSyncProvider(tempo_NODE);
serial.println("aggiornamento avvenuto");
ma mi dà questo messaggio di errore compilandolo "
request for member 'minute' in 'tempo_NODE', which is of non-class type 'time_t {aka long int}'
"ma da problemi anche impostando "long" su minute
potete aiutarmi ?