Skip to content

Instantly share code, notes, and snippets.

@RuiSantosdotme
Created May 27, 2019 17:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuiSantosdotme/914ea499fad94da98f22ca5cf2885f37 to your computer and use it in GitHub Desktop.
Save RuiSantosdotme/914ea499fad94da98f22ca5cf2885f37 to your computer and use it in GitHub Desktop.
# Complete project details at https://RandomNerdTutorials.com
import network
import urequests
import esp
esp.osdebug(None)
import gc
gc.collect()
ssid = 'REPLACE_WITH_YOUR_SSID'
password = 'REPLACE_WITH_YOUR_PASSWORD'
api_key = 'REPLACE_WITH_YOUR_THING_SPEAK_API_KEY'
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
while station.isconnected() == False:
pass
print('Connection successful')
print(station.ifconfig())
temp = '12'
hum = '70'
sensor_readings = {'field1':temp, 'field2':hum}
print(sensor_readings)
request_headers = {'Content-Type': 'application/json'}
request = urequests.post(
'http://api.thingspeak.com/update?api_key=' + api_key,
json=sensor_readings,
headers=request_headers)
print(request.text)
request.close()
@Koukou2307
Copy link

thank you you are the best @RuiSantosdotme

@mateunix
Copy link

mateunix commented Mar 6, 2022

Thank you! Helped me a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment