Jun-23-2018, 08:43 PM
(This post was last modified: Jun-23-2018, 08:48 PM by gontajones.)
The first file:
def read_sensor(sensorID) tempfile = open("/sys/bus/w1/devices/"+ sensorID +"/w1_slave") thetext = tempfile.read() tempfile.close() tempdata = thetext.split("\n")[1].split(" ")[9] temperature = float(tempdata[2:]) temp_sensor = temperature / 1000 print (temp_sensor)Seconde file:
# Execute DS18B20 function for sensor ID's below. # As sensorsID is a dictionary, you declare it like this: sensorsID = { 'solar_panel': float(read_ds18b20('28-0516a3ff90ff')), 'top_cyl': float(read_ds18b20('28-0317003f1cff')), 'flow_panel': float(read_ds18b20('28-0416c4a3a0ff')) }Now, in the last file:
from mySensorModule import read_sensor from mySensors import sensorsID # Accessing a dictionary: dict_name[key] = value sID = sensorsID['solar_panel'] read_sensor(sID) # Or... read_sensor(sensorsID['solar_panel'])PS: Raspi is so cool!