Merci Mips pour ces premières réponses.
Je tente d’avancer sur mon projet de pilotage d’un ampli nad avec son port RS232.
Il faut ceci:
Raspberry Pi 3, running Debian Jessie (remplacé par une VM)
Python 2.7 and python-pip from official packages
the following installed via pip: paho-mqtt, pyserial, flask
a PL2303-type USB2Serial Adapter
La VM en question est jeedom avec mosquitto et un port USB attaché
root@Ubuntu-Jeedom:~# lsusb
Bus 001 Device 002: ID 1bbb:0017 T & A Mobile Phones
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
`root@Ubuntu-Jeedom:~# sudo service mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
Loaded: loaded (/etc/init.d/mosquitto; generated)
Active: active (running) since Tue 2021-12-07 21:21:40 CET; 1 weeks 3 days ago
Docs: man:systemd-sysv-generator(8)
Process: 493 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/mosquitto.service
└─505 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
déc. 07 21:21:40 Ubuntu-Jeedom systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
déc. 07 21:21:40 Ubuntu-Jeedom mosquitto[493]: * Starting network daemon: mosquitto
déc. 07 21:21:40 Ubuntu-Jeedom mosquitto[493]: ...done.
déc. 07 21:21:40 Ubuntu-Jeedom systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
root@Ubuntu-Jeedom:~# `
Le script fait ceci:
connect via RS232 to a NAD Electronics Amplifier (tested with a C-368 model)
connect to a MQTT broker and publish all messages from the device
subscribe to a given topic and forward all messages as commands to the device
implement a simple REST-API to query/configure the C-368 device
`root@Ubuntu-Jeedom:~# python /var/www/html/plugins/script/data/nad.py
2021-12-18 21:00:07,937 - INFO - Starting mqtt thread
2021-12-18 21:00:07,940 - INFO - Starting serial port thread
2021-12-18 21:00:07,940 - DEBUG - [MQTT] Connected to broker (result code 0)
Serving Flask app "nad" (lazy loading)
Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
Debug mode: off
Traceback (most recent call last):
File "/var/www/html/plugins/script/data/nad.py", line 228, in
main(sys.argv[1:])
File "/var/www/html/plugins/script/data/nad.py", line 225, in main
app.run(host=config["restBindIp"], port=config["restBindPort"])
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 990, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 1052, in run_simple
inner()
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 1005, in inner
fd=fd,
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 848, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 740, in init
HTTPServer.init(self, server_address, handler)
File "/usr/lib/python2.7/SocketServer.py", line 420, in init
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 434, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
root@Ubuntu-Jeedom:~#
`
J’ai l’impression qu’il manque un argument mais je ne vois pas comment faire la chose.
De plus il y a un rest.service dont je ne sais pas trop quoi faire ^^:
[Unit]
Description=NAD RS232 REST-API Service
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/python /usr/local/bin/nad-rs232-rest.py
Restart=always
[Install]
WantedBy=multi-user.target
Comme client pour le broker je me suis dit que j’allais prendre JMQTT
Mais j’arrive au bout de mes compétences
Si vous avez des idées