Docsity

IOT Practical 11 mini-project code TE AIDS SPPU 2024 Pattern, Study Guides, Projects, Research of Internet and Information Access

Toggle sidebar
bg1
import time
import random
import json
from machine import Pin
from dht import DHT22
# --- HARDWARE SYSTEM SETTINGS ---
dht_sensor = DHT22(Pin(2))
alert_led = Pin(3, Pin.OUT)
# --- VIRTUAL NETWORK LOOPBACK PIPELINE MATRIX ---
class VirtualMQTTBroker:
"""Simulates a secure cloud message broker entirely within chip memory."""
def __init__(self):
self.subscriptions = {}
def subscribe(self, topic, callback_function):
self.subscriptions[topic] = callback_function
print(" [Network Layer] Channel Subscribed -> Ready for data link.")
def publish(self, topic, message_string):
print(" [Network Layer] Packet routing through Virtual Infrastructure Broker...")
# Simulate an instant asynchronous network loopback deliverable
if topic in self.subscriptions:
self.subscriptions[topic](topic, message_string.encode('utf-8'))
# Instantiate the localized network sandbox layer
virtual_broker = VirtualMQTTBroker()
# --- EMBEDDED INTEL-DECISION ENGINE (CLOUD ML LAYER) ---
BASELINE_TEMP = 24.0
BASELINE_HUMID = 45.0
SAFETY_RADIUS_THRESHOLD = 20.0
def evaluate_cloud_level_ml(temp, humid):
"""Calculates geometric variance to isolate malicious tampering or critical events."""
variance_distance = ((temp - BASELINE_TEMP)**2 + (humid - BASELINE_HUMID)**2)**0.5
print(" [Cloud ML Engine] Computed Variance Metric Score:
{:.2f}".format(variance_distance))
if variance_distance > SAFETY_RADIUS_THRESHOLD:
return "OUTLIER_ANOMALY"
return "STABLE_DATA"
def incoming_packet_subscriber_loop(topic, msg):
"""Acts as the Cloud analytics pipeline consumer interface loop."""
print("\n [Ingested Event: Cloud Data Intake Pipeline]")
try:
data = json.loads(msg.decode())
t_in = data["temp"]
h_in = data["humid"]
p_type = data["privacy_mode"]
pf3

Partial preview of the text

Download IOT Practical 11 mini-project code TE AIDS SPPU 2024 Pattern and more Study Guides, Projects, Research Internet and Information Access in PDF only on Docsity!

import time import random import json from machine import Pin from dht import DHT

--- HARDWARE SYSTEM SETTINGS ---

dht_sensor = DHT22(Pin(2)) alert_led = Pin(3, Pin.OUT)

--- VIRTUAL NETWORK LOOPBACK PIPELINE MATRIX ---

class VirtualMQTTBroker: """Simulates a secure cloud message broker entirely within chip memory.""" def init(self): self.subscriptions = {} def subscribe(self, topic, callback_function): self.subscriptions[topic] = callback_function print(" [Network Layer] Channel Subscribed - > Ready for data link.") def publish(self, topic, message_string): print(" [Network Layer] Packet routing through Virtual Infrastructure Broker...")

Simulate an instant asynchronous network loopback deliverable

if topic in self.subscriptions: self.subscriptions[topic](topic, message_string.encode('utf-8'))

Instantiate the localized network sandbox layer

virtual_broker = VirtualMQTTBroker()

--- EMBEDDED INTEL-DECISION ENGINE (CLOUD ML LAYER) ---

BASELINE_TEMP = 24. BASELINE_HUMID = 45. SAFETY_RADIUS_THRESHOLD = 20. def evaluate_cloud_level_ml(temp, humid): """Calculates geometric variance to isolate malicious tampering or critical events.""" variance_distance = ((temp - BASELINE_TEMP)2 + (humid - BASELINE_HUMID)2)**0. print(" [Cloud ML Engine] Computed Variance Metric Score: {:.2f}".format(variance_distance)) if variance_distance > SAFETY_RADIUS_THRESHOLD: return "OUTLIER_ANOMALY" return "STABLE_DATA" def incoming_packet_subscriber_loop(topic, msg): """Acts as the Cloud analytics pipeline consumer interface loop.""" print("\n [Ingested Event: Cloud Data Intake Pipeline]") try: data = json.loads(msg.decode()) t_in = data["temp"] h_in = data["humid"] p_type = data["privacy_mode"]

print(" Decoded - > Temp: {}°C, Humid: {}% [Privacy: {}]".format(t_in, h_in, p_type))

Pass variables directly to the isolation engine analytics layer

ml_decision = evaluate_cloud_level_ml(t_in, h_in) print(" Analytical Verdict Result:", ml_decision)

Control physical alarm status outputs based on ML models verification metrics

if ml_decision == "OUTLIER_ANOMALY": print(" Threat Verified! Enforcing local isolation loop.") alert_led.value(1) # Flash warning hazard indicators red else: print(" Operational parameters stabilized within nominal limits.") alert_led.value(0) # Clear system logs parameters except Exception as error: print(" Payload parser verification logic failure event:", error)

--- SYSTEM INITIALIZATION SETUP ---

print("Initializing Privacy-Aware Intelligent AIoT Application...") print("Starting Virtual Secure Network Gateway Stack...") time.sleep(0.5) print("Device IP Allocated: 10.10.0.1 (Localized Wokwi Sandbox Sandbox Mode)")

Establish subscription links

TELEMETRY_TOPIC = "aiot/integrated/telemetry" virtual_broker.subscribe(TELEMETRY_TOPIC, incoming_packet_subscriber_loop) print("System Pipeline Connected. Local Cloud-Loop Active via In-Memory Secure Bridge.")

--- PRODUCTION RUNTIME EXECUTION LOOP ---

while True: try:

1. Edge Layer: Collect physical telemetry values

dht_sensor.measure() raw_t = dht_sensor.temperature() raw_h = dht_sensor.humidity()

2. Privacy Preprocessing Layer (Local Data Anonymization via Noise Injection)

Applies Differential Privacy perturbation to mask precision patterns

noise_variance = (random.getrandbits(8) / 255.0 - 0.5) * 0. anonymized_t = round(raw_t + noise_variance, 2)

3. Secure Payload Construction

sensor_payload = { "temp": anonymized_t, "humid": raw_h, "privacy_mode": "Differential_Noise_Injection", "timestamp_node_tick": time.ticks_ms() } print("\n [Edge Sensor Node Telemetry Update]") print(" Raw Sensor: T={:.1f}°C, H={:.1f}%".format(raw_t, raw_h)) print(" Anonymized Outbound Stream:", json.dumps(sensor_payload))