import time
import requests
import RPi.GPIO as GPIO
ssid = "Wokwi-GUEST"
password = ""
api_url = "https://virtserver.swaggerhub.com/ABDULAHALI982/Access_Scan/1.0.0/get-user"
relay_pin = 16
relay_state = False
GPIO.setmode(GPIO.BCM)
GPIO.setup(relay_pin, GPIO.OUT)
GPIO.output(relay_pin, GPIO.LOW)
def make_get_request(uid):
url = f"{api_url}?uid={uid}"
try:
response = requests.get(url)
if response.status_code == 200:
print(f"API Response: {response.text}")
# You can add more logic here based on the response if needed
else:
print(f"Error in HTTP request. HTTP Response Code: {response.status_code}")
except Exception as e:
print(f"Error: {e}")
def toggle_relay():
global relay_state
relay_state = not relay_state
GPIO.output(relay_pin, relay_state)
def generate_random_uid():
uid = "A1254627"
return uid
def main():
# Connect to Wi-Fi
# Note: In a real-world scenario, you may want to use a more secure method for Wi-Fi credentials
print("Connecting to WiFi...")
# Add your Wi-Fi connection logic here
print("Connected to WiFi")
while True:
# Generate a random RFID UID for demonstration purposes
uid = generate_random_uid()
# Make the GET request
make_get_request(uid)
print(uid)
# Toggle relay based on the response
toggle_relay()
time.sleep(10) # Wait for 10 seconds before the next request
#if __name__ == "__main__":
time.sleep(0.1) # Wait for USB to become ready
main()