輸入
選取
輸入
選取
輸入
Copy
https://maker.ifttt.com/trigger/ESP32_message/with/key/e2L........asdf
?value1=10&value2=20&value3=30
import network
import time
import urequests as requests
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Connected!")
# Define the API key and URL for the GET request
api_key = ".................your_key................"
ifttt_url = "https://maker.ifttt.com/trigger/ESP32_message/with/key/" + api_key\
+"?value1=10&value2=20&value3=30"
res = requests.get(url=ifttt_url)
print(res.text)
import network, time
wlan = network.WLAN(network.STA_IF) # Initializes the station interface
wlan.active(True) # Activates the WLAN interface
ssid = 'CSIE_C306'
passwd = '@ndhuc306'
connected = wlan.isconnected() # Check if the connection was successful
if not connected: # if it is not connected
print(f'Trying to connect to {ssid}') # Display a message indicating an attempt to connect
wlan.connect(ssid, passwd) # Attempt to connect to the Wi-Fi network again
for _ in range(100): # Try to connect 100 times, waiting 0.1 seconds each time
connected = wlan.isconnected() # Check if the connection was successful
if connected:
break # Break out of the loop if connected
time.sleep(0.1) # Wait for 0.1 seconds before checking again
print('.', end='') # Print progress dots to indicate ongoing connection attempts
if connected: # If connected successfully
# Display successful connection and network configuration
print(f'\nConnected to ssid {ssid}. Network config: {wlan.ifconfig()}')
else: # If the connection failed
print(f'\nFailed. Not Connected to: {ssid}') # Display a failure message
import urequests
# Define the API key and URL for the GET request
api_key = "....................your_key....................."
ifttt_url = "https://maker.ifttt.com/trigger/ESP32_message/with/key/" + api_key\
+"?value1=10&value2=20&value3=30"
res = urequests.get(url=ifttt_url)
print(res.text)