def check_feature(chip, feature): sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures label = sensors.get_label(chip, feature) skipname = len(feature.name)+1 # skip common prefix # vals is a list of value min and max vals = [sensors.get_value(chip, sf.number) for sf in sfs] if feature.type == sensors.feature.INTRUSION: # short path for INTRUSION to demonstrate type usage status = "alarm" if int(vals[0]) == 1 else "normal" print("\t"+label+"\t"+status) names = [sf.name[skipname:].decode("utf-8") for sf in sfs] data = list(zip(names, vals)) str_data = ", ".join([e[0]+": "+str(e[1]) for e in data]) if vals[2] > value_max[label]: print("\tCheck "+src[label]+"\tFAILED! "+str(vals[2])+" > "+str(value_max[label])+")") return False if vals[1] < value_min[label]: print("\tCheck "+src[label]+"\tFAILED! "+str(vals[1])+" < "+str(value_min[label])+")") return False print("\tCheck "+src[label]+"\t"+"\t("+str(vals[0])+") ....OK") return True
def template(title="HELLO!", text="", error=""): now = datetime.datetime.now() timeString = now drip_states = list() last_watered = list() for p in state.pumps: drip_states.append(DripState(p, p in state.drip)) last_watered.append(config.get_last_watered(p)) sensor_states = list() for s in state.sensors: sensor_states.append(sensors.get_value(s)) templateDate = { 'title': title, 'time': timeString, 'text': text, 'error': error, 'logdate': state.logdate, 'logs': logger.get_logs(state.logdate).splitlines(), 'drips': drip_states, 'drip_delay': state.drip_delay, 'drip_duration': state.drip_duration, 'sensors': sensor_states, 'timed': state.timed, 'timed_edit': state.timed_edit, 'drip_edit': state.drip_edit, 'last_watered': last_watered, 'water_now_pump': state.water_now_pump, 'water_now_duration': state.water_now_duration } return templateDate
def process_temp(): print("-" * 50) sensors.init() critical = False try: for chip in sensors.ChipIterator(): for feature in sensors.FeatureIterator(chip): subs = list(sensors.SubFeatureIterator(chip, feature)) critical = None current = None for sub in subs: value = sensors.get_value(chip, sub.number) if sub.name.endswith(b"input"): current = value if sub.name.endswith(b"crit"): critical_value = value name = sensors.get_label(chip, feature) print("Current temp for {}: {} / {}".format(name, current, critical_value)) if current >= critical_value: critical = True if critical: play_critical() finally: sensors.cleanup()
def print_feature(chip, feature): sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures label = sensors.get_label(chip, feature) skipname = len(feature.name)+1 # skip common prefix vals = [sensors.get_value(chip, sf.number) for sf in sfs] if feature.type == sensors.feature.INTRUSION: # short path for INTRUSION to demonstrate type usage status = "alarm" if int(vals[0]) == 1 else "normal" print("\t"+label+"\t"+status) return names = [sf.name[skipname:].decode("utf-8") for sf in sfs] data = list(zip(names, vals)) str_data = ", ".join([e[0]+": "+str(e[1]) for e in data]) print("\t"+label+"\t"+str_data)
def print_feature(chip, feature): sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures label = sensors.get_label(chip, feature) skip_name = len(feature.name) + 1 # skip common prefix values = [sensors.get_value(chip, sf.number) for sf in sfs] if feature.type == sensors.Feature.INTRUSION: # short path for INTRUSION to demonstrate type usage status = "alarm" if int(values[0]) == 1 else "normal" print("\t" + label + "\t" + status) return names = [sf.name[skip_name:].decode("utf-8") for sf in sfs] data = list(zip(names, values)) str_data = ", ".join([e[0] + ": " + str(e[1]) for e in data]) print("\t" + label + "\t" + str_data)
def coretemp(): rv = {} for chip in sensors.ChipIterator(): chipname = sensors.chip_snprintf_name(chip) if "temp" not in chipname: continue chipdata = {} for feature in sensors.FeatureIterator(chip): label = sensors.get_label(chip, feature) sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures vals = [sensors.get_value(chip, sf.number) for sf in sfs] names = [sf.name[len(feature.name)+1:].decode("utf-8") for sf in sfs] data = dict(zip(names, vals)) # We use the label instead of the name because the name is typically unhelpful. chipdata[sanitizeName(label)] = data["input"] rv[chipname] = chipdata return rv
def get_temp(): sensors.init() temp = 0 try: for chip in sensors.ChipIterator(): for feature in sensors.FeatureIterator(chip): subs = list(sensors.SubFeatureIterator(chip, feature)) try: sensor_temp = sensors.get_value(chip, subs[0].number) # el 200 es por que en las maquinas de desarrollo devuelve # los RPM de los ventiladores como features. Esta es la # solucion menos compleja para descartar ese valor. if sensor_temp < 200 and sensor_temp > temp: temp = sensor_temp except Exception: # alguno de los sensores no se pudo leer. en circunstancias # normales no pasa pero atajamoe el error para que siga con # el resto de las featuras pass finally: sensors.cleanup() return temp
critical_alarm5 = 0 #print("*********************************") print "Time : %f " % time.time() cnt = 0 for chip in sensors.ChipIterator( ): # optional arg like "coretemp-*" restricts iterator #print(sensors.chip_snprintf_name(chip)+" ("+sensors.get_adapter_name(chip.bus)+")") print("*********************************") for feature in sensors.FeatureIterator(chip): #print_feature(chip, feature) #value = sensors.get_value(chip, feature.number) #print(value) #print(feature.number) if cnt == 1: coretemp[0] = sensors.get_value(chip, 4) coretemp[1] = sensors.get_value(chip, 8) coretemp[2] = sensors.get_value(chip, 12) coretemp[3] = sensors.get_value(chip, 16) coretemp[4] = sensors.get_value(chip, 20) coretemp[5] = sensors.get_value(chip, 24) dateTimeObj = datetime.now() timestampStr = dateTimeObj.strftime( "%d-%b-%Y (%H:%M:%S.%f)") report_statement = "An alarm was released at " + timestampStr + " reporting a violation in PR2 Robot's hardware temperature. The current processor core temperature in degree Celsius values are reported: Core 0 : " + str( coretemp[0]) + " Core 1 : " + str( coretemp[1]) + " Core 2 : " + str( coretemp[2]) + " Core 3 : " + str( coretemp[3]) + " Core 4 : " + str( coretemp[4]) + " Core 5 : " + str(
# Подключаемся к серверу client_sensor.connect("ks-cube.tk") # Запускаем цикл работы с сетевым траффиком client_sensor.loop_start() # Запускаем вечный цикл, обрываемый исключением try: sensors.init() # Получаем объект для считвания значения температуры chip, nr = sensors.get_detected_chips(sensors.parse_chip_name("dell_smm-virtual-0"), 0) while True: # Получаем текущую температуру 2-го эелемента чипа dell_smm-virtual-0 (CPU) payload = sensors.get_value(chip, 2) # Публикуем текущую температура, печатаем результат передачи номер сообщения в сессии print("temp: {0}".format(payload)) print(client_sensor.publish("/sensors/book1/cpu", payload=payload, qos=0, retain=False)) # ...раз в 10 секунд time.sleep(10) finally: # Если выброшено исключение... print("disconnecting") client_sensor.loop_stop() # Останавливаем сетевой цикл, Иначе получим аварийный обрыв соединения # и брокер вышлет last will всем подписавшимся клиентам client_sensor.disconnect() # Отключаемся sensors.cleanup() # Чистим после себя