The routine below works in the Zephyr SDK but reboots the system in the software-SDK. There aren’t any examples or documentation that have helped me find out what changed.
The commented out lines are attempts I’ve mad that don’t work for one reason or another.
Thanks for this report @john.stuewe! Could you share the versions of the Zephyr SDK and firmware SDK that you are using? Also, is there any relevant output that you could share to help us further troubleshoot the issue? I’d also be interested in the value for CONFIG_LOG_PROCESS_THREAD_STACK_SIZE in each case.
I tested this and found it to be working using the tip-of-main of the Golioth Firmware SDK (71ce17986a1de429ec56445847735792339c0943) with an nRF9160dk running our logging sample. I made one change to remove the void * casting from your function and make the pointer a const:
#include <zephyr/logging/log_ctrl.h>
void log_printk_enable(int enabled) {
const struct log_backend *log_backend_golioth_p;
log_backend_golioth_p = log_backend_get_by_name("log_backend_golioth");
if (log_backend_golioth_p == NULL) { LOG_ERR("Golioth log backend not found");}
else if (enabled && !log_backend_is_active(log_backend_golioth_p)) {
log_backend_activate(log_backend_golioth_p, log_backend_golioth_p->cb->ctx);
}
else if (!enabled && log_backend_is_active(log_backend_golioth_p)) {
LOG_INF("Turning off logging to conserve cellular bandwidth");
log_process();
log_process();
log_backend_deactivate(log_backend_golioth_p);
}
}
(edit: It also does not reboot the chip for me when using the original as you posted. I ran an additional test at v0.10.0 of our SDK and also found this to work as expected.)
I’m moving from Zephyr SDK 0.7.1 to Software-SDK 0.10.0
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048 for both configs. I tried it at 10K and it still failed.
in SDK 0.7.1 log_backend_is_active(log_backend_golioth_p) returns “1” but very similar code in SDK 0.10.0 returns “0”.
Does the backend not start automatically on 0.10.0 and is the call log_backend_get_by_name(“log_backend_golioth”) still correct for 0.10.0?
We were able to reproduce the reboot issue when the device wasn’t connected to the network. We are looking into the solution and we’ll follow up with it.
Thanks for reporting this issue (and thanks to @marko for helping me reproduce it). We have pushed two commits related to this problem:
A fix to prevent dereferencing the context pointer when it is null
A behavior change that ensures your activate/deactivate setting will not be overwritten during a disconnect/reconnect event.
The fix was included in today’s release v0.11.0; the behavior change will be included in the next release which should come soon as we’re just waiting on a response about an issue from Nordic before merging in NCS v2.6.0.
I suggest calling your function from the Golioth connection event callback so that the logging is activated/deactivate on each reconnect. This should work no matter which version of the SDK you are using.