A tiny Python script connects to ws://YOUR_IP:3030/websocket to send pause (129), stop (130), and resume (131) commands.
⚠️ Replace YOUR_IP with your printer’s IP (and the MainboardID if needed) before running.
Usage rapide
# 1) pip install websocket-client
# 2) Exemples :
python centauri_ws.py --ip 192.168.1.174 pause
python centauri_ws.py --ip 192.168.1.174 stop
python centauri_ws.py --ip 192.168.1.174 resume
centauri_ws.py
import json, time, uuid, argparse, websocket
def now_ms():
return int(time.time() * 1000)
def new_id32():
# 32 hex chars (comme "979d4C78...")
return uuid.uuid4().hex[:32]
def new_req_id():
return uuid.uuid4().hex
# Codes vus/inférés :
CMD_PAUSE = 129 # pause
CMD_STOP = 130 # stop
CMD_RESUME = 131 # resume
def build_payload(cmd, data=None, mainboard_id=""):
if data is None:
data = {}
return {
"Id": new_id32(),
"Data": {
"Cmd": cmd,
"Data": data,
"RequestID": new_req_id(),
"MainboardID": mainboard_id or "",
"TimeStamp": now_ms(),
"From": 1
}
}
def detect_mainboard_id(ws, timeout=2.0):
"""Essaie de lire quelques messages pour trouver un MainboardID."""
ws.settimeout(timeout)
mbid = ""
try:
for _ in range(10):
raw = ws.recv()
# print("←", raw)
try:
pkt = json.loads(raw)
mbid = (
pkt.get("Data", {}).get("MainboardID")
or pkt.get("MainboardID")
or mbid
)
# Certaines implémentations renvoient des topics SDCP/MQTT-like
# où l'ID est dans Data/MainboardID des responses.
if mbid:
break
except Exception:
pass
except Exception:
pass
return mbid
def send_and_print(ws, payload):
msg = json.dumps(payload, separators=(",", ":"))
ws.send(msg)
print("→", msg)
def main():
p = argparse.ArgumentParser()
p.add_argument("--ip", required=True, help="IP de la Centauri (ex: 192.168.1.174)")
p.add_argument("--port", type=int, default=3030)
p.add_argument("--path", default="/websocket")
p.add_argument("--mainboard", default="", help="MainboardID connu (sinon auto)")
p.add_argument("action", choices=["pause","stop","resume"])
args = p.parse_args()
ws_url = f"ws://{args.ip}:{args.port}{args.path}"
# L’Origin vu dans ton dump était http://IP:3030
origin = f"http://{args.ip}:{args.port}"
print(f"Connexion → {ws_url}")
ws = websocket.create_connection(
ws_url,
timeout=5,
header=[f"Origin: {origin}"]
)
mainboard_id = args.mainboard or detect_mainboard_id(ws)
if mainboard_id:
print("MainboardID détecté:", mainboard_id)
else:
print("MainboardID non détecté (ok, on envoie quand même vide).")
if args.action == "pause":
payload = build_payload(CMD_PAUSE, data={}, mainboard_id=mainboard_id)
send_and_print(ws, payload)
elif args.action == "stop":
payload = build_payload(CMD_STOP, data={}, mainboard_id=mainboard_id)
send_and_print(ws, payload)
elif args.action == "resume":
# Historiquement, on a vu un Data = {"Ack":0} dans les échanges du 131
payload = build_payload(CMD_RESUME, data={"Ack": 0}, mainboard_id=mainboard_id)
send_and_print(ws, payload)
# Lis quelques réponses pour debug
ws.settimeout(3)
try:
while True:
print("←", ws.recv())
except Exception:
pass
ws.close()
if __name__ == "__main__":
main()
[–]rtuite81 Volunteer Moderator 0 points1 point2 points (0 children)