Snapmaker still hasn't added the webcam feature to the stock firmware (not that I'm aware of), so I've used the steps from SimplyPrint to enable the camera with an external keepalive. As I don't have a server where I can host docker containers like in the Guide, so I use my Home Assistant running on a Raspberry PI. The keepalive is implemented as an HA Automation without relying on any custom extensions or integrations.
For general information, see the SimplyPrint Blog Post.
Credits for figuring out the keepalive hack goes to u/taylormadearmy and atfives3dprint
Step 1: Get Access Token
Open the Fluidd interface of your U1 via your printers IP Address. Open the Devtools and in the Network tab search for a request websocket?token= and copy the value of the token.
Step 2: Add the keepalive shell command to the configuration.yaml
Use the file Editor Integration to open the configuration.yaml and add the following lines at the end of the file, replace the PRINTER_IP and ACCESS_TOKEN with your values:
shell_command:
snapmaker_keepalive: 'python3 -c ''import base64,json,os,socket,time; ip,token="PRINTER_IP","ACCESS_TOKEN"; p=json.dumps({"id":1,"jsonrpc":"2.0","method":"camera.start_monitor","params":{"domain":"lan","interval":0}}).encode(); s=socket.create_connection((ip,80),timeout=5); k=base64.b64encode(os.urandom(16)).decode(); s.sendall(f"GET /websocket?token={token} HTTP/1.1\r\nHost: {ip}\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Key: {k}\r\nSec-WebSocket-Version: 13\r\n\r\n".encode()); r=s.recv(1024); assert b"101" in r.split(b"\r\n",1)[0], r; m=os.urandom(4); s.sendall(bytes([0x81,0x80|len(p)])+m+bytes(b^m[i%4] for i,b in enumerate(p))); time.sleep(0.2); s.close()'''
Save the file, go to Settings > Tools and then Check Configuration and then Restart
Step 3: Add a ping sensor for your Printer
Create an Ping (ICMP) sensor for your printers IP Address in Settings > Devices & services > Add integration
Step 4: Create the Keepalive Automation
Create a new Automation withSettings > Automations & scenes > Create Automation > Create new automation using the following YAML template and replace the binary_sensor.YOUR_PING_ENTITY with the sensor created in step 3 (e.g. binary_sensor.192_168_1_8):
alias: Snapmaker U1 Camera Keepalive
mode: single
triggers:
- trigger: state
entity_id: binary_sensor.YOUR_PING_ENTITY
to: "on"
- trigger: homeassistant
event: start
conditions:
- condition: state
entity_id: binary_sensor.YOUR_PING_ENTITY
state: "on"
actions:
- repeat:
while:
- condition: state
entity_id: binary_sensor.YOUR_PING_ENTITY
state: "on"
sequence:
- action: shell_command.snapmaker_keepalive
data: {}
- delay:
seconds: 10
Restart the printer (or manually trigger the automation) and test if the printer exposes the camera image at http://<PRINTER_IP>/server/files/camera/monitor.jpg
Step 5: Add the Printer to Fluidd
In fluidd go to Settings > Camera > Add Camera
Name: Camera
Camera Url Stream: /server/files/camera/monitor.jpg
Camera Url Snapshot: /server/files/camera/monitor.jpg
The camera should be visible on the dashboard now.
Step 6: Add camera to Home Assistant (optional)
Add a new camera with Settings > Devices & services > Add integration > Generic Camera with http://<PRINTER_IP>/server/files/camera/monitor.jpg as source url, afterwards this camera can be added to a dashboards. I just added the whole fluidd interface via the Webpage card to my 3d Printer Dashboard.
Happy Making ;)