这个库提供了一个框架来为连接到mqtt的raspberry pi编写设备驱动程序。
Copreus的Python项目详细描述
对于用户
安装核心功能
核心功能的先决条件是:
sudo apt install python3 python3-pip sudo pip3 install RPi.GPIO pelops
通过PIP安装:
sudo pip3 install copreus
要更新到最新版本,请在 pip3 上面的行。
通过Gitlab安装(可能需要其他软件包):
git clone git@gitlab.com:pelops/copreus.git cd copreus sudo python3 setup.py install
这将安装以下shell脚本:* copreus -alias 对于* `copreus_drivermanager <; https://gitlab.com/pelops/copreus/wikis/devicemanager devicemanager >;。`_ -驱动程序管理器可以实例化多个驱动程序* `copreus_adc <; https://gitlab.com/pelops/copreus/wikis/drivers adc >;。`_ -通过SPI的模数转换器* `copreus_bme280 <; https://gitlab.com/pelops/copreus/wikis/drivers-bme_280 >;。`_ -通过SMBus的博世BME280传感器* `copreus_dac <; https://gitlab.com/pelops/copreus/wikis/drivers dac >;。`_ -通过SPI的数模转换器* `copreus_dht <; https://gitlab.com/pelops/copreus/wikis/drivers dht >;。`_ -DHT11/DHT2/AM2302型* `copreus_epaperdirect <; https://gitlab.com/pelops/copreus/wikis/drivers epaperdirect >;。`_ -WaveShare电子纸1.54英寸/2.13英寸/2.9英寸,通过SPI-* `copreus_eppersimple <; https://gitlab.com/pelops/copreus/wikis/drivers-eppersimple >;。`_ -WaveShare电子纸1.54英寸/2.13英寸/2.9英寸,通过SPI* `copreus_input <; https://gitlab.com/pelops/copreus/wikis/drivers input >;。`_ -通用GPIO输入* `copreus_output <; https://gitlab.com/pelops/copreus/wikis/drivers-output >;。`_ -通用GPIO输出* `copreus_rotaryencoder <; https://gitlab.com/pelops/copreus/wikis/drivers rotaryencoder >;。`_ -类似于ky-040的旋转编码器,具有去噪和 方向检测。* `copreus_rotaryencoder2 <; https://gitlab.com/pelops/copreus/wikis/drivers-rotaryencoder2 >;。`_ -旋转编码器,如KY-040和施密特触发器 去抖动和触发器,用于硬件中的方向检测。
脚本cli参数是:*'-c'/'-config'-config文件 (必需)*'–version'-显示版本号并退出
驱动程序的附加先决条件
一些驱动程序,如
adc 和 dac
sudo pip3 install spidev
bme280
sudo pip3 install smbus2 RPi.bme280
dht
sudo apt install build-essential python-dev git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT sudo python3 setup.py install
epaperdirect
sudo apt install libopenjp2-7 libtiff5 sudo pip3 install spidev Pillow
sudo apt install libopenjp2-7 libtiff5 sudo pip3 install spidev Pillow
立即安装所有组件
sudo apt install python3 python3-pip build-essential python-dev libopenjp2-7 libtiff5 sudo pip3 install RPi.GPIO paho-mqtt pyyaml spidev Pillow smbus2 RPi.bme280 pelops git clone https://github.com/adafruit/Adafruit_Python_DHT.git cd Adafruit_Python_DHT sudo python3 setup.py install cd .. sudo pip3 install copreus
示例和测试可能需要更多的ubuntu和python包。 例如, test_epaper.py 要求ubuntu包 已安装字体freefont ttf 。
yaml配置
一个yaml文件必须包含两个根块:*mqtt-mqtt address, MQTT端口和凭据文件的路径凭据文件(文件 包含两个条目:mqtt user、mqtt password)*logger-logger 配置。日志级别和输出文件。*司机。驱动程序 是一个驱动程序条目列表,每个驱动程序有两个附加参数: 活动和名称。驱动程序条目至少包含(驱动程序实现 可能会添加其他项:类型、名称、主题pub(键/值列表 pairs)和topic sub(键/值对列表)。
目前,pyyaml符合yaml 1.1。在pyyaml中开/关和是/否是 自动转换为真/假。这是一种不受欢迎的行为 在yaml 1.2中已弃用。在copreus中,此自动转换被删除。因此, on/off和yes/no作为字符串从yaml文件中读取(参见模块 基类。myconfigtools)。
示例
驱动器配置 输入
可以从 copreus_input -c config.yaml -v 开始。更多 中的信息 维基
配置yaml:
sudo apt install python3 python3-pip sudo pip3 install RPi.GPIO pelops0
凭据。yaml:
sudo apt install python3 python3-pip sudo pip3 install RPi.GPIO pelops1
系统d
- 添加系统示例。