0

RTC Question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RTC Question

by whmckinley on Mon Mar 18, 2019 11:58 pm

Totally new to IOT, so please excuse my confusion.

I have an application, testing and running that is standalone. Looking to move it to IOT. I can duplicate all items in my running application except one item I can't quite understand.
The application is an Automatic Water Meter Reader, It reads the counts from a water meter with a trigger output. Calculates the gallonage by hour and is currently sending a daily email listing hour by hour usage and daily total at midnight each day. I'm trying to get away from using email and transitioning to IOT for increased functionality.

Short problem explanation.

I'm using a DS3231 RTC chip to control the timing. I am syncing a timing circuit to the hour,min,sec rollover to accurately perform the calculations.
Main Problem getting the correct time on initial setup to program the DS3231. I am currently using the following code snippet to set the RTC.

second = timeinfo.tm_sec;
minute = timeinfo.tm_min;
hour = timeinfo.tm_hour;
day = timeinfo.tm_mday;
month = timeinfo.tm_mon + 1;
year = timeinfo.tm_year + 1900;
rtc.adjust(DateTime(year, month, day, hour, minute, second));

time.h is the library I am using for the DS3231. It is supplying the timeinfo.tm_xx struct. Pulling the time from the pool.ntp.org. It works very well for my standalone application, but i can't seem to cross this over to IOT.

whmckinley
 
Posts: 8
Joined: Thu Oct 13, 2011 12:43 am

Re: RTC Question

by adafruit_support_mike on Tue Mar 19, 2019 3:39 am

What part of the system has an internet connection?

adafruit_support_mike
 
Posts: 57479
Joined: Thu Feb 11, 2010 2:51 pm

Re: RTC Question

by whmckinley on Tue Mar 19, 2019 8:50 am

I am using an Huzzah esp32

Perhaps easier to attach code,

amr.txt
File for the Automatic Meter Reader
(12.79 KiB) Downloaded 13 times

whmckinley
 
Posts: 8
Joined: Thu Oct 13, 2011 12:43 am

Re: RTC Question

by adafruit_support_mike on Tue Mar 19, 2019 11:49 pm

The ESP32 has a known issue where the I2C doesn't work while the Wifi radio is active. Try pulling an NTP update, shutting off the Wifi, setting the RTC, then reconnecting the Wifi when you need it.

adafruit_support_mike
 
Posts: 57479
Joined: Thu Feb 11, 2010 2:51 pm

Re: RTC Question

by whmckinley on Wed Mar 20, 2019 1:52 am

Mike

Then, by your suggestion I have modified the Adafruit_IO_00_Publish example code to pull the NTP time. (attached modiied code) This does pull down the NTP time, Do I add a WIFI_OFF stop the wifi to write to the rtc and then recall io.connect(); to reconnect to io.adafruit.com ? I'm using that example as a learning curve.

Thank You for your assistance.

bill
Attachments
Modified_Publish_00.txt
(2.44 KiB) Downloaded 17 times

whmckinley
 
Posts: 8
Joined: Thu Oct 13, 2011 12:43 am

Re: RTC Question

by adafruit_support_mike on Thu Mar 21, 2019 12:10 am

That would be a good starting point.

The library code has enough moving pieces that it's hard to say exactly where it needs modified, but in general, anything you do-then-undo in your main code should leave the library code undisturbed.

adafruit_support_mike
 
Posts: 57479
Joined: Thu Feb 11, 2010 2:51 pm

Re: RTC Question

by whmckinley on Thu Mar 21, 2019 12:38 pm

Mike
Thanks, I'll play with it.

whmckinley
 
Posts: 8
Joined: Thu Oct 13, 2011 12:43 am

Please be positive and constructive with your questions and comments.