Calendar on IOT

Hello, everyone!

I'm starting a new project and I'll need to use the calendar (Dashboard / Arduino Cloud / IOT) with the Arduino Uno R4 Wi-fi. Does anybody know where I can get some examples of codes using the calendar dashboard?

Thanks.

Trying Google is one idea.

Hi @fernandoagf

I'm not sure I understand what you mean by "calendar dashboard". Are you referring to the "Time Picker" widget?:

https://docs.arduino.cc/arduino-cloud/cloud-interface/dashboard-widgets/#time-picker

If not, please provide a link to where you found information about the "calendar dashboard" in a reply here on the forum thread so that the helpers can better understand the subject of your query.

I did. But I could only find using esp32 and the WiFi shield module. I didn’t find anything using the uno r4 WiFi. That’s why I am asking here.

Yes, that’s exactly what I’m talking about. Do you know where I can find examples of how can I use it?

Okey. The R4 is relatively new. Look for similar use of the R4 Wifi. Drop the dashboard for the moment.

I'm not aware of any existing examples unfortunately, so I wrote one:

/* 
  Arduino IoT Cloud Variables description:

  CloudTime currentTime;
  CloudTime selectedTime;
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // See: https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/docs/api.md#getlocaltime
  currentTime = ArduinoCloud.getLocalTime();
}


/*
  Since selectedTime is READ_WRITE variable, onSelectedTimeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onSelectedTimeChange() {
  // Cast variable to standard time type used by gmtime.
  time_t selectedTimeCast = selectedTime;
  // Convert time to standard tm struct used by strftime.
  // See: https://cplusplus.com/reference/ctime/gmtime/
  struct tm *selectedTimeStruct = gmtime(&selectedTimeCast);
  // Create appropriately sized char array to hold the time string.
  char selectedTimeBuffer[sizeof("yyyy-mm-dd hh:mm:ss") + 1];
  // Convert the time to a text representation.
  // See: https://cplusplus.com/reference/ctime/strftime/
  strftime(selectedTimeBuffer, sizeof(selectedTimeBuffer), "%Y-%m-%d %H:%M:%S", selectedTimeStruct);
  Serial.println("A new time was selected on the dashboard:");
  Serial.println(selectedTimeBuffer);
}

image

1 Like

Thanks a lot for your time!!! It helped me a lot.

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

Thank you!!! Now it's working, but not the way I want.
I want to control the irrigation pump through a push button or a calendar o IOT.
The rules are:

  • No matter if the push button is pressed or not, if the calendar is set to TRUE, the pump will run.
  • Whenever the pump is running, if I turn off the pump through the push button, it should turn off the pump, even if the calendar is set to through (By doing this I have a button to turn the pump on or off manually and it will also work as an emergency button).
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/758ca0da-74e6-4361-9014-33d2deb21fff 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudLight led;
  CloudSwitch switch1;
  CloudSchedule calendar;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#define pump 10
#define ferti 11

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  pinMode(10, OUTPUT);
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  if (calendar.isActive()){
    digitalWrite(10, HIGH);
    Serial.println("Calendar activated");
    delay(500);
  } else
  {
    digitalWrite(10, LOW);
    Serial.println("Calendar deactivated");
    delay(500);
  }     
/*if (led == 1){
   digitalWrite(10, HIGH);
   Serial.println("On by button");
   delay(500);
 } else{
   digitalWrite(10, LOW);
   Serial.println("Off by button");
   delay(500);
 }*/
}
void onLedChange()  {
 if (led == 1){
   digitalWrite(10, HIGH);
   Serial.println("On by button");
   delay(500);
 } else{
   digitalWrite(10, LOW);
   Serial.println("Off by button");
   delay(500);
 }
}

void onCalendarChange()  {
  // Add your code here to act upon Calendar change
}


void onSwitch1Change()  {
  
}

Thanks again for the help

You are welcome. I think it is good progress at least.

Unfortunately I won't be able to advise on this aspect of your project. I'm certain if you keep at it you will achieve success soon enough. Hopefully the other forum helpers will be able to step in with whatever additional assistance is required.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.