Hi Artur,
Quite easy doing it if you use timers.h library.
Check it here: Arduino Playground - Timer Library
I extracted what matters most from my code as an example.
//in the include session:
#include <Time.h>
#include "Timer.h" // examples at http://playground.arduino.cc/Code/Timer#Links
Timer t; // creating a timer object named "t"
// in setup
void setup() {
// ... your code
triggerTimers(); // Start timer that triggers events
}
void loop() {
// Cayenne.run(); // don't run it here. Commented. Will kick it from triggerTimers
t.update(); // triggers all timer t objects defined on setup
}
void triggerTimers() {
t.every(1000 , callCayenne); // for some reason I could not call Cayenne.run() here so I call a routine that do it at every second
}
void callCayenne() {
Cayenne.run();
}
Hope it helps
Cheers
Carlos