Fix possible buffer overflow by using snprintf
Use a single GPIO read instead of multiple ones