"Not charging" is 12 characters; %12[a-zA-Z ] reads up to 12 chars plus a NUL terminator (13 bytes) into a 12-byte buffer. Increase state buffer to 13 in both battery_state and battery_remaining.