# main.py - IoT Medical Monitoring (Pressure + Position) with fake WiFi workaround
import time
import math
# Simulated BMP280 pressure sensor
class BMP280:
def read_pressure(self):
return 1012.5 + math.sin(time.time()) * 2 # simulate fluctuation
# Simulated MPU6050 tilt angle
class MPU6050:
def read_position_angle(self):
return 10 + math.sin(time.time()) * 30 # simulate angle tilt
# Fake WiFi connection (Wokwi doesn't simulate WiFi)
def connect_wifi():
print("[FakeWiFi] Connecting to WiFi...")
time.sleep(1)
print("[FakeWiFi] Connected successfully (simulated)")
# Simulated ThingSpeak API call (print instead of real request)
def send_to_thingspeak(systolic, diastolic, angle):
api_key = "THINGSPEAK_API_KEY"
print("[ThingSpeak] Sending data:")
print(f" -> Systolic: {systolic:.1f} mmHg")
print(f" -> Diastolic: {diastolic:.1f} mmHg")
print(f" -> Angle: {angle:.2f}°")
print(f" -> Sent to https://api.thingspeak.com/update?api_key={api_key}&field1={systolic:.1f}&field2={diastolic:.1f}&field3={angle:.2f}")
# Simulated alert system
def check_alerts(systolic, diastolic, angle):
#Typical human blood pressure values:
#Systolic: 90–120 mmHg - Diastolic: 60–80 mmHg
alerts = []
if angle < 10 and systolic < 90:
alerts.append("⚠️ Πιθανή ορθοστατική υπόταση : ελεγχος!")
if abs(angle) > 45:
alerts.append("⚠️ Επικίνδυνη κλίση : πιθανή πτώση!")
if abs(angle) < 5 and pressure > 120:
alerts.append("ℹ️ Καθιστή θέση με υψηλή πίεση : έλεγχος συνθηκών.")
for alert in alerts:
print(alert)
# Initialize sensors
bmp280 = BMP280()
mpu6050 = MPU6050()
connect_wifi()
while True:
angle = mpu6050.read_position_angle()
#In reality, a BMP280 gives atmospheric pressure in hPa, not blood pressure. But for simulation/educational purposes, we can "translate" it.
pressure = bmp280.read_pressure()
# Convert BMP280 pressure to fake systolic and diastolic (for demo only!)
systolic = (pressure - 980) * math.rand 1.5 + 100 # simulate range ~100–140 mmHg
diastolic = systolic * 0.75 # keep diastolic ~75% of systolic
check_alerts(systolic, diastolic, angle)
send_to_thingspeak(systolic, diastolic, angle)
time.sleep(30) # simulate ThingSpeak limit