import machine
import time
import json
from machine import Pin
adc = machine.ADC(Pin(26))
THESHOLD = 500
last_sent_value = 0
def simulate_cloud_processing(packet):
data json.loads(packet)
val = data["raw_value"]
if val > 60000:
print(f">>> [CLOUD ALERT] critical pressure at {val}! shutting down system.")
else:
print(f" [CLOUD LOG] Normal operation recorded for {data['id']})
print("Experiment 4.2: Edge Filtering with potentiometer startd...")
print("_" * 50)
while True:
current_value = adc.read_u16()
diff = abc(current_value - last_sent_value)
if diff > THESHOLD:
packet = json.dumps({
"id": "VALUE_01",
"raw_value": current_value,
"event": "significant change"
})
print(f"EDGE: pot moved! change = {diff}. sending to cloud...")
simulate_cloud_processing(packet)
last_sent_value = current_value
else:
print(f"EDGE: minor pot movement ({diff}). Data filtered locally.")
time.sleep(2)