import network
import machine
import utime
import random
# Configure ADC for temperature reading
temp_sensor = machine.ADC(machine.Pin(34))
temp_sensor.atten(machine.ADC.ATTN_11DB)
# WiFi Configuration
def connect_wifi():
# Create network interface
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
# Attempt to connect to Wokwi-GUEST network
print("Attempting to connect to WiFi...")
sta_if.connect("Wokwi-GUEST", "")
# Wait for connection
while not sta_if.isconnected():
print("Connecting...")
utime.sleep(1)
# Print connection details
print("WiFi Connected!")
print("Network Config:", sta_if.ifconfig())
# Temperature Reading Function
def read_temperature():
# Read raw ADC value
raw_value = temp_sensor.read()
# Convert to temperature (0-100°C range)
temperature = (raw_value / 4095.0) * 100.0
return round(temperature, 2)
# MitM Attack Simulation
def perform_mitm_attack():
while True:
# Read original temperature
original_temp = read_temperature()
# Simulate temperature modification
modified_temp = original_temp + random.uniform(10, 25)
# Print attack details
print("------- MitM Attack Simulation -------")
print(f"Original Temperature: {original_temp}°C")
print(f"Modified Temperature: {modified_temp}°C")
print("-------------------------------------")
# Wait before next reading
utime.sleep(5)
# Main Execution
def main():
try:
# Connect to WiFi
connect_wifi()
# Start MitM attack simulation
perform_mitm_attack()
except Exception as e:
print("Error:", e)
machine.reset()
# Run the main function
main()