import network
import time
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!")
print('network config:', sta_if.ifconfig())
import urequests as requests
import json
import random
from machine import Pin
HTTP_HEADERS = {'Content-Type': 'application/json'}
THINGSPEAK_WRITE_API_KEY = "MYLRJK1W99PHNVEX"
sensor =Pin(15,Pin.IN).value
print(sensor)
data = {'field2':sensor}
while True:
request = requests.post('http://api.thingspeak.com/update?api_key=' +THINGSPEAK_WRITE_API_KEY,json = data,
headers = HTTP_HEADERS )
request.close()
time.sleep(0.1)