-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpub.py
More file actions
53 lines (42 loc) · 1.3 KB
/
pub.py
File metadata and controls
53 lines (42 loc) · 1.3 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#-*- coding: utf-8 -*-
import paho.mqtt.publish as publish
import threading
import time
from time import ctime,sleep
import json
#hostname='162.105.80.59'
# hostname='192.168.199.231'
hostname='127.0.0.1'
device_json={"secretkey":"93cf82461c324858961b6cc70fc5033d","deviceprofile":{"devicename":"hhhh","IP":"1.1.1.1","location":"23","tags":"33","latitude":"33","longitude":"22","sensors":[{"name":"22","sid":"22","channels":[{"name":"22","type":"22","unit":"22","samplingperiod":"22"}]},{"name":"22","sid":"22","channels":[{"name":"22","type":"22","unit":"22","samplingperiod":"22"}]}],"actuators":[{"name":"22name"}]}}
def pub_TEST():
while 1:
msg=[{
'topic':"TEST",
'payload':" This just is the content of TEST--timestamp:"+ctime(),
'qos':0,
'retain':False
}]
publish.multiple(msg,hostname=hostname)
sleep(5)
pass
def pub_SB():
while 1:
device_json['deviceprofile']['devicename']='devicename'+str(int(time.time()))
msg=[{
'topic':"ICS",
'payload':json.dumps(device_json),
'qos':0,
'retain':False
}]
publish.multiple(msg,hostname=hostname)
print json.dumps(device_json)+'\n'
sleep(5)
pass
if __name__ == "__main__":
#threads=[]
t1=threading.Thread(target=pub_TEST)
#threads.append(t)
#t.setDaemon(True)
t1.start()
t2=threading.Thread(target=pub_SB)
t2.start()