Why core module blinking SOS by morse code?


#1

Why Core module blinking SOS after approx 5 minutes of using? Probably it is some internal function (because I am not using morse code in my code, yet :wink:), but I am not sure what does it mean. After that the application freezes.

I found that it is related to one function which I am calling every 20 seconds. But it is just about writing something to log (after I have commented 99% of function to find where is the problem), nothing complex… When I disable this function, it works normally…

Here is the code which cause it:

#define DEFAULT_WATERING_NORMAL_CHECK_INTERVAL          (1 * 20 * 1000)
bc_scheduler_register(watering_handler, NULL, bc_scheduler_get_spin_tick() + 10 * 1000);

void watering_handler()
{  
    bc_log_info("WATERING HANDLER - running");
    bc_scheduler_register(watering_handler, NULL, bc_scheduler_get_spin_tick() + DEFAULT_WATERING_NORMAL_CHECK_INTERVAL);
}

Thanks for any suggestion…


#2

Hello, we added this blinking when you forget to call bc_log_init in the application_init().

Please check your init function.

I must say you have agood eye to spot the SOS pattern :wink:


#3

Hello,
when it was blinking I found that it is not random, that something is repeating. Then I read the pattern and I started to laugh. Because I know that my work is not so clean in the application, I understand, that Core module shouts for help :grin:

But… I have call bc_log_init in the application_init(). I am using logs for a long time and it works. Yesterday, when I seen the SOS signals, it writed logs too.

Or need I to init every type of log which I want to use? (debug, error, info)


#4

The other error which starts SOS is that you are registering too much tasks. If the blinking is not random, then most probably there is some bug in your code which is creating tasks on runtime but not terminaning it.

Search for the application_error function.


#5

Thank you, it is very likely that I am still using tasks wrongly… It is related to: How to correctly use bc_scheduler?

I am not using “bc_scheduler_unregister(bc_scheduler_get_current_task_id());” and calling other and other “instances” of the same function if I want to create “infinite loop” started every x seconds… I wrongly understand this sentence: “Every task has to call “plan” function, otherwise it is planned in the time “INFINITY” which means the task is never run again, unless is replanned by bc_scheduler functions.” --> I thought that when I call some function, it runs only once and I need to replan it to next run. (not to unregister the task, because it will be cleared after it finish) I need to study it more…

Thank you for your ideas!


#6

Probably I have mixed registering a task and calling a task… I have read https://www.bigclown.com/doc/firmware/timing-and-scheduler/ more carefully and I have some ideas to change in my code…


#7

If has task registered, then get id, this id can by using for unregister or change execution time.
for example:

bc_button_t button;
bc_scheduler_task_id_t warning_task_id;

void button_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param)
{
    if (event == BC_BUTTON_EVENT_CLICK)
    {
        bc_scheduler_plan_now(warning_task_id);
    }
    else if (event == BC_BUTTON_EVENT_HOLD)
    {
        bc_scheduler_plan_relative(warning_task_id, 2000);
    }
}

void warning_task(void *param)
{
    bc_log_warning("Example warning task.");
}

void application_init(void)
{
    bc_button_init(&button, BC_GPIO_BUTTON, BC_GPIO_PULL_DOWN, false);

    bc_button_set_event_handler(&button, button_event_handler, NULL);

    warning_task_id = bc_scheduler_register(warning_task, NULL, BC_TICK_INFINITY);
}

#8

Reason why blinking SOS is printing to serial port. Use this command for show error messages:
bcf log


#9

Thank you, but as Martin metnioned, there was no problem with log (I am using bcf log for debugging), but there was problem with calling tasks. When I registered the task just only once and then reschedule It to some time, it works.

Thanks for great example above!


#10

I know, but sos handler using same mechanism as bc_log for printing why is blinking sos.