-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbs.py
83 lines (74 loc) · 2.48 KB
/
sbs.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
# Script to generate simulated IoT device parameters data
import json
import random
import datetime
import boto3
import time
deviceNames = ['SBS01', 'SBS02', 'SBS03', 'SBS04', 'SBS05']
iot = boto3.client('iot-data');
# generate Flow values
def getFlowValues():
data = {}
data['deviceValue'] = random.randint(60, 100)
data['deviceParameter'] = 'Flow'
data['deviceId'] = random.choice(deviceNames)
data['dateTime'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return data
# generate Temperature values
def getTemperatureValues():
data = {}
data['deviceValue'] = random.randint(15, 35)
data['deviceParameter'] = 'Temperature'
data['deviceId'] = random.choice(deviceNames)
data['dateTime'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return data
# generate Humidity values
def getHumidityValues():
data = {}
data['deviceValue'] = random.randint(50, 90)
data['deviceParameter'] = 'Humidity'
data['deviceId'] = random.choice(deviceNames)
data['dateTime'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return data
# generate Sound values
def getSoundValues():
data = {}
data['deviceValue'] = random.randint(100, 140)
data['deviceParameter'] = 'Sound'
data['deviceId'] = random.choice(deviceNames)
data['dateTime'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return data
# Generate each parameter's data input in varying proportions
while True:
time.sleep(1)
rnd = random.random()
if (0 <= rnd < 0.20):
data = json.dumps(getFlowValues())
print data
response = iot.publish(
topic='/sbs/devicedata/flow',
payload=data
)
elif (0.20<= rnd < 0.55):
data = json.dumps(getTemperatureValues())
print data
response = iot.publish(
topic='/sbs/devicedata/temperature',
payload=data
)
elif (0.55<= rnd < 0.70):
data = json.dumps(getHumidityValues())
print data
response = iot.publish(
topic='/sbs/devicedata/humidity',
payload=data
)
else:
data = json.dumps(getSoundValues())
print data
response = iot.publish(
topic='/sbs/devicedata/sound',
payload=data
)