Trotz intensiven Suchens habe ich keine fertige Lösung gefunden, wie man den Status eines Netzwerkdruckers (IPP-Supprt vorausgesetzt) innerhalb von Node-Red abfragen könnte.
Also selber ans Werk.
Nach einigen Suchen bin auf das Tool ipptool (sudo apt install cups-ipp-utils) gestoßen. Mit Hilfe von diesem Tool kann man den Status eines Druckers über IPP abfragen. Die folgende Bash-Datei (“printerstatus”) ruft den Status den Druckers (in meinem Fall IP 192.168.2.123) ab. Wenn der Drucker nicht erreichbar ist, wird ein Offline Status zurückgeliefert.
#!/bin/bash /usr/bin/ipptool -T 5 -c -t -v ipp://192.168.2.123/ipp/ get-printer-attributes.test || echo " printer-state-message (textWithoutLanguage) = Offline"
Ich habe die Datei unter “/home/pi/bin/printerstatus” abgelegt.
In Node-Red ist es keine große Herausforderung mehr. Die Datei regelmäßig aufrufen, die Ausgabe zeilenweise splitten, nach der Zeile “printer-state-message” suchen und das Ergebnisse ausgeben.
[{"id":"71745fbb.535e1","type":"exec","z":"379c0ed1.2ef2da","command":"/home/pi/bin/printerstatus","addpay":false,"append":"","useSpawn":"false","timer":"10","oldrc":false,"name":"Ipptool","x":270,"y":660,"wires":[["9afc54de.945c4"],[],[]]},{"id":"f6207655.510128","type":"inject","z":"379c0ed1.2ef2da","name":"30 sec","topic":"","payload":"","payloadType":"str","repeat":"30","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":660,"wires":[["71745fbb.535e1"]]},{"id":"9afc54de.945c4","type":"split","z":"379c0ed1.2ef2da","name":"Split \\n","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":460,"y":740,"wires":[["cdc67f9b.25fd5"]]},{"id":"cdc67f9b.25fd5","type":"switch","z":"379c0ed1.2ef2da","name":"Filter State","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"printer-state-message","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":640,"y":740,"wires":[["85cef94c.6ec2c8"]]},{"id":"41376012.1d44b","type":"ui_text","z":"379c0ed1.2ef2da","group":"2ca42408.15cfac","order":0,"width":"4","height":"1","name":"","label":"Status: ","format":"{{msg.payload}}","layout":"row-spread","x":690,"y":840,"wires":[]},{"id":"85cef94c.6ec2c8","type":"change","z":"379c0ed1.2ef2da","name":"Remove Prefix","rules":[{"t":"change","p":"payload","pt":"msg","from":"printer-state-message (textWithoutLanguage) =","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":840,"wires":[["41376012.1d44b"]]},{"id":"2ca42408.15cfac","type":"ui_group","z":"","name":"Geräte-Steuerung","tab":"d60df41e.ae9c2","order":1,"disp":true,"width":"6","collapse":false},{"id":"d60df41e.ae9c2","type":"ui_tab","z":"","name":"Geräte-Steuerung","icon":"dashboard","order":3}]
Das ipptool unterstützt auch eine XML-Ausgabe, da aber XML nicht gut in Node-Red zu verarbeiten ist, habe ich die Text-Ausgabe genutzt.