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()

coapClient.stop()
'''initialise variable for DataUtil class'''

data = DataUtil()
#ip/ or hostname direct
host = '127.0.0.1'  #config.getProperty(ConfigConst.COAP_DEVICE_SECTION, ConfigConst.HOST_KEY)
#port number initialized
port = 5683  #int(config.getProperty(ConfigConst.COAP_DEVICE_SECTION, ConfigConst.PORT_KEY))
#equivalent to channel in mqtt
path = 'temperature'
#instance variable for SensorData class
sensorData = SensorData()

#add new sensordata value
sensorData.addvalue(20.00)
#call the Coapclient connector
coapClient_obj = CoapClientConnector(host, port, path)
'''ping request'''
coapClient_obj.ping()
'''get request'''
coapClient_obj.get()
'''post request'''
coapClient_obj.post(data.tojsonfromSensorData(sensorData))
'''add new value to sensor data'''
sensorData.addvalue(15.00)
'''put request'''
coapClient_obj.put(data.tojsonfromSensorData(sensorData))
'''delete request'''
coapClient_obj.delete()
'''stop the Coap client'''
coapClient_obj.stop()