Created
May 27, 2019 17:41
-
-
Save RuiSantosdotme/914ea499fad94da98f22ca5cf2885f37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you you are the best @RuiSantosdotme