forked from connectIOT/iottoolkit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinimalServer.py
40 lines (29 loc) · 1.47 KB
/
MinimalServer.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
'''
Created on Dec 7, 2013
Minimal service creation, base object auto-created by the first server,
passed to constructor of second server
@author: mjkoster
'''
from iottoolkit.interfaces.HttpObjectService import HttpObjectService
from iottoolkit.interfaces.CoapObjectService import CoapObjectService
from time import sleep
#workaround to register rdf JSON plugins
import rdflib
from rdflib.plugin import Serializer, Parser
rdflib.plugin.register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer')
rdflib.plugin.register('json-ld', Parser, 'rdflib_jsonld.parser', 'JsonLDParser')
rdflib.plugin.register('rdf-json', Serializer, 'rdflib_rdfjson.rdfjson_serializer', 'RdfJsonSerializer')
rdflib.plugin.register('rdf-json', Parser, 'rdflib_rdfjson.rdfjson_parser', 'RdfJsonParser')
if __name__ == '__main__' :
# make an empty instance of a SmartObject shared by 2 interfaces,
# CoAP and HTTP, default object root and default ports 5683 and 8000
# CoAP service makes the base object and it is passed to the http service constructor
baseObject = HttpObjectService( CoapObjectService().baseObject ).baseObject
# emulate the .well-known/core interface
baseObject.create({'resourceName': '.well-known','resourceClass': 'SmartObject'},\
).create({'resourceName': 'core','resourceClass': 'LinkFormatProxy'})
try:
# register handlers etc.
while 1: sleep(1)
except KeyboardInterrupt: pass
print 'got KeyboardInterrupt'