Ejemplo n.º 1
0
    def __init__(
        self,
        baseObject=None,
        port=None
    ):  # FIXME if no baseObject given, create a default base object

        if port == None:
            self._port = 5683  # IETF default port for coap://
        else:
            self._port = port

        if baseObject == None:
            from SmartObject.SmartObject import SmartObject
            self._baseObject = SmartObject()
        else:
            self._baseObject = baseObject

        self.resources = self._baseObject.resources

        self._host = gethostname()
        self._baseObject.Properties.update(
            {'coapService': 'coap://' + self._host + ':' + repr(self._port)})

        self._coapHandler = CoapRequestHandler(self._baseObject)
        self._coapServer = COAPServer(self._host, self._port,
                                      self._coapHandler)
        print 'CoAP Service started at', baseObject.Properties.get(
            'coapService')
Ejemplo n.º 2
0
    def __init__(self, baseObject=None, port=None):

        if port == None:
            self._port = 8000
        else:
            self._port = port  # default port 8000

        if baseObject == None:
            from SmartObject.SmartObject import SmartObject
            self._baseObject = SmartObject()
        else:
            self._baseObject = baseObject

        self.resources = self._baseObject.resources

        if port != None or baseObject == None:
            self.start()
Ejemplo n.º 3
0
'''
from SmartObject.SmartObject import SmartObject
from SmartObject.Description import Description
from SmartObject.ObservableProperty import ObservableProperty
from SmartObject.Observers import Observers
from SmartObject.PropertyOfInterest import PropertyOfInterest
from rdflib.term import Literal, URIRef
from rdflib.namespace import RDF, RDFS, XSD, OWL
from SmartObjectService import SmartObjectService
from time import sleep
import sys


if __name__ == '__main__' :
    # print 'path = ', sys.path
    baseObject = SmartObject() # create a Smart Object to serve as the base container for other Smart Objects and resources
    server = SmartObjectService(baseObject) # make an instance of the service, baseObject is the object root
    server.start(8000) # forks a server thread to listen on port 8000
    print 'httpd started at', baseObject.Properties.get('httpService')

    # create the weather station resource template
    # first the description 
    baseObject.Description.set((URIRef('sensors/rhvWeather-01'), RDFS.Class, Literal('SmartObject')))
    baseObject.Description.set((URIRef('sensors/rhvWeather-01'), RDFS.Resource, Literal('SensorSystem')))
    baseObject.Description.set((URIRef('sensors/rhvWeather-01'), RDF.type, Literal('WeatherSensor')))
    
    # sensors resource under the baseObject for all sensors    
    sensors = baseObject.create({'resourceName': 'sensors',\
                                 'resourceClass': 'SmartObject'}) # top level object container for sensors, default class is SmartObject
    #weather resource under sensors for the weather sensor    
    weather = sensors.create({'resourceName': 'rhvWeather-01', \