My Raspberry Pi box has 8 character hostname 'acarspi3', that does not fit in the given buffer with the terminating null character. In principle hostname() function should care of that, but the glibc implementation has an undefined behaviour in this case and omits the terminator, resulting garbage as station id in JSON output. The following modification solved the issue:
My Raspberry Pi box has 8 character hostname 'acarspi3', that does not fit in the given buffer with the terminating null character. In principle hostname() function should care of that, but the glibc implementation has an undefined behaviour in this case and omits the terminator, resulting garbage as station id in JSON output. The following modification solved the issue:
char sys_hostname[9]; sys_hostname[sizeof(sys_hostname) - 1] = '\0'; gethostname(sys_hostname, sizeof(sys_hostname) - 1);