How can I loop like Arduino Loop()

Hi. I new in mongoose normally I develop on Particle.io it’s 100% Arduino compatible. And am not C expert I afraid to make clash on our production firmware.

This is my question..

  1. How can I loop like Arduino Loop() I should used SW timer or HW timer ?
  2. if I have many sensor to read I should used many timer or single timer ?
  3. Do I have to free ram or anything I should concern about memory management ?
  4. If anyone open for consultancy service please leave an email.

There is no “loop” like arduino - mOS is event driven.

What you can do is look at the timer callback feature.
If you wanted as tight a loop as possible you could call your “loop” function once it was complete, otherwise if you wanted a time based loop you can use the “MGOS_TIMER_REPEAT” flag.

mgos_set_timer(0, 0, loop, NULL);    // call 'loop' immediately
mgos_set_timer(1000, MGOS_TIMER_REPEAT, loop, NULL);    // call 'loop' every 1000 ms

Thanks you for your reply…
So if I have multiple sensor to read which way are the best way to do

  1. have multiple timer to call individual method
  2. have 1 timer inside timer_cb I call multiple method in each method may do like this for set difference cycle time read

void readSensorA() {
if(mills()-lastSensorACall > 1000) {

}
}

It depends. If the interval when you read the sensors is the same for all of them, you can use 1 timer

mgos_set_timer(sensors_read_interval, MGOS_TIMER_REPEAT, sensors_read_cb, NULL);

otherwise you can group the readings for the same interval in several timers.

I agree, my biggest hurdle coming from Arduino was trying to change my though process of how my program should execute.

Best to think about what actions/events that would cause your project to do different things. Then you can start to think about what sensor readings might trigger those events etc.

OK. so used multiple timer to do this. Thanks you guys