Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion: update time #213

Open
societyofrobots opened this issue Aug 15, 2021 · 1 comment
Open

suggestion: update time #213

societyofrobots opened this issue Aug 15, 2021 · 1 comment

Comments

@societyofrobots
Copy link

v3 now has date/time parameters, looks good, but they don't update.

I was thinking, could timeParam.value()/dateParam.value() in the background add elapsed time to the initial stored date/time? Not saved in SPIFFS of course, just calculated and returned when requested.

Of course, the user will have to fix the starting date/time on any power reset, but it does simplify tracking elapsed time for the user.

In wifi mode one could just take the time from an online server, but this won't work in AP mode.

@societyofrobots
Copy link
Author

In the meantime, I added some very basic date/time code for anyone interested.
I'm not the best of programmers and it's not 100% tested in all cases yet, but here it is.

Create parameters:

iotwebconf::ParameterGroup group1 = iotwebconf::ParameterGroup("group1", "Starting Date / Time");
iotwebconf::IntTParameter<int16_t> dayParam =
  iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("dayParam").
  label("Day").
  defaultValue(1).
  min(1).
  max(31).
  step(1).
  placeholder("day of month").
  build();
iotwebconf::IntTParameter<int16_t> monthParam =
  iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("monthParam").
  label("Month #").
  defaultValue(1).
  min(1).
  max(12).
  step(1).
  placeholder("month of year").
  build();
iotwebconf::IntTParameter<int16_t> yearParam =
  iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("yearParam").
  label("Year, last two digits only").
  defaultValue(21).
  min(21).
  max(99).
  step(1).
  placeholder("last 2 digits of year").
  build();
iotwebconf::IntTParameter<int16_t> hourParam =
  iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("hourParam").
  label("Hour (military time, 0 to 23)").
  defaultValue(0).
  min(0).
  max(23).
  step(1).
  placeholder("hour of day, military time").
  build();
iotwebconf::IntTParameter<int16_t> minuteParam =
  iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("minuteParam").
  label("Minute").
  defaultValue(0).
  min(0).
  max(59).
  step(1).
  placeholder("minute").
  build();

In wifi setup:

  group1.addItem(&dayParam);
  group1.addItem(&monthParam);
  group1.addItem(&yearParam);
  group1.addItem(&hourParam);
  group1.addItem(&minuteParam);
    
  iotWebConf.addParameterGroup(&group1);//time

Include this header:
#include "date_time.h"

Download my header from date_time.

This goes in your main setup()

  //initialize time from memory
  day=dayParam.value();
  month=monthParam.value();
  year=yearParam.value();
  hour=hourParam.value();
  minute=minuteParam.value();

And finally, call these two lines to update and print the time:

date_time_calculate();
date_time_print();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant