def __init__(self, hub_serial, hub_port, thermal_channel): self.sensor = TemperatureSensor() self.sensor.setHubPort(hub_port) self.sensor.setChannel(thermal_channel) self.sensor.setDeviceSerialNumber(hub_serial) self.sensor.openWaitForAttachment(5000) self.previous_temp = 0 self.thermal_channel = thermal_channel
def attachSensor(self): ''' Connects sensor to application. Sets the "channel" parameter which is the handle to the phidget ''' self.channel = TemperatureSensor() self.channel.setDeviceSerialNumber(self.deviceSN) self.channel.setChannel(0) self.channel.openWaitForAttachment(5000) print("***** {} Sensor Attached *****".format(self.sensorName)) self.attached = True self.channel.setDataInterval(self.dataInterval)
def attachSensor(self): ''' Connects the sensor to the application ''' self.channel = TemperatureSensor() self.channel.setDeviceSerialNumber(self.deviceSN) self.channel.setChannel(self.channelNo) self.channel.openWaitForAttachment(100) print("\n***** {} Sensor Attached *****".format(self.sensorName)) self.attached = True self.channel.setThermocoupleType(self.sensorType) self.channel.setDataInterval(self.dataInterval) self.sensorUnits = "degrees C"
def configure_phidget(phidget): """ :param serial: Serial Number as int :param hub: Is this connected to a hub? 1:Yes, 0:No :param channel: Channel 0 is Thermocouple. 1 is Board. :return: configured phidget """ phidget_channels = [] for index, sensor in enumerate(phidget["channels"]): ch = TemperatureSensor() ch.setDeviceSerialNumber(phidget["serial"]) ch.setHubPort(phidget["hub"]) ch.setChannel(phidget["channel"][index]) ch.setOnAttachHandler(onAttachHandler) phidget_channels.append((ch, sensor)) return phidget_channels
def __init__(self, hub_port=0, hub_channel=1, serial_number=-1, use_hub=False): self.use_hub = use_hub self.hub_port = hub_port self.hub_channel = hub_channel try: self.ch = TemperatureSensor() self.ch.setDeviceSerialNumber(serial_number) if use_hub: self.ch.setHubPort(hub_port) self.ch.setChannel(hub_channel) print('HUB, PORT:%d CHANNEL: %d' % (hub_port, hub_channel)) except PhidgetException as e: sys.stderr.write( "Runtime Error -> Creating TemperatureSensor: \n\t") DisplayError(e) self.ch.close() raise except RuntimeError as e: sys.stderr.write( "Runtime Error -> Creating TemperatureSensor: \n\t" + e) self.ch.close() raise logging.info("Phidget: Opening and Waiting for Attachment...") try: self.ch.openWaitForAttachment(5000) except PhidgetException as e: PrintOpenErrorMessage(e, self.ch) self.ch.close() raise EndProgramSignal("Program Terminated: Open Failed") time.sleep(1) logging.info("Phidget: Ready!")
def initialize_sensors(): print("\n--- Sensors initializing...") try: #For a raspberry pi, for example, to set up pins 4 and 5, you would add #GPIO.setmode(GPIO.BCM) #GPIO.setup(4, GPIO.IN) #GPIO.setup(5, GPIO.IN) print("--- Waiting 10 seconds for sensors to warm up...") time.sleep(10) # Activate the Phidget global ch ch = TemperatureSensor() # Assign event handlers ch.setOnAttachHandler(PhidgetAttached) ch.setOnDetachHandler(PhidgetDetached) ch.setOnErrorHandler(ErrorEvent) # Wait for the sensor to be attached print("--- Waiting for the Phidget Object to be attached...") ch.openWaitForAttachment(5000) print("--- Sensors initialized!") # Sync the time on this device to an internet time server try: print('\n--- Syncing time...') os.system('sudo service ntpd stop') time.sleep(1) os.system('sudo ntpd -gq') time.sleep(1) os.system('sudo service ntpd start') print('--- Success! Time is ' + str(datetime.datetime.now())) except: print('Error syncing time!') except Exception as ex: # Log any error, if it occurs print(str(datetime.datetime.now()) + " Error when initializing sensors: " + str(ex))
class IRTemperatureSensor(Sensor): ''' Class for connecting to Phidget IR temperature sensors. Extends base Sensor class ''' def __init__(self, deviceSN, dataInterval, refreshPeriod, sensorName=None): ''' Constructor for IR Temp class. Takes same arguments as Sensor ''' Sensor.__init__(self, deviceSN, dataInterval, refreshPeriod, sensorName) self.sensorUnits = "Degrees C" def attachSensor(self): ''' Connects sensor to application. Sets the "channel" parameter which is the handle to the phidget ''' self.channel = TemperatureSensor() self.channel.setDeviceSerialNumber(self.deviceSN) self.channel.setChannel(0) self.channel.openWaitForAttachment(5000) print("***** {} Sensor Attached *****".format(self.sensorName)) self.attached = True self.channel.setDataInterval(self.dataInterval) def activateDataListener(self): ''' Sets up the event which triggers when the sensor updates its output values ''' self.startTime = time.time() def onTemperatureChange(channelObject, temperature): # logs time and sensor value to the thread safe dataQ rawTime = time.time() deltaTime = rawTime - self.startTime self.dataQ.put([temperature, deltaTime, rawTime]) self.channel.setOnTemperatureChangeHandler(onTemperatureChange)
def __init__(self): """ Virtually private constructor. """ if TemperatureSensorAccessObject.__instance != None: raise Exception("This class is a singleton!") else: TemperatureSensorAccessObject.__instance = self try: TemperatureSensorAccessObject.__ch = TemperatureSensor() except PhidgetException as e: sys.stderr.write( "Phidget Error -> Creating TemperatureSensor: \n\t" + str(e)) raise except RuntimeError as e: sys.stderr.write( "Runtime Error -> Creating TemperatureSensor: \n\t" + str(e)) raise TEMPERATURE_SERIAL_NUMBER = int( os.getenv("TEMPERATURE_SERIAL_NUMBER")) TEMPERATURE_VINT_HUB_PORT_NUMBER = int( os.getenv("TEMPERATURE_VINT_HUB_PORT_NUMBER")) TEMPERATURE_CHANNEL_NUMBER = int( os.getenv("TEMPERATURE_CHANNEL_NUMBER")) TemperatureSensorAccessObject.__ch.setDeviceSerialNumber( TEMPERATURE_SERIAL_NUMBER) TemperatureSensorAccessObject.__ch.setHubPort( TEMPERATURE_VINT_HUB_PORT_NUMBER) TemperatureSensorAccessObject.__ch.setChannel( TEMPERATURE_CHANNEL_NUMBER) TemperatureSensorAccessObject.__ch.setOnAttachHandler( onAttachHandler) TemperatureSensorAccessObject.__ch.setOnDetachHandler( onDetachHandler) TemperatureSensorAccessObject.__ch.setOnErrorHandler( onErrorHandler)
import time from time import ctime from Phidget22.Devices.TemperatureSensor import * from Phidget22.PhidgetException import * from Phidget22.Phidget import * from Phidget22.Net import * import numpy as np import csv tempslist0 = np.asarray([]) tempslist1 = np.asarray([]) tempslist2 = np.asarray([]) tempslist3 = np.asarray([]) try: ch0 = TemperatureSensor() ch1 = TemperatureSensor() ch2 = TemperatureSensor() ch3 = TemperatureSensor() except RuntimeError as e: print("Runtime Exception %s" % e.details) print("Press Enter to Exit...\n") readin = sys.stdin.read(1) exit(1) def TemperatureSensorAttached(e): try: attached = e print("\nAttach Event Detected (Information Below)")
class ThermoCouple(Sensor): '''Class used to handle any thermcouple data ''' def __init__(self, deviceSN, channelNo, dataInterval, refreshPeriod, sensorType, sensorName=None): ''' Constructor for creating thermcouple sensors. Takes standard sensor arguments. Sensor type here is enum for different thermcouples. J,K,E and T types are represented by 1,2,3,4. ''' self.channelNo = channelNo self.sensorType = sensorType self.sensorUnits = None Sensor.__init__(self, deviceSN, dataInterval, refreshPeriod, sensorName) def attachSensor(self): ''' Connects the sensor to the application ''' self.channel = TemperatureSensor() self.channel.setDeviceSerialNumber(self.deviceSN) self.channel.setChannel(self.channelNo) self.channel.openWaitForAttachment(100) print("\n***** {} Sensor Attached *****".format(self.sensorName)) self.attached = True self.channel.setThermocoupleType(self.sensorType) self.channel.setDataInterval(self.dataInterval) self.sensorUnits = "degrees C" def activateDataListener(self): ''' Sets up the event which triggers when the sensor updates its outputs ''' self.startTime = time.time() def onTempChange(channelObject, temp): rawTime = time.time() deltaTime = rawTime - self.startTime self.dataQ.put([temp, deltaTime, rawTime]) self.channel.setOnTemperatureChangeHandler(onTempChange)
class PhidgetTemperature(object): def __init__(self, hub_port=0, hub_channel=1, serial_number=-1, use_hub=False): self.use_hub = use_hub self.hub_port = hub_port self.hub_channel = hub_channel try: self.ch = TemperatureSensor() self.ch.setDeviceSerialNumber(serial_number) if use_hub: self.ch.setHubPort(hub_port) self.ch.setChannel(hub_channel) except PhidgetException as e: sys.stderr.write( "Runtime Error -> Creating TemperatureSensor: \n\t") DisplayError(e) self.ch.close() raise except RuntimeError as e: sys.stderr.write( "Runtime Error -> Creating TemperatureSensor: \n\t" + e) self.ch.close() raise logging.info("Phidget: Opening and Waiting for Attachment...") try: self.ch.openWaitForAttachment(5000) except PhidgetException as e: PrintOpenErrorMessage(e, self.ch) self.ch.close() raise EndProgramSignal("Program Terminated: Open Failed") time.sleep(1) logging.info("Phidget: Ready!") def getTemperature(self, fahrenheit=False): if fahrenheit: return (self.ch.getTemperature() * 9 / 5.0) + 32 else: return self.ch.getTemperature() def closeConnection(self): return self.ch.close()
#Add Phidgets library from Phidget22.Phidget import * from Phidget22.Devices.TemperatureSensor import * from Phidget22.Devices.PressureSensor import * #Required for sleep statement import time #Create temperatureSensor = TemperatureSensor() pressureSensor = PressureSensor() #Open temperatureSensor.openWaitForAttachment(1000) pressureSensor.openWaitForAttachment(1000) #Use your Phidgets while (True): #Update user print("Logging data...") #Write data to file in CSV format with open('data.csv', 'a') as datafile: datafile.write( time.strftime("%Y-%m-%d %H:%M:%S") + "," + str(temperatureSensor.getTemperature()) + "," + str(pressureSensor.getPressure()) + "\n") time.sleep(1.0)
class MyThermo: def __init__(self, hub_serial, hub_port, thermal_channel): self.sensor = TemperatureSensor() self.sensor.setHubPort(hub_port) self.sensor.setChannel(thermal_channel) self.sensor.setDeviceSerialNumber(hub_serial) self.sensor.openWaitForAttachment(5000) self.previous_temp = 0 self.thermal_channel = thermal_channel def get_temp(self): try: temp = self.sensor.getTemperature() self.previous_temp = temp return temp except PhidgetException as exception: print('Error on thermal channel', self.thermal_channel, exception) return self.previous_temp def __del__(self): self.sensor.close()
def plugin_reconfigure(handle, new_config): """ Reconfigures the plugin Args: handle: handle returned by the plugin initialisation call new_config: JSON object representing the new configuration category for the category Returns: new_handle: new handle to be used in the future calls """ _LOGGER.info("Old config for wind_turbine plugin {} \n new config {}".format(handle, new_config)) # Shutdown sensors try: handle['humidity'].close() handle['temperature'].close() handle['current'].close() handle['encoder'].close() handle['accelerometer'].close() handle['gyroscope'].close() handle['magnetometer'].close() except Exception as ex: _LOGGER.exception("wind_turbine exception: {}".format(str(ex))) raise ex time.sleep(5) new_handle = copy.deepcopy(new_config) try: # check if temp/humidity sensor is enabled. If so restart it if new_handle['tempHumEnable']['value'] == 'true': new_handle['humidity'] = HumiditySensor() new_handle['humidity'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['humidity'].setHubPort(int(new_handle['tempHumPort']['value'])) new_handle['humidity'].setIsHubPortDevice(False) new_handle['humidity'].setChannel(0) new_handle['humidity'].openWaitForAttachment(5000) try: new_handle['humidity'].getHumidity() except Exception: pass new_handle['temperature'] = TemperatureSensor() new_handle['temperature'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['temperature'].setHubPort(int(new_handle['tempHumPort']['value'])) new_handle['temperature'].setIsHubPortDevice(False) new_handle['temperature'].setChannel(0) new_handle['temperature'].openWaitForAttachment(5000) try: new_handle['temperature'].getTemperature() except Exception: pass # check if current sensor is enabled, if so restart it if new_handle['currentEnable']['value'] == 'true': new_handle['current'] = CurrentInput() new_handle['current'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['current'].setHubPort(int(new_handle['currentPort']['value'])) new_handle['current'].setIsHubPortDevice(False) new_handle['current'].setChannel(0) new_handle['current'].openWaitForAttachment(5000) try: new_handle['current'].getCurrent() except Exception: pass # check if encoder sensor is enabled if new_handle['encoderEnable']['value'] == 'true': new_handle['encoder'] = Encoder() new_handle['encoder'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['encoder'].setHubPort(int(new_handle['encoderPort']['value'])) new_handle['encoder'].setIsHubPortDevice(False) new_handle['encoder'].setChannel(0) new_handle['encoder'].openWaitForAttachment(5000) new_handle['encoder'].setDataInterval(20) i = 0 while i < 120: try: new_handle['encoder'].getPosition() except Exception: time.sleep(1) i += 1 else: break # check if accelerometer is enabled if new_handle['accelerometerEnable']['value'] == 'true': new_handle['accelerometer'] = Accelerometer() new_handle['accelerometer'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['accelerometer'].setHubPort(int(new_handle['spatialPort']['value'])) new_handle['accelerometer'].setIsHubPortDevice(False) new_handle['accelerometer'].setChannel(0) new_handle['accelerometer'].openWaitForAttachment(5000) new_handle['accelerometer'].setDataInterval(20) i = 0 while i < 120: try: new_handle['accelerometer'].getAcceleration() except Exception: time.sleep(1) i += 1 else: break # check if gyroscope is enabled if new_handle['gyroscopeEnable']['value'] == 'true': new_handle['gyroscope'] = Gyroscope() new_handle['gyroscope'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['gyroscope'].setHubPort(int(new_handle['spatialPort']['value'])) new_handle['gyroscope'].setIsHubPortDevice(False) new_handle['gyroscope'].setChannel(0) new_handle['gyroscope'].openWaitForAttachment(5000) new_handle['gyroscope'].setDataInterval(20) i = 0 while i < 120: try: new_handle['gyroscope'].getAngularRate() except Exception: time.sleep(1) i += 1 else: break # check if magnetometer enable is enabled if new_handle['magnetometerEnable']['value'] == 'true': new_handle['magnetometer'] = Magnetometer() new_handle['magnetometer'].setDeviceSerialNumber(int(new_handle['hubSN']['value'])) new_handle['magnetometer'].setHubPort(int(new_handle['spatialPort']['value'])) new_handle['magnetometer'].setIsHubPortDevice(False) new_handle['magnetometer'].setChannel(0) new_handle['magnetometer'].openWaitForAttachment(5000) new_handle['magnetometer'].setDataInterval(20) i = 0 while i < 120: try: new_handle['magnetometer'].getMagneticField() except Exception: time.sleep(1) i += 1 else: break # check if hub has changed, if so init restart if new_handle['hubSN']['value'] != handle['hubSN']['value']: new_handle['restart'] = 'yes' else: new_handle['restart'] = 'no' except Exception as ex: _LOGGER.exception("wind_turbine exception: {}".format(str(ex))) raise ex # counter to know when to run process new_handle['tempHumCount'] = 0 new_handle['currentCount'] = 0 new_handle['encoderCount'] = 0 new_handle['accelerometerCount'] = 0 new_handle['gyroscopeCount'] = 0 new_handle['magnetometerCount'] = 0 # counter of last encoder value new_handle['encoderPreviousValue'] = handle['encoderPreviousValue'] return new_handle
# code for humidity sensor humidity = HumiditySensor() humidity.setDeviceSerialNumber(561266) humidity.setHubPort(5) humidity.setIsHubPortDevice(False) humidity.setChannel(0) humidity.openWaitForAttachment(5000) try: humidity.getHumidity() except Exception as e: pass time.sleep(2) print(humidity.getHumidity()) # code for temperature sensor temp = TemperatureSensor() temp.setDeviceSerialNumber(561266) temp.setHubPort(5) temp.setIsHubPortDevice(False) temp.setChannel(0) temp.openWaitForAttachment(5000) try: temp.getTemperature() except Exception as e: pass time.sleep(2) print(temp.getTemperature())
def main(): try: """ * Allocate a new Phidget Channel object """ try: ch = TemperatureSensor() except PhidgetException as e: sys.stderr.write("Runtime Error -> Creating TemperatureSensor: \n\t") DisplayError(e) raise except RuntimeError as e: sys.stderr.write("Runtime Error -> Creating TemperatureSensor: \n\t" + e) raise """ * Set matching parameters to specify which channel to open """ #You may remove this line and hard-code the addressing parameters to fit your application channelInfo = AskForDeviceParameters(ch) ch.setDeviceSerialNumber(channelInfo.deviceSerialNumber) ch.setHubPort(channelInfo.hubPort) ch.setIsHubPortDevice(channelInfo.isHubPortDevice) ch.setChannel(channelInfo.channel) if(channelInfo.netInfo.isRemote): ch.setIsRemote(channelInfo.netInfo.isRemote) if(channelInfo.netInfo.serverDiscovery): try: Net.enableServerDiscovery(PhidgetServerType.PHIDGETSERVER_DEVICEREMOTE) except PhidgetException as e: PrintEnableServerDiscoveryErrorMessage(e) raise EndProgramSignal("Program Terminated: EnableServerDiscovery Failed") else: Net.addServer("Server", channelInfo.netInfo.hostname, channelInfo.netInfo.port, channelInfo.netInfo.password, 0) """ * Add event handlers before calling open so that no events are missed. """ print("\n--------------------------------------") print("\nSetting OnAttachHandler...") ch.setOnAttachHandler(onAttachHandler) print("Setting OnDetachHandler...") ch.setOnDetachHandler(onDetachHandler) print("Setting OnErrorHandler...") ch.setOnErrorHandler(onErrorHandler) #This call may be harmlessly removed PrintEventDescriptions() print("\nSetting OnTemperatureChangeHandler...") ch.setOnTemperatureChangeHandler(onTemperatureChangeHandler) """ * Open the channel with a timeout """ print("\nOpening and Waiting for Attachment...") try: ch.openWaitForAttachment(5000) except PhidgetException as e: PrintOpenErrorMessage(e, ch) raise EndProgramSignal("Program Terminated: Open Failed") print("Sampling data for 10 seconds...") print("You can do stuff with your Phidgets here and/or in the event handlers.") time.sleep(10) """ * Perform clean up and exit """ #clear the TemperatureChange event handler ch.setOnTemperatureChangeHandler(None) print("\nDone Sampling...") print("Cleaning up...") ch.close() print("\nExiting...") return 0 except PhidgetException as e: sys.stderr.write("\nExiting with error(s)...") DisplayError(e) traceback.print_exc() print("Cleaning up...") ch.setOnTemperatureChangeHandler(None) ch.close() return 1 except EndProgramSignal as e: print(e) print("Cleaning up...") ch.setOnTemperatureChangeHandler(None) ch.close() return 1 finally: print("Press ENTER to end program.") readin = sys.stdin.readline()
from prometheus_client import start_http_server, Gauge from Phidget22.PhidgetException import * from Phidget22.Phidget import * from Phidget22.Devices.TemperatureSensor import * import time TEMPERATURE_FAHRENHEIT = Gauge('current_temperature_fahrenheit', 'Current Temperature in FahrenHeit') TEMPERATURE_CELCIUS = Gauge('current_temperature_celcius', 'Current Temperature in Celcius') tc = TemperatureSensor() tc.setHubPort(1) tc.setChannel(0) tc.openWaitForAttachment(5000) def c_to_f(c): return (9 / 5 * c + 32) def get_temp(fahrenheit=False): temp_celcius = tc.getTemperature() if fahrenheit: temp = c_to_f(temp_celcius) else: temp = temp_celcius return round(temp, 1)
def plugin_init(config): """ Initialise the plugin. Args: config: JSON configuration document for the South plugin configuration category Returns: data: JSON object to be used in future calls to the plugin Raises: """ try: data = copy.deepcopy(config) if data['tempHumEnable']['value'] == 'true': data['humidity'] = HumiditySensor() data['humidity'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['humidity'].setHubPort(int(data['tempHumPort']['value'])) data['humidity'].setIsHubPortDevice(False) data['humidity'].setChannel(0) data['humidity'].openWaitForAttachment(5000) try: data['humidity'].getHumidity() except Exception: pass data['temperature'] = TemperatureSensor() data['temperature'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['temperature'].setHubPort(int(data['tempHumPort']['value'])) data['temperature'].setIsHubPortDevice(False) data['temperature'].setChannel(0) data['temperature'].openWaitForAttachment(5000) try: data['temperature'].getTemperature() except Exception: pass if data['currentEnable']['value'] == 'true': data['current'] = CurrentInput() data['current'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['current'].setHubPort(int(data['currentPort']['value'])) data['current'].setIsHubPortDevice(False) data['current'].setChannel(0) data['current'].openWaitForAttachment(5000) try: data['current'].getCurrent() except Exception: pass if data['encoderEnable']['value'] == 'true': data['encoder'] = Encoder() data['encoder'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['encoder'].setHubPort(int(data['encoderPort']['value'])) data['encoder'].setIsHubPortDevice(False) data['encoder'].setChannel(0) data['encoder'].openWaitForAttachment(5000) data['encoder'].setDataInterval(20) i = 0 while i < 120: try: data['encoder'].getPosition() except Exception: time.sleep(1) i += 1 else: break if data['accelerometerEnable']['value'] == 'true': data['accelerometer'] = Accelerometer() data['accelerometer'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['accelerometer'].setHubPort(int(data['spatialPort']['value'])) data['accelerometer'].setIsHubPortDevice(False) data['accelerometer'].setChannel(0) data['accelerometer'].openWaitForAttachment(5000) data['accelerometer'].setDataInterval(20) i = 0 while i < 120: try: data['accelerometer'].getAcceleration() except Exception: time.sleep(1) i += 1 else: break if data['gyroscopeEnable']['value'] == 'true': data['gyroscope'] = Gyroscope() data['gyroscope'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['gyroscope'].setHubPort(int(data['spatialPort']['value'])) data['gyroscope'].setIsHubPortDevice(False) data['gyroscope'].setChannel(0) data['gyroscope'].openWaitForAttachment(5000) data['gyroscope'].setDataInterval(20) i = 0 while i < 120: try: data['gyroscope'].getAngularRate() except Exception: time.sleep(1) i += 1 else: break if data['magnetometerEnable']['value'] == 'true': data['magnetometer'] = Magnetometer() data['magnetometer'].setDeviceSerialNumber(int(data['hubSN']['value'])) data['magnetometer'].setHubPort(int(data['spatialPort']['value'])) data['magnetometer'].setIsHubPortDevice(False) data['magnetometer'].setChannel(0) data['magnetometer'].openWaitForAttachment(5000) data['magnetometer'].setDataInterval(20) i = 0 while i < 120: try: data['magnetometer'].getMagneticField() except Exception: time.sleep(1) i += 1 else: break except Exception as ex: _LOGGER.exception("wind_turbine exception: {}".format(str(ex))) raise ex # counter to know when to run process data['tempHumCount'] = 0 data['currentCount'] = 0 data['encoderCount'] = 0 data['accelerometerCount'] = 0 data['gyroscopeCount'] = 0 data['magnetometerCount'] = 0 # counter of last encoder value data['encoderPreviousValue'] = 0 data['encoderPreviousTime'] = 0 return data
def whattemp(): global temp9 ch2 = TemperatureSensor() ch2.setDeviceSerialNumber(118651) ch2.setChannel(0) ch2.setOnAttachHandler(onAttachHandler) ch2.setOnTemperatureChangeHandler(onTemperatureChangeHandler) ch2.openWaitForAttachment(5000) temp9 = ch2.getTemperature() * 9 / 5 + 32 temp8 = temp9 #time.sleep(10) ch2.close() print("i got the temperature, its ", temp9) return temp8