Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Thu Jul 07, 2016 10:23 pm 

Joined: Thu Jul 07, 2016 10:16 pm
Posts: 2
OK, so I had a code that was working properly at a testing time @usb and @wifi (see below). As you can see, I want to send a PowerStrip on/off codes at certain part of the day.

Code:
#include <OpenGarden.h>
#include <Wire.h>

//Power strip codes. Please insert here your own codes generated with
//RF_Receive_remoteControl_codes
unsigned long on1 = 1622153562;
unsigned long off1 = 1605376348;
unsigned long on2 = 1605376364;
unsigned long off2 = 1605376366;
unsigned long on3 = 1605376256;
unsigned long off3 = 1605376258;
unsigned long on4 = 1605376094;
unsigned long off4 = 1605376096;
unsigned long on5 = 1605375608;
unsigned long off5 = 1605375610;

int on_hr = 7;
int on_min = 0;

int off_hr = 22;
int off_min = 36;

void setup() {
  Serial.begin(9600);
  OpenGarden.initRTC();
  //OpenGarden.setTime(); //write time to the RTC chip
  OpenGarden.sendPowerStrip(on1); //Turn ON plug 1
  OpenGarden.sendPowerStrip(on2); //Turn ON plug 2
  OpenGarden.sendPowerStrip(on3); //Turn ON plug 3
  OpenGarden.sendPowerStrip(on4); //Turn ON plug 4
  OpenGarden.sendPowerStrip(on5); //Turn ON plug 5
   
}
DateTime now;

void loop() {
  now = OpenGarden.getTime(); //Get date and time
 
  if ( now.hour() == on_hr && now.minute() == on_min && now.second() == 0 ) {
    OpenGarden.sendPowerStrip(on1); //Turn ON plug 1
    Serial.println("Plug 1: ON");
    Serial.print("godzina na ON: ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(),DEC);
    Serial.println(" ");
    Serial.print("lajt ON, czekam...");
    Serial.println(" ");
    Serial.println(" ");
    delay(1000);
  }
 
   if ( now.hour() == off_hr && now.minute() == off_min && now.second() == 0 ) {
     OpenGarden.sendPowerStrip(off1); //Turn ON plug 1
     Serial.println("Plug 1: OFF");
     Serial.print("godzina na OFF: ");
     Serial.print(now.hour(), DEC);
     Serial.print(':');
     Serial.print(now.minute(),DEC);
     Serial.println(" ");
     delay(1000);   
}
 
}


As the code didn't send an off signal at the proper hour, I've tried to reset the RTC (again, via wifi, and via usb).

Code:
#include <OpenGarden.h>
#include <Wire.h>

DateTime now;

void setup() {
  Serial.begin(9600);
  OpenGarden.initRTC(); //Initialize RTC
  OpenGarden.setTime(); //write time to the RTC chip
}

void loop() {
  Serial.print(now.day(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.year(), DEC);
    Serial.print("  ");
  Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(),DEC);
    Serial.println(" ");
  delay(1000);
}


the above code gives me some insane date, like 6/2/2106 and time not being correct.

my board is Arduino Uno WiFi (http://www.arduino.org/learning/getting ... o-uno-wifi).

WTF am I doing wrong?


Top
 Profile  
 
 Post subject: Re: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Fri Jul 08, 2016 7:44 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11338
Hello eof,

We have only tested RTC with Arduino Uno. Please try closing the IDE and disconnecting the USB. Open and reconnect USB and run quickly "RTC_setHour" only once, and after this run "RTC_printAll".

Regards


Top
 Profile  
 
 Post subject: Re: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Thu Jul 14, 2016 9:30 am 

Joined: Thu Jul 07, 2016 10:16 pm
Posts: 2
libelium-dev wrote:
We have only tested RTC with Arduino Uno. Please try closing the IDE and disconnecting the USB. Open and reconnect USB and run quickly "RTC_setHour" only once, and after this run "RTC_printAll".


I have connected the shield into a fresh Uno and result is the same. RTC_setHour prints incorrect date/time to serial monitor... :(


Top
 Profile  
 
 Post subject: Re: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Fri Jul 15, 2016 7:28 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11338
Hello eof,

RTC takes the hour of the PC where the compiler is running (Arduino IDE). Is the hour well set in your PC?

Regards


Top
 Profile  
 
 Post subject: Re: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Tue Jun 04, 2019 5:37 pm 

Joined: Thu Dec 08, 2016 10:37 am
Posts: 7
Location: Italy
Quote:
I have connected the shield into a fresh Uno and result is the same. RTC_setHour prints incorrect date/time to serial monitor... :(


Hello eof,
I had trouble too with RTC, in my case I had to remap A4 and A5 on the correct pins for Arduino Yun, not sure on Arduino wifi but could be the same of your original issue.

About the code you posted, I got the very same insane date, i think that the root cause is the setTime() that honestly I've no idea how to use this function.

base on your code, following a works for me version:

Code:
#include <OpenGarden.h>
#include <Wire.h>

DateTime now;

void setup() {
  Serial.begin(9600);
  OpenGarden.initRTC(); //Initialize RTC
}

void loop() {
  now = OpenGarden.getTime(); //Get date and time
  Console.print(now.day(), DEC);
  Console.print("/");
  Console.print(now.month(), DEC);
  Console.print("/");
  Console.print(now.year(), DEC);
  Console.print("  ");
  Console.print(now.hour(), DEC);
  Console.print(':');
  Console.print(now.minute(),DEC);
  Console.println(" ");
  delay(1000);
}


Top
 Profile  
 
 Post subject: Re: OpenGarden.SetTime(); doesn't reset to CPU
PostPosted: Wed Jun 05, 2019 7:48 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11338
Thanks for your cooperation with the community federcobriata!

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use.