from datetime import datetime
from arcros import create_subscriber


def handle_message(data):
    timestamp = datetime.now().strftime('%H:%M:%S.%f')[:-3]
    print(f"[{timestamp}]")
    
    if isinstance(data, dict):
        for key, value in data.items():
            if isinstance(value, float):
                print(f"  {key}: {value:.4f}")
            else:
                print(f"  {key}: {value}")
    else:
        print(f"  {data}")
    
    print()


def main():
    with create_subscriber('sensor_data') as sub:
        sub.listen(handle_message)


if __name__ == "__main__":
    main()
