-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclouddata_server.py
43 lines (35 loc) · 1.07 KB
/
clouddata_server.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
#!/usr/bin/python
#============================ define ==========================================
DFLT_PORT = 8080
INFLUX_HOST = 'localhost'
INFLUX_PORT = 8086
INFLUX_DBNAME = 'grafana'
#============================ imports =========================================
from bottle import post,request,run
import influxdb
print 'CloudData Server'
influxClient = influxdb.client.InfluxDBClient(
host = INFLUX_HOST,
port = INFLUX_PORT,
database = INFLUX_DBNAME,
)
@post('/oap')
def root_post():
mac = request.json['mac']
temperature = request.json['temperature']
influxClient.write_points(
[
{
"measurement": "temperature",
"tags": {
"mac": mac,
},
"fields": {
"value": temperature,
}
},
]
)
print 'received mac={0} temperature={1}'.format(mac,temperature)
print 'Server started on port {0}'.format(DFLT_PORT)
run(host='0.0.0.0', port=DFLT_PORT, quiet=True)