RS232 et ampli Nad

Bonjour,

Je voudrais piloter mon Nad c368 et cela est possible en passant par le port RS232 de l’ampli.
https://github.com/rbott/nad-rs232-rest

J’ai le câble qu’il faut, mon souci est de comprendre la partie soft ou il faut un MQTT broker.

J’ai regardé pour le MQTT Broker (How to Use The Paho MQTT Python Client - Beginners Guide) mais ce que je n’arrive pas à comprendre c’est comme trouver une IP de l’ampli à partir du port RS232.

Merci pour votre aide

Bonjour,
Cela n’a pas de rapport avec le core de jeedom ni avec un plug-in, j’ai donc déplacé le post.

Pour ce que vous voulez faire, vous avez besoin d’un pi sur lequel ce script python tournera, ce pi doit être connecté au port rs232 via votre câble.

Par ailleurs vous devez avoir installé un broker mqtt (=un serveur mqtt), regardez mosquito.
Celui-ci peut être installé sur le même pi ou ailleurs.

Le script aura besoin de l’ip de la machine sur lequel est installé le broker pour y envoyer les données lue sur l’interface rs232.

Enfin vous voudrez probablement lire ces infos sur le broker mqtt depuis un autre client pour les traiter.
Depuis jeedom avec un des plug-in mqtt (je suppose puisqu’on est sur le community de jeedom), manuellement avec un outils tel que mqtt explorer.

Vous n’avez donc pas besoin de l’ip de l’ampli (qui n’en a pas) mais du broker mqtt.

1 « J'aime »

Merci @Mips
Est il possible de s’affranchir d’un PI est d’installer sur une VM puis via USB <=> port série ?

Merci

Je ne suis pas l’auteur de l’outils, j’ignore s’il existe pour x86, je suppose que oui.

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.
Capture1
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 :frowning:

Si vous avez des idées :slight_smile: :slight_smile:

Hello,

Je vais répondre à moi même :slight_smile:
J’avance, le script semble fonctionner:

^Croot@Ubuntu-Jeedom:~# python /var/www/html/plugins/script/data/nad.py
2021-12-22 11:54:08,439 - INFO - Starting mqtt thread
2021-12-22 11:54:08,442 - INFO - Starting serial port thread
 * Serving Flask app "nad" (lazy loading)
 * Environment: production
2021-12-22 11:54:08,443 - DEBUG - [MQTT] Connected to broker (result code 0)
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
2021-12-22 11:54:08,447 - INFO -  * Running on http://0.0.0.0:3333/ (Press CTRL+C to quit)
2021-12-22 11:54:08,459 - INFO - [SERIAL] Connected to /dev/ttyUSB2 with 115200 Baud

Il me reste à comprendre comment utiliser la partie cliente avec le rest.service ou le curl.

root@Ubuntu-Jeedom:~# curl http://localhost:1883/nad/c368/v1.0/Main/Power
curl: (56) Recv failure: Connexion ré-initialisée par le correspondant

root@Ubuntu-Jeedom:~# curl -v -X PUT http://localhost:3333/nad/c368/v1.0/Main/Power/on
*   Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 3333 failed: Connexion refusée
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3333 (#0)
> PUT /nad/c368/v1.0/Main/Power/on HTTP/1.1
> Host: localhost:3333
> User-Agent: curl/7.58.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: application/json
< Content-Length: 110
< Server: Werkzeug/1.0.1 Python/2.7.17
< Date: Wed, 22 Dec 2021 11:23:20 GMT
<
{"command":"main.power","error":1,"errorMsg":"Did not receive a valid answer withing 4 seconds","value":null}
* Closing connection 0

Tout à l’air OK sur la connexion mais cela renvoie un code erreur :frowning:
Si quelqu’un veut creuser avec moi :slight_smile:

Hello,

Pour ceux que cela intéresse cela fonctionne et permet de piloter l’ampli.
Script adapté pour le python3. Si vous le souhaitez vous pouvez me contacter :slight_smile:

1 « J'aime »