Esempio n. 1
0
 def setUp(self):
     host = '127.0.0.1'
     #port number to connect
     port = 5683
     #resource uri
     path = 'temperature'
     self.coap_client = CoapClientConnector(host, port, path)
Esempio n. 2
0
class DeviceDataManager(object):
    '''
    The manager for the device responsible for creating 
    the CoapClientConnector to be used for this Module
    Also responsible for starting the TempSensorAdaptor thread
    '''
    #Instantiate the modules
    coapClientConnector = CoapClientConnector()
    tempSensorAdaptor = TempSensorAdaptor()

    #Empty constructor as we do not want to initialize anything during instantiation
    def __init__(self):
        '''
        Constructor
        '''  
    """
    Method that passes its own reference CoapClientConnector to TempSensorAdaptor
    and starts the TempSensorAdaptor's thread so that it can get SensorData from
    the TempSensorAdaptorTask
    """
    def run(self):
        
        #Set the CoapClientConnector of the TempSensorAdaptor to the current CoapClientConnector reference
        self.tempSensorAdaptor.setCoapClient(self.coapClientConnector)
        
        #Enable the fetcher of adaptor
        self.tempSensorAdaptor.enableFetcher = True
        
        #Start
        self.tempSensorAdaptor.start()

        #will always return true as no error can occur here
        return True
Esempio n. 3
0
	def setUp(self):

		"""
		Initialize TempSensorAdaptor, TempSensorAdaptorTask, DeviceDataManager 
		and CoapClientConnector (Modules in Module7)
		"""
		self.tempSensorAdaptor 		= 		TempSensorAdaptor()
		self.tempSensorAdaptorTask	= 		TempSensorAdaptorTask()
		self.deviceDataManager 		= 		DeviceDataManager()
		self.coapClientConnector 	= 		CoapClientConnector()
Esempio n. 4
0
    def setUp(self):

        #getting the host data
        host = ConfigUtil().getProperty(ConfigConst.COAP_DEVICE_SECTION,
                                        ConfigConst.HOST_KEY)

        #port number to connect
        port = int(ConfigUtil().getProperty(ConfigConst.COAP_DEVICE_SECTION,
                                            ConfigConst.PORT_KEY))

        #resource uri
        path = 'Temperature Resource'

        #connecting to my CoAp client connector
        self.coap_client = CoapClientConnector(host, port, path)
'''
@author: Mengfan Shi
'''
from labs.module07.CoapClientConnector import CoapClientConnector
'''
connect to local host
'''
host = "coap://127.0.0.1:5683/temp"
test = CoapClientConnector(host)
test.test()
        
        
@author: sk199
'''
from labs.module07.CoapClientConnector import CoapClientConnector
from labs.common.SensorData import SensorData
from labs.module07.TempSensorAdaptorTask import TempSensorAdaptorTask
from labs.common.DataUtil import DataUtil
import logging

if __name__ == '__main__':
    resource = 'temp'
    #payload = "for test"

    logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',
                        level=logging.DEBUG)
    print('------->')
    logging.info("Connecting to Coap Server...")
    coapClientConnector = CoapClientConnector()
    tempSensorData = SensorData()
    temp = TempSensorAdaptorTask()
    dataUtil = DataUtil()

    tempSensorData.addValue(temp.getTemperature())
    payload = dataUtil.toJsonFromSensorData(tempSensorData)
    print("Json Before issuing the request...")
    logging.info(payload)
    print('------->')
    coapClientConnector.postRequest(resource, payload)
    coapClientConnector.putRequest(resource, payload)
    coapClientConnector.getRequest(resource)
    coapClientConnector.deleteRequest(resource)
run a number of tests, then exit.
'''
config = ConfigUtil('../../../config/ConnectedDevicesConfig.props')
config.loadConfig()

data = DataUtil()

host = config.getProperty(ConfigConst.ConfigConst.COAP_DEVICE_SECTION, ConfigConst.ConfigConst.HOST_KEY)
port = int(config.getProperty(ConfigConst.ConfigConst.COAP_DEVICE_SECTION, ConfigConst.ConfigConst.PORT_KEY))
path = 'temperature'

sensor = SensorData("Temperature",0.0,30.0)
sensor.addValue(4.0)
print(str(sensor))

coapClient = CoapClientConnector(host, port, path)

coapClient.ping()
json_data = data.SensorDataToJson(sensor)
print("json"+json_data)

#coapClient.get() #Get will respond with NOT_FOUND since data object on server is not initialized
coapClient.post((json_data)) #Post JSON to server
coapClient.get()

sensor.addValue(5.00)
coapClient.put(data.SensorDataToJson(sensor)) #Update resource on the server
coapClient.get()

coapClient.delete() #Delete resource
coapClient.get()
 def setUp(self):
     self.ccc = CoapClientConnector()
     pass
 def __init__(self):
     self.sensorAdaptor = MultiSensorAdaptor()
     self.ccc = CoapClientConnector()
 def coapclient(self):
     host = '127.0.0.1'
     port = 5683
     #invoke coapclientconnector to connect the server
     coapClientConnector = CoapClientConnector(host, port)
     coapClientConnector.runTests("temp")