def __init__(self, host, port, multicast=False): CoAP.__init__(self, (host, port), multicast) '''Adding resources to the server along with the HTTP endpoints for the resource ''' self.add_resource('electricitymeters/', ElectricityResource()) self.add_resource('watermeters/', WaterResource()) self.add_resource('allmeters/', AllMetersResource()) self.add_resource('basic/', BasicResource()) print("CoAP server starting on " + host + ":" + str(port)) print(self.root.dump())
def __init__(self, host, port, multicast=False): CoAP.__init__(self, (host, port), multicast) self.add_resource('basic/', BasicResource()) self.add_resource('storage/', Storage()) self.add_resource('separate/', Separate()) self.add_resource('long/', Long()) self.add_resource('big/', Big()) self.add_resource('void/', voidResource()) self.add_resource('xml/', XMLResource()) self.add_resource('encoding/', MultipleEncodingResource()) self.add_resource('etag/', ETAGResource()) self.add_resource('child/', Child()) print "CoAP Server start on " + host + ":" + str(port) print self.root.dump()
def main(): # pragma: no cover ip = "0.0.0.0" port = 5683 multicast = False server = CoAPServer(ip, port, multicast) thing = [] with open('CoAPserverconf.txt') as csvfile: inputreader = csv.reader(csvfile) for row in inputreader: thing.append(row) for obj in thing: if obj[0] == 'c': resourceName = obj[1] foreignIP = obj[2] foreignPort = obj[3] foreignURI = obj[4] server.add_resource( resourceName, BasicResource("1", None, rt="interact", fIP=foreignIP, fPort=int(foreignPort), fPath=foreignURI)) print("CoAP device with URI " + resourceName + " added!") elif obj[0] == 'b': if (obj[1] == '2650'): tagHost = obj[2] try: tag = SensorTag(tagHost) tag.IRtemperature.enable() tag.humidity.enable() tag.barometer.enable() tag.accelerometer.enable() tag.magnetometer.enable() tag.gyroscope.enable() tag.battery.enable() tag.lightmeter.enable() server.add_resource('/temperature', SensortagResource(tag.IRtemperature)) server.add_resource('/humidity', SensortagResource(tag.humidity)) server.add_resource('/barometer', SensortagResource(tag.barometer)) server.add_resource('/accelerometer', SensortagResource(tag.accelerometer)) server.add_resource('/magnetometer', SensortagResource(tag.magnetometer)) server.add_resource('/gyroscope', SensortagResource(tag.gyroscope)) server.add_resource('/battery', SensortagResource(tag.battery)) server.add_resource('/lightmeter', SensortagResource(tag.lightmeter)) print("BLUETOOTH device type CC2650 added") except Exception as e: print "BLUETOOTH device not connected. Error code: ", e.code else: print("IMPROPER BLUETOOTH INFORMATION IN INPUT\n") else: print("UNKNOWN RESOURCE TYPE DECLARATION IN INPUT\n") server.root.dump print "awaiting PROBE..." try: server.listen(10) except KeyboardInterrupt: print "Server Shutdown" server.close() print "Exiting..."
def __init__(self, host, port): CoAP.__init__(self, (host, port)) self.add_resource('basic/', BasicResource())
def __init__(self, host, port): print("Server starting") CoAP.__init__(self, (host, port)) self.add_resource('basic/', BasicResource()) print("Server on, host IP: %s" % host)
def __init__(self, host, port): CoAP.__init__(self, (host, port)) self.add_resource("testing/", BasicResource())