-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_demo
More file actions
30 lines (23 loc) · 958 Bytes
/
python_demo
File metadata and controls
30 lines (23 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import paho.mqtt.publish as publish
from time import sleep
import random
channelID = "XXXXXX"
apiKey = "XXXXXXXXXXX"
useUnsecuredTCP = False
useUnsecuredWebsockets = False
topic = "channels/" + channelID + "/publish/" + apiKey
while(True):
# calcola le variabili v1,v2,v3,v4,v5,v6,v7,v8
# demo che genera numeri casuali, tu metti le variabili che ti servono ovviamente
v1 = random.randint(18,25)
v2 = random.randint(50,70)
v3 = random.randint(5,30)
v4 = random.randint(0,100)
v5 = random.randint(0,1)
v6 = random.randint(0,1)
v7 = random.randint(0,10)
v8 = random.uniform(1,2)
print(v1,v2,v3,v4,v5,v6,v7,v8)
messaggio = "field1=" + str(v1) + "&field2=" + str(v2) + "&field3=" + str(v3) + "&field4=" + str(v4) + "&field5=" + str(v5) + "&field6=" + str(v6) + "&field7=" + str(v7) + "&field8=" + str(v8)
publish.single(topic, payload=messaggio, hostname="mqtt.thingspeak.com", port=1883, tls=None, transport="tcp")
sleep(60)