コード例 #1
0
    def init(self):
        self.topic = self.a_topic
        if self.b_payload == "":
            self.payload_text = None
        else:
            self.payload_text = self.b_payload.split('.')
#            self.payload_text = self.b_payload
        SensorActive.init(self)

        def on_message(client, userdata, msg):

            try:
                print "payload " + msg.payload
                #                f.write("payload " + msg.payload\n)
                json_data = json.loads(msg.payload)
                #print json_data
                #		f.write(json_data\n)
                print json_data
                val = json_data
                if self.payload_text is not None:
                    for key in self.payload_text:
                        val = val.get(key, None)
                #print val
                print val
                if isinstance(val, (int, float, basestring)):
                    q.put({"id": on_message.sensorid, "value": val})
            except Exception as e:
                print e

        on_message.sensorid = self.id
        self.api.cache["mqtt"].client.subscribe(self.topic)
        self.api.cache["mqtt"].client.message_callback_add(
            self.topic, on_message)
コード例 #2
0
    def init(self):
        # convert properties to usable attributes
        self.gpio = int(self.a_gpio_prop)
        self.display_type = self.b_display_prop if self.b_display_prop else "volume"
        self.volume_units = self.c_volume_units_prop if self.c_volume_units_prop else "Units"
        self.time_units = str(self.d_time_units_prop)
        self.period_adjust = 60.0 if (self.d_time_units_prop == "/m") else 1.0
        self.calibration = float(self.e_calibration_units_prop) / float(
            self.f_calibration_count_prop)

        # initialize
        self.initialize_gpio_counter(self.gpio)
        self.reset_volume()
        SensorActive.init(self)
コード例 #3
0
    def init(self):
        # convert properties to usable attributes
        try:
            self.flow_actor = int(self.a_flow_actor_prop)
            self.flow_rate = float(self.a_flow_rate_prop)
        except:
            self.flow_actor = None
            self.flow_rate = 0.0
        self.display_type = self.b_display_prop if self.b_display_prop else 'volume'
        self.time_units = str(self.d_time_units_prop)
        self.period_adjust = 1.0 / 60.0 if (self.d_time_units_prop
                                            == "/m") else 1.0
        self.volume_units = "Units" if self.c_volume_units_prop == "" else self.c_volume_units_prop
        self.flow_device = None

        # initialize
        self.reset_volume()
        SensorActive.init(self)
コード例 #4
0
ファイル: __init__.py プロジェクト: tiagoclc/cbpi_FermentWifi
 def stop(self):
     mqttc.unsubscribe(self.topic)
     SensorActive.stop(self)
コード例 #5
0
ファイル: __init__.py プロジェクト: jpgimenez/cbpi-mqtt
 def stop(self):
     """
     stop sensor
     """
     self.api.cache["mqtt"].client.unsubscribe(self.topic)
     SensorActive.stop(self)
コード例 #6
0
ファイル: __init__.py プロジェクト: Grooviee/craftbeerpi3
 def init(self):
     SensorActive.stop(self)
     SensorActive.init(self)
コード例 #7
0
ファイル: __init__.py プロジェクト: Grooviee/craftbeerpi3
 def stop(self):
     SensorActive.stop(self)
コード例 #8
0
ファイル: __init__.py プロジェクト: avollkopf/craftbeerpi3
 def stop(self):
     """
     stop sensor
     """
     SensorActive.stop(self)
コード例 #9
0
    def init(self):
        self.topic = self.a_topic

        if self.b_payload == "":
            self.payload_text = None
        else:
            self.payload_text = self.b_payload.split('.')
        #self.unit = self.c_unit[0:3]

        SensorActive.init(self)
        def on_message(client, userdata, msg):

            try:
                #print "payload " + msg.payload
                sensorUnits=""

                json_data = json.loads(msg.payload)
                val = json_data

                #build dict of sensors returned in mqtt (up to 8 in tasmota)
                sensorDict={}
                for key in val:
                    if 'DS18B20-' in key:
                        mydict= val[key]
                        sensorDict[str(mydict["Id"])] = str(mydict["Temperature"])
                    if 'TempUnit' in key:
                        sensorUnits=val[key]

                #loop through defined sensors and see if any match mqtt Dict built above
                for key, value in cbpi.cache.get("sensors").iteritems():
                    if value.type == "MQTT_SENSOR":
                        for DSid in sensorDict:
                            if value.config["b_payload"] == DSid:
                                ConvTemp=0
                                if self.get_config_parameter("unit", "C") == sensorUnits:
                                    ConvTemp=(round(float(sensorDict[str(DSid)]) + float(value.config["d_offset"]), 2))
                                    self.unit="C"
                                else:
                                    ConvTemp=(round(9.0 / 5.0 * float(sensorDict[str(DSid)]) + 32 + float(value.config["d_offset"]), 2))
                                    self.unit="F"

                                q.put({"id": value.id, "value": ConvTemp})
                        
                #print("------Original ----")
                #if self.payload_text is not None:

                #    for key in self.payload_text:
                #        val = val.get(key, None)
  
                #if isinstance(val, (int, float, basestring)):
                #    q.put({"id": on_message.sensorid, "value": val})
                #print("------Orig end-----")    

            except Exception as e:
                print e

        on_message.sensorid = self.id
        
        #print("self.id=" + str(self.id))
        #print("Failed to connect mqtt, response: " + str(rc))

        self.api.cache["mqtt"].client.subscribe(self.topic)
        self.api.cache["mqtt"].client.message_callback_add(self.topic, on_message)