-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources.py
49 lines (40 loc) · 1.38 KB
/
resources.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
#!/usr/bin/env python
from coapthon.resources.resource import Resource
from coapthon.server.coap import CoAP
import sys
# Temperature Threshold resource
class Threshold_T(Resource):
def __init__(self,name="Threshold",coap_server=None):
super(Threshold_T,self).__init__(name,coap_server,visible=True,observable=True,allow_children=True)
self.payload = ""
self.resource_type = "rt1"
self.content_type = "application/json"
self.interface_type = "if1"
def set_server(self, server):
self.server = server
# Return payload
def render_GET(self,request):
return self
# Set payload
def render_POST(self, request):
self.server.t_lim = float(request.payload)
res = self.init_resource(request, Threshold_T())
return res
# Pressure Threshold resource
class Threshold_P(Resource):
def __init__(self,name="Threshold",coap_server=None):
super(Threshold_P,self).__init__(name,coap_server,visible=True,observable=True,allow_children=True)
self.payload = ""
self.resource_type = "rt1"
self.content_type = "application/json"
self.interface_type = "if1"
def set_server(self, server):
self.server = server
# Return payload
def render_GET(self,request):
return self
# Set payload
def render_POST(self, request):
self.server.p_lim = float(request.payload)
res = self.init_resource(request, Threshold_P())
return res