From efba1814923649937813ae287ba2b01c9d58d8cc Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Wed, 24 Jan 2024 15:23:11 -0500 Subject: [PATCH] initialize file, test wifi connection out with led to show if connected --- Scripts/discord-webhook.py | 15 ++++++------ Scripts/network-scan.py | 4 ++++ main.py | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 Scripts/network-scan.py create mode 100644 main.py diff --git a/Scripts/discord-webhook.py b/Scripts/discord-webhook.py index 860beef..280bc85 100644 --- a/Scripts/discord-webhook.py +++ b/Scripts/discord-webhook.py @@ -1,5 +1,6 @@ import network -import urequests as requests #dependency faked as another dependency ig +import requests +# import urequests as requests #dependency faked as another dependency ig url = "https://discord.com/api/webhooks/1199545130378608650/UyJj0e-YuSlmVZD87zaHitXZLC55RP6LVBUv3nt9ZWr6d4AGzSGKZ-zI6V_VwA6I4qSq" #webhook url, from here: https://i.imgur.com/f9XnAew.png @@ -11,12 +12,12 @@ data = { #leave this out if you dont want an embed #for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object -data["embeds"] = [ - { - "description" : "Testing for temps", - "title" : "Tent Temp=5000c" - } -] +# data["embeds"] = [ +# { +# "description" : "Testing for temps", +# "title" : "Tent Temp=5000c" +# } +# ] result = requests.post(url, json = data) diff --git a/Scripts/network-scan.py b/Scripts/network-scan.py new file mode 100644 index 0000000..c533ad5 --- /dev/null +++ b/Scripts/network-scan.py @@ -0,0 +1,4 @@ +import network +wlan = network.WLAN(network.STA_IF) +wlan.active(True) +print(wlan.scan()) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..77f9378 --- /dev/null +++ b/main.py @@ -0,0 +1,47 @@ +from machine import Pin +import time +import network +import urequests as requests +from secrets import secrets + +# Load login data from different file for security! +# ssid = secrets['ssid'] +# pw = secrets['pw'] + +# Initialize pins +contactorLights = Pin(18, Pin.OUT) +led = machine.Pin("LED", machine.Pin.OUT) + + +led.low() +contactorLights.low() # sets to lowest setting 0 first. + +contactorLights.toggle() # Toggle contactor on for testing + +# Network connection going through +wifi = network.WLAN(network.STA_IF) +wifi.active(True) # must capitalize boolean statements! +wifi.connect(secrets['ssid'], secrets['password']) + +print(wlan.ifconfig()) + +#Proof connected +led.on() +print('Connected to Wi-Fi network') +time.sleep(5) +led.off() + +# If disconnect will flash light +while wifi.isconnected() == False: + led.on() + time.sleep(0.5) + led.off() + time.sleep(0.5) + +# think the while loop will hold the next line from running, we will see + +# while True: +# led.toggle() +# utime.sleep(0.2) + +# Need to log time accurately. Connect to internet with wifi and set time. Start logging. Also need temp probes and how to pull temps \ No newline at end of file