forked from fabaff/mqtt-panel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-messages.py
executable file
·37 lines (32 loc) · 1016 Bytes
/
test-messages.py
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
#!/usr/bin/env python
#
# test-messages.py - This script publish a random MQTT messages every 2 s.
#
# Copyright (c) 2013, Fabian Affolter <[email protected]>
# Released under the MIT license. See LICENSE file for details.
#
import random
import time
import mosquitto
timestamp = int(time.time())
print timestamp
broker = '127.0.0.1'
port = 1883
element = 'home'
areas = ['front', 'back', 'kitchen', 'basement', 'living']
entrances = ['door', 'window']
states = ['true', 'false']
print 'Messages are published on topic %s/#... -> CTRL + C to shutdown' \
% element
while True:
area = random.choice(areas)
if (area in ['basement', 'living']):
topic = element + '/' + area + '/temp'
message = random.randrange(0, 30, 1)
else:
topic = element + '/' + area + '/' + random.choice(entrances)
message = random.choice(states)
client = mosquitto.Mosquitto("mqtt-panel-test")
client.connect(broker)
client.publish(topic, message)
time.sleep(2)