IotWebConf icon indicating copy to clipboard operation
IotWebConf copied to clipboard

suggestion: update time

Open societyofrobots opened this issue 3 years ago • 1 comments

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 avatar Aug 15 '21 01:08 societyofrobots

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();

societyofrobots avatar Aug 15 '21 17:08 societyofrobots