mqtt_app.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:sdk-samples 作者: cradlepoint 项目源码 文件源码
def publish_file(file_name, file_path):
    global mqtt_client
    log.debug('publish_file({})'.format(file_path))
    try:
        with open(file_path) as fh:
            file_contents = fh.read()
        ret_obj = mqtt_client.publish(topic=file_name, payload=file_contents, qos=0)

        if ret_obj.rc == mqtt.MQTT_ERR_SUCCESS:
            log.debug('MQTT published file: {}'.format(file_path))
        else:
            log.warning('MQTT failed to publish file: {}'.format(file_path))
            log.warning('MQTT failed to publish file. error: {}'.format(mqtt.error_string(ret_obj.rc)))

    except Exception as ex:
        log.error('Exception in publish_file(). ex: {}'.format(ex))


# This function will periodically publish device data to the MQTT Broker
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号