LED Lights to be set at particular time

Hello everyone,
I want to set a particular time in text box and the state of LED(on or off) in another text box.When the user enters time in text box, it should be compared with the NTP time and then the state of lights should change according to the users interest.How should user take time in format(hh:mm:ss) in a text box and compare with NTP time??

Hi,

if you’d like to display time in a text widget you should define an output resource. See an example below:

 void setup(){

// Output resource
         thing["time"] >> [](pson& out){
         String time = hh_var + String(":") + mm_var + String(":") + ss_var;   
         out = time.c_str();    
        };
    }

To my knowledge, it doesn’t work the other way around. I mean you can not type text into a text widget and send it back to your device (this would be an awesome feature! :wink:).

1 Like

This widget should be easy to develop! I will try to include it this week! :wink:

I’ve make this kind of implementations (time setings), and the way that I used is to compare hours and minutes as separate variables

something like this:

Clock= actual time
Set= Time to begin the action, turn the led on for example.
Reset= Time to end the action, turn the led off for example

if (((hourClock== hourSet && minuteClock>minuteSet) || (hourClock>hourSet)) &&((hourClock== hourReset && minuteClock<minuteReset) || (hourClock<hourReset)))
{
//turn the led on for this example (or do whatever)
}
else
{
//turn the led off for this example (or don't do whatever xD)
}

with that if, the action will be executed meanwhile the clock be between Set and Reset

I’m not an experienced programmer, this was the way that I found to solve the particulary need that I had :wink:

Yes, from the thinger perspective, to configure the hour, minute and second to control the led (at least for the api console), I would define something like:

short hour=0, minute=0, second=0;

void setup() {

  thing["hour"] << [](pson& in){
    if(in.is_empty()){
       in["hh"] = hour;
       in["mm"] = minute;
       in["ss"] = second;
    }else{
      hour = in ["hh"];
      minute = in["mm"];
      second = in["ss"];
    }
  };
  

You can also define the hour in text format and later compare it as string:

String hour="00:00:00";

void setup() {

  thing["hour"] << inputValue(hour);
  
}

How to control state of led from this??
How to compare the given time with ntp time ??

How can you compare time by taking it in a text box with system time(using ntp)?? and also state of led should be set

Do you have a problem with thinger platform? or developing your project’s code?

Thinger Platform mainly.How can time be read from text box and it should be compared with network time i.e; ntp .Can I read time from text box and proceed??Please develop code for time comparison and set the state of led accordingly.