You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
984 B
31 lines
984 B
import requests
|
|
import random
|
|
import time
|
|
|
|
WRITE_API_KEY = "VÁŠ_WRITE_API_KEY"
|
|
SEND_TIME = 15
|
|
|
|
def odeslat_data(hodnota):
|
|
url = f"https://api.thingspeak.com/update?api_key={WRITE_API_KEY}&field1={hodnota}"
|
|
try:
|
|
response = requests.get(url)
|
|
if response.status_code == 200:
|
|
if response.text == "0":
|
|
print("ThingSpeak odmítl zápis")
|
|
else:
|
|
print("Úspěšně odesláno")
|
|
else:
|
|
print(f"Chyba serveru: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"Chyba:{e}")
|
|
|
|
if __name__ == "__main__":
|
|
print("Připravuji odesílaní dat, pro ukonční použíjte CTRL+C")
|
|
try:
|
|
while True:
|
|
nahodne_cislo = random.randint(10,30)
|
|
odeslat_data(nahodne_cislo)
|
|
print(f"Čekám {SEND_TIME} vteřin na další odeslání")
|
|
time.sleep(SEND_TIME)
|
|
except KeyboardInterrupt:
|
|
print("\nProgram ukončen uživatelem")
|