config = {} execfile('sampleProp.conf', config) #--------------------------------------------------------------------------- def getTemp(): th = TemperHandler() devs = th.get_devices() t = devs[0].get_temperatures() return t[0]['temperature_c'] #-------------------------------------------------------------------------- # In this example, we demonstrate how data from a simulated device generating # random numbers can be directed to graphite data center component using Liota. # The program illustrates the ease of use Liota brings to IoT application developers. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to an alternate data center component (e.g. data lake for analytics) # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) tempMetric = graphite.create_metric(graphite_gateway, 'Temperature C', unit=None, sampling_interval_sec=10, aggregation_size=1, sampling_function=getTemp) tempMetric.start_collecting()
network_bits_recieved.start_collecting() else: print "vROPS resource not registered successfully" # Here we are showing how to create a device object, registering it in vrops, and setting properties on it # Since there are no attached devices are as simulating one by considering RAM as separate from the gateway # The agent makes possible many different data models # arguments: # device name # Read or Write # another Resource in vrops of which the should be the child of a parent-child relationship among Resources ram = RAM(config['Device1Name'], 'Read', gateway) vrops_device = vrops.register(ram) # note that the location of this 'device' is different from the location of the gateway. It's not really different # but just an example of how one might create a device different from the gateway if vrops_device.registered: vrops.set_properties(vrops_device, config['Device1PropList']) mem_free = vrops.create_metric(vrops_device, "Memory_Free", unit=None, sampling_interval_sec=10, sampling_function=read_mem_free) mem_free.start_collecting() else: print "vROPS resource not registered successfully" # Sending data to an alternate data center component (e.g. data lake for analytics) # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) content_metric = graphite.create_metric(graphite_gateway, config['GraphiteMetric'], unit=None, sampling_interval_sec=10, aggregation_size=2, sampling_function=simulated_device) content_metric.start_collecting()
def getTempKelvin(): temp = getTemp() temp_kelvin = temp.to('kelvin') return temp_kelvin.magnitude # -------------------------------------------------------------------------- # In this example, we demonstrate how data from a simulated device generating # random numbers can be directed to graphite data center component using Liota. # The program illustrates the ease of use Liota brings to IoT application developers. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to an alternate data center component (e.g. data lake for analytics) # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) temp_metric_degC = graphite.create_metric(graphite_gateway, 'temperature.degC', unit=ureg.degC, sampling_interval_sec=33, aggregation_size=1, sampling_function=getTempDegC) temp_metric_degC.start_collecting() temp_metric_degF = graphite.create_metric(graphite_gateway, 'temperature.degF', unit=ureg.degF, sampling_interval_sec=62, aggregation_size=1, sampling_function=getTempDegF) temp_metric_degF.start_collecting() temp_metric_kelvin = graphite.create_metric(graphite_gateway, 'temperature.kelvin', unit=ureg.kelvin, sampling_interval_sec=125, aggregation_size=1, sampling_function=getTempKelvin) temp_metric_kelvin.start_collecting()
# Here we are showing how to create a device object, registering it in vrops, and setting properties on it # Since there are no attached devices are as simulating one by considering RAM as separate from the gateway # The agent makes possible many different data models # arguments: # device name # Read or Write # another Resource in vrops of which the should be the child of a parent-child relationship among Resources ram = RAM(config['Device1Name'], 'Read', gateway) vrops_device = vrops.register(ram) if vrops_device.registered: # note that the location of this 'device' is different from the location of the gateway. It's not really different # but just an example of how one might create a device different from the gateway vrops.set_properties(vrops_device, config['Device1PropList']) mem_free = vrops.create_metric(vrops_device, "Memory_Free", unit=None, sampling_interval_sec=10, sampling_function=read_mem_free) mem_free.start_collecting() else: print "vROPS resource not registered successfully" # Sending data to an alternate data center component (e.g. data lake for analytics) # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) content_metric = graphite.create_metric(graphite_gateway, config['GraphiteMetric'], unit=None, sampling_interval_sec=10, aggregation_size=2, sampling_function=simulated_device) content_metric.start_collecting()
config = {} execfile('sampleProp.conf', config) comms_channel = Queue.Queue() # channel between device and a udm used for a metric #simulates a device putting data into a comms channel at random intervals def simulated_event_device(write_channel): while(True): time.sleep(random.randint(1,10)) write_channel.put(random.randint(1,300)) # starting the simulated device thread.start_new_thread(simulated_event_device, (comms_channel,)) def udm1(): return comms_channel.get(block=True) #--------------------------------------------------------------------------- # In this example, we demonstrate how an event stream of data can be directed to graphite # data center component using Liota by setting sampling_interval_sec parameter to zero. if __name__ == '__main__': # Sending data to a data center component # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) content_metric = graphite.create_metric(gateway, 'event', unit=None, sampling_interval_sec=0, aggregation_size=1, sampling_function=udm1) content_metric.start_collecting()
10 * ureg.kg / ureg.m ** 3 ).to(ureg.newton), speed ).to(ureg.watt) power = power_acceleration + power_gravity + power_resistance return power.to(ureg.watt).magnitude #--------------------------------------------------------------------------- # In this example, we demonstrate how data from a simulated device generating # random physical variables can be directed to graphite data center component # using Liota. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to a data center component # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) bike_speed = graphite.create_metric(graphite_gateway, "model.bike.speed", unit=(ureg.m / ureg.sec), sampling_interval_sec=5, sampling_function=get_bike_speed) bike_speed.start_collecting() bike_power = graphite.create_metric(graphite_gateway, "model.bike.power", unit=ureg.watt, sampling_interval_sec=5, sampling_function=get_bike_power) bike_power.start_collecting()
# getting values from conf file config = {} execfile('sampleProp.conf', config) #--------------------------------------------------------------------------- def getTemp(): th = TemperHandler() devs = th.get_devices() t = devs[0].get_temperatures() return t[0]['temperature_c'] #-------------------------------------------------------------------------- # In this example, we demonstrate how data from a simulated device generating # random numbers can be directed to graphite data center component using Liota. # The program illustrates the ease of use Liota brings to IoT application developers. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to an alternate data center component (e.g. data lake for analytics) # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) tempMetric = graphite.create_metric(gateway, 'Temperature C', unit=None, sampling_interval_sec=10, aggregation_size=1, sampling_function=getTemp) tempMetric.start_collecting()
comms_channel = Queue.Queue() # channel between device and a udm used for a metric #simulates a device putting data into a comms channel at random intervals def simulated_event_device(write_channel): while(True): time.sleep(random.randint(1,10)) write_channel.put(random.randint(1,300)) # starting the simulated device thread.start_new_thread(simulated_event_device, (comms_channel,)) def udm1(): return comms_channel.get(block=True) #--------------------------------------------------------------------------- # In this example, we demonstrate how an event stream of data can be directed to graphite # data center component using Liota by setting sampling_interval_sec parameter to zero. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to a data center component # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) content_metric = graphite.create_metric(graphite_gateway, 'event', unit=None, sampling_interval_sec=0, aggregation_size=1, sampling_function=udm1) content_metric.start_collecting()
thermistor_model.get_c2(), thermistor_model.get_c3(), get_rx( thermistor_model.get_u(), thermistor_model.get_r0(), thermistor_model.get_ux() ) ).to(ureg.degC) return temper.magnitude # return a scalar for compatibility #--------------------------------------------------------------------------- # In this example, we demonstrate how data from a simulated device generating # random physical variables can be directed to graphite data center component # using Liota. if __name__ == '__main__': gateway = Dk300(config['Gateway1Name']) # Sending data to a data center component # Graphite is a data center component # Socket is the transport which the agent uses to connect to the graphite instance graphite = Graphite(Socket(config['GraphiteIP'], config['GraphitePort'])) graphite_gateway = graphite.register(gateway) thermistor_temper = graphite.create_metric(graphite_gateway, "model.thermistor.temperature", unit=ureg.degC, sampling_interval_sec=5, sampling_function=get_thermistor_temperature) thermistor_temper.start_collecting()