-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice-simulator.py
More file actions
38 lines (30 loc) · 1.02 KB
/
Copy pathdevice-simulator.py
File metadata and controls
38 lines (30 loc) · 1.02 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
"""
Python script for simulating sensor data feed. This can be:
- Raspberry Pi
- BalenaOS
- MicroPython
- Cloud-based services
"""
import random
import requests
import pycristoforo as pyc
# Replace with your API products url (get from Datacake)
url = "YOURCUSTOMDATACAKEAPIURLHERE"
# Settings
number_of_sensors = 100
serial_prefix = "level00"
# Generate real GPS coords for devices using pycristoforo
country = pyc.get_shape("Germany")
points = pyc.geoloc_generation(country, number_of_sensors, "Germany")
for device in range(1, number_of_sensors + 1):
payload = {
"temperature": round(random.uniform(20, 25), 2),
"battery": round(random.uniform(2, 4), 2),
"signal": random.randrange(70, 99),
"level": random.randrange(20, 90),
"location": "(" + str( points[device-1]["geometry"]["coordinates"][1] ) + "," + str( points[device-1]["geometry"]["coordinates"][0] ) +")",
"serial": serial_prefix + str(device)
}
print(payload)
r = requests.post(url, json=payload)
print(r)