import machine
import time
import json
DEVICE_ID = "PICO_W_BLDG_01"
LOCATION = "Server_Room"
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / 65535
print("Experiment 4.2: JSON Packaging Started...")
print("-" * 40)
while True:
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706) / 0.001721
data_dictionary = {
"sensor_id": DEVICE_ID,
"location" : LOCATION,
"telemetry":{
"temp": round(temperature, 2),
"unit": "Celsius"
},
"timestamp_ms": time.ticks_ms(),
"status": "OK"
}
json_packet = json.dumps(data_dictionary)
print(f"RAW DICTIONARY: {data_dictionary}")
print(f"JSON PACKET: {json_packet}")
print(f"DATA TYPE: {type(json_packet)}")
print("-" * 40)
time.sleep(5)