當前位置: 首頁>>代碼示例>>Python>>正文


Python MQTTClient.tls_set方法代碼示例

本文整理匯總了Python中Adafruit_IO.MQTTClient.tls_set方法的典型用法代碼示例。如果您正苦於以下問題:Python MQTTClient.tls_set方法的具體用法?Python MQTTClient.tls_set怎麽用?Python MQTTClient.tls_set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Adafruit_IO.MQTTClient的用法示例。


在下文中一共展示了MQTTClient.tls_set方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_message

# 需要導入模塊: from Adafruit_IO import MQTTClient [as 別名]
# 或者: from Adafruit_IO.MQTTClient import tls_set [as 別名]
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))

def on_publish(client, userdata, mid):
    print("data sent")

def on_disconnect(client, userdata, rc):
    print("disconnect")

client = MQTTClient(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY,service_port=8883)
client.on_connect = on_connect
client.on_message = on_message
client.on_publish = on_publish
client.on_disconnect = on_disconnect
client.tls_set("/home/pi/adafruitio-temperature/certs/geotrust.pem")
client.connect()
#client.loop_background()

# Get temperature from sensor
#byte1 = 29
#byte2 = 0x00
#temperature = ((byte1 << 8) + byte2) >> 4
#if (temperature & 0x800):
#    temperature = (temperature & 0x7FF) - 0x800
#temperature = temperature * 0.0625
#temperature = 30
temperature = tempSensor.readTemperature()
print("temperature "+str(temperature))
client.publish("bedroom",temperature)
開發者ID:vorasilp,項目名稱:adafruitio-temperature,代碼行數:32,代碼來源:adafruitio_ssl.py


注:本文中的Adafruit_IO.MQTTClient.tls_set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。