コード例 #1
0
        def connected(client):
            for feed_id in self.sensor:
                if client._username == self.sensor[feed_id]['owner']:
                    client.subscribe(feed_id=feed_id,
                                     feed_user=self.sensor[feed_id]['owner'])
                    client.receive(feed_id)

            for feed_id in self.tempHumid:
                if client._username == self.tempHumid[feed_id]['owner']:
                    client.subscribe(
                        feed_id=feed_id,
                        feed_user=self.tempHumid[feed_id]['owner'])
                    client.receive(feed_id)

            for feed_id in self.pump:
                if client._username == self.pump[feed_id]['owner']:
                    client.subscribe(feed_id=feed_id)
                    client.receive(feed_id)
コード例 #2
0
def on_connect(client, userdata, flags, rc):
    printBetter("Connected with result code " + str(rc))
    # Subscribing in on_connect() means that if we lose the connection and
    # reconnect then subscriptions will be renewed.
    client.subscribe("/leds/pi")
コード例 #3
0
def on_connect(client, userdata, rc):
    print("Connected with result coe " + str(rc))
    client.subscribe("Entity/SHM/Node/353041080754218/Device/Status")
コード例 #4
0
# 클라이언트가 서버에게서 CONNACK 응답을 받을 때 호출되는 콜백
def on_connect(client, userdata, rc):
    print("Connected with result coe " + str(rc))
    client.subscribe("Entity/SHM/Node/353041080754218/Device/Status")


# 서버에게서 PUBLISH 메시지를 받을 때 호출되는 콜백
def on_message(client, userdata, msg):
    now_time = str(date.datetime.now())
    print("Time: ", now_time)
    print("Topic: ", msg.topic)
    mqtt_data = str(msg.payload)
    split_topic = str(msg.topic).split('/')


logger = logging.getLogger(__name__)

client = mqtt.Client()  # MQTT Client 오브젝트 생성
print("Test Step 01")
client.enable_logger(logger)
print("Test Step 02")
client.on_connect = on_connect  # on_connect callback 설정
print("Test Step 03")
client.on_message = on_message  # on_message callback 설정
print("Test Step 04")
client.connect(broker.strip())  # MQTT 서버에 연결
print("Test Step 05")

client.subscribe(mqtt_topic.strip())

client.loop_forever()
コード例 #5
0
def on_connect(client, userdata, flags, rc):
    print("Connected with result code " + str(rc) + "\n")
    client.subscribe("ECS/temp2")
    client.subscribe("ECS/force")
    client.subscribe("ECS/calendar_update")