29 lines
810 B
Python
29 lines
810 B
Python
import configparser
|
||
|
||
import subprocess
|
||
|
||
p = subprocess.Popen(['cat /home/pi/device_name'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||
out, err = p.communicate()
|
||
# 设备名称,必须要有
|
||
device_name = out.decode('utf-8').strip()
|
||
|
||
# 读取配置
|
||
config = configparser.ConfigParser()
|
||
# 读取公共配置
|
||
config.read('conf/main/common.conf')
|
||
# 域名
|
||
broker = config.get("broker", "host")
|
||
# 端口,这里必须是int类型
|
||
port = config.getint("broker", "port")
|
||
|
||
# 读取设备配置
|
||
config.read('conf/device/device.conf')
|
||
# 订阅的主题
|
||
subscribe_topic = config.get(device_name, "subscribe_topic")
|
||
# 发布的主题
|
||
publish_topic = config.get(device_name, "publish_topic")
|
||
# 用户
|
||
username = config.get(device_name, "username")
|
||
# 密码
|
||
password = config.get(device_name, "password")
|