-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiotsimulator_charles.py
70 lines (53 loc) · 1.46 KB
/
iotsimulator_charles.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
#!/usr/bin/python
import sys
import datetime
import random
import string
# Set number of simulated messages to generate
if len(sys.argv) > 1:
numMsgs = int(sys.argv[1])
else:
numMsgs = 1
# Fixed values
guidStr = "0-ZZZ12345678"
destinationStr = "0-AAA12345678"
formatStr = "urn:example:sensor:roller-coaster-data"
# Choice for random letter
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
iotmsg_header = """\
{
"guid": "%s",
"destination": "%s", """
iotmsg_eventTime = """\
"eventTime": "%sZ", """
iotmsg_payload ="""\
"payload": {
"format": "%s", """
iotmsg_data ="""\
"data": {
"g-force": %.2f,
"angular-velocity": %.2f,
"barometric-pressure": %.2f
}
}
}"""
##### Generate JSON output:
print "["
dataElementDelimiter = ","
for counter in range(0, numMsgs):
randInt = random.randrange(0, 9)
randLetter = random.choice(letters)
print iotmsg_header % (guidStr+str(randInt)+randLetter, destinationStr)
today = datetime.datetime.today()
datestr = today.isoformat()
print iotmsg_eventTime % (datestr)
print iotmsg_payload % (formatStr)
# Generate a random floating point number
randTemp = random.uniform(0.0, 40.0) + 60.0
randGforce = random.uniform(0.0, 7.0)
randomAngularVelocity = random.uniform(0.0, 1.0)
randomPressure = random.uniform(1000, 1200)
if counter == numMsgs - 1:
dataElementDelimiter = ""
print iotmsg_data % (randGforce, randomAngularVelocity, randomPressure) + dataElementDelimiter
print "]"