app_sched_event_put passing string as parameter

Please provide an example of using app_sched_event_put() to pass a string.

This is what I have at present:

static char timeStr[LEN];
// code fills timeStr here
app_sched_event_put(&timeStr, sizeof(char *), myHandler);

void myHandler(void * p_event_data, uint16_t event_size) {
	char *str = (char *)p_event_data;
	uint16_t length = strlen((char *)p_event_data);

	NRF_LOG_INFO("From %p received %d characters '%s'", p_event_data, length, str);
	NRF_LOG_INFO("Original at %p is '%s'", &timeStr, timeStr);
	NRF_LOG_HEXDUMP_INFO((uint8_t *)str, 26);
}

The handler appears to get the first 4 characters OK (perhaps this is one 32-bit word?) then garbage

<info> app: From 0x20004F14 received 6 characters 'utc �['
<info> app: Original at 0x20005B10 is 'utc 2025-03-26T01:50:00Z'
<info> app:  75 74 63 20 C9 5B 00 20|utc .[.
<info> app:  75 74 63 20 C9 5B 00 20|utc .[.
<info> app:  00 00 00 00 00 04 00 00|........
<info> app:  00 04                  |..

  • Hello,

    sizeof(char *) sets the length to '4' bytes, so only 4 characters will be copied. If you only want to copy the pointer reference, then you can do something like this:

    void myHandler(void * p_event_data, uint16_t event_size) {
    	char *str = *(char **)p_event_data;
    	uint16_t length = strlen(str);
    	
    	...
    
    char * time_ptr = timeStr;
    app_sched_event_put(&time_ptr, sizeof(char *), myHandler);

    Best regards,

    Vidar

Related