Created
January 3, 2025 11:32
-
-
Save lin-ycv/7464551c8e6408a6bed900961ecd0041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ╔═══════════════════════════════════════════════════════╗ | |
# ║░█▀▄░█▀█░█▄█░█▀▄░█░█░█▀▀░█░░░▀█▀░█▀▀░█▀█░▀█▀░░░░█▀█░█░█║ | |
# ║░█▀▄░█▀█░█░█░█▀▄░█░█░█░░░█░░░░█░░█▀▀░█░█░░█░░░░░█▀▀░░█░║ | |
# ║░▀▀░░▀░▀░▀░▀░▀▀░░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░░▀░░▀░░▀░░░░▀░║ | |
# ╚═══════════════════════════════════════════════════════╝ | |
# bambu_octoeverywhere/bambuclient.py | |
# Additional imports for sending HTTP requests | |
import urllib.request | |
# To be added in def __init__ | |
self.MsgEndpointSent = False | |
# To be added near the end _OnMessage function | |
# Inside `if self.State is not None:` | |
# This must be done before Octoeverywhere starts updating states with new value | |
if "print" in msg and not self.MsgEndpointSent and self.State.gcode_state != 'RUNNING': | |
self.MsgEndpointSent = False | |
if "print" in msg and not self.MsgEndpointSent and self.State.stg_cur == 2 and self.State.mc_remaining_time is not None and self.State.mc_remaining_time > 0: | |
self.MsgEndpointSent = True | |
endpoint = 'URLtoENDPOINT' | |
jsonObj = {'sn': f'{self.PrinterSn}', 'file': f'{self.State.GetFileNameWithNoExtension()}', 'remaining': f'{self.State.mc_remaining_time}'} | |
payload = json.dumps(jsonObj).encode('utf-8') | |
postReq = urllib.request.Request(endpoint, data=payload, method='POST') | |
try: | |
urllib.request.urlopen(postReq, timeout=0.1) | |
except: | |
pass | |
# Resume Octoeverywhere logic | |
# Before `self.StateTranslator.OnMqttMessage` | |
--- | |
# ╔═══════════════════════════════════════════════════════════════════════╗ | |
# ║░█▄█░█▀█░█▀█░█▀█░█▀▄░█▀█░█░█░█▀▀░█▀▄░█▀▀░█░░░▀█▀░█▀▀░█▀█░▀█▀░░░░█▀█░█░█║ | |
# ║░█░█░█░█░█░█░█░█░█▀▄░█▀█░█▀▄░█▀▀░█▀▄░█░░░█░░░░█░░█▀▀░█░█░░█░░░░░█▀▀░░█░║ | |
# ║░▀░▀░▀▀▀░▀▀▀░▀░▀░▀░▀░▀░▀░▀░▀░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░░▀░░▀░░▀░░░░▀░║ | |
# ╚═══════════════════════════════════════════════════════════════════════╝ | |
# moonraker_octoeverywhere/moonrakerclient.py | |
# Needs to be installed using companion install `./install.sh -companion` | |
# To check run `find / -name "octoeverywhere.secrets" 2>/dev/null` | |
# should return `/home/pi/.octoeverywhere-companion/octoeverywhere-store/octoeverywhere.secrets` after a few seconds | |
# Additional imports for sending HTTP requests | |
import urllib.request | |
# To be added near the start of _OnWsNonResponseMessage function | |
# Inside `if "filename" in jobObj:` | |
# After `self.MoonrakerCompat.OnPrintStart` | |
endpoint = 'URLtoENDPOINT' | |
endpointPayload = {'ip': f'{self.MoonrakerHostAndPort}', 'file': f'{fileName}', 'remaining': f'{jobObj["metadata"]["estimated_time"]}'} | |
endpointPayloadE = json.dumps(endpointPayload).encode('utf-8') | |
endpointReq = urllib.request.Request(endpoint, data=endpointPayloadE, method='POST') | |
try: | |
urllib.request.urlopen(endpointReq, timeout=0.1) | |
except: | |
pass | |
# Before `return` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment