Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Plugin loads but doesn't find the printer ever. #9

Closed
jallen2281 opened this issue Aug 14, 2022 · 22 comments
Closed

Plugin loads but doesn't find the printer ever. #9

jallen2281 opened this issue Aug 14, 2022 · 22 comments

Comments

@jallen2281
Copy link

The plugin isn't working correctly and cannot find my printer attached to the same wifi, or even hard wired to the same network. Network is wide open, firewall rules in place. Below is the Cura log.

2022-08-14 14:11:11,147 - INFO - [MainThread] UM.PluginRegistry.loadPlugin [493]: Loaded plugin SettingsGuide2 2.9.0 2022-08-14 14:11:11,192 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.24.64.1 2022-08-14 14:11:11,194 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.22.32.1 2022-08-14 14:11:11,196 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.18.16.1 2022-08-14 14:11:11,197 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 192.168.1.181 2022-08-14 14:11:11,198 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.237.178 2022-08-14 14:11:11,199 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.114.113 2022-08-14 14:11:11,201 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.168.112 2022-08-14 14:11:11,202 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.3.80 2022-08-14 14:11:11,204 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.104.157 2022-08-14 14:11:11,205 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.113.228 2022-08-14 14:11:11,206 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.62.62 2022-08-14 14:11:11,207 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.159.183 2022-08-14 14:11:11,208 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.139.228 2022-08-14 14:11:11,210 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 192.168.1.249 2022-08-14 14:11:11,211 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 169.254.47.78 2022-08-14 14:11:11,212 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.17.64.1 2022-08-14 14:11:11,213 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.28.224.1 2022-08-14 14:11:11,213 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.31.176.1 2022-08-14 14:11:11,214 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.20.48.1 2022-08-14 14:11:11,216 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.29.0.1 2022-08-14 14:11:11,217 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.27.160.1 2022-08-14 14:11:11,217 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [75]: Discovering printers on network interface: 172.25.32.1 2022-08-14 14:11:11,219 - DEBUG - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.__init__ [99]: '0' tokens loaded. 2022-08-14 14:11:11,220 - INFO - [MainThread] UM.PluginRegistry.loadPlugin [493]: Loaded plugin Snapmaker2Plugin 7.2.0 2022-08-14 14:11:11,303 - INFO - [MainThread] UM.PluginRegistry.loadPlugin [493]: Loaded plugin ThingiBrowser 3.0.0 2022-08-14 14:11:11,309 - DEBUG - [MainThread] UM.PluginRegistry.loadPlugins [416]: Loading all plugins took 2.534653425216675 seconds 2022-08-14 14:11:11,330 - INFO - [MainThread] UM.VersionUpgradeManager.upgrade [163]: Looking for old configuration files to upgrade. 2022-08-14 14:11:11,619 - INFO - [MainThread] UM.VersionUpgradeManager.upgrade [177]: Checking and performing updates took 0.2895798683166504 2022-08-14 14:11:11,637 - INFO - [MainThread] UM.Qt.QtApplication.startSplashWindowPhase [265]: Completed loading preferences. 2022-08-14 14:11:11,661 - INFO - [MainThread] UM.Qt.QtApplication.startSplashWindowPhase [300]: Created system tray icon. 2022-08-14 14:11:13,078 - DEBUG - [MainThread] UM.Settings.ContainerRegistry.loadAllMetadata [548]: Loading metadata into container registry took 1.4096324443817139 seconds 2022-08-14 14:11:13,094 - DEBUG - [MainThread] cura.Scene.CuraSceneController.setActiveBuildPlate [142]: Select build plate: 0 2022-08-14 14:11:13,094 - INFO - [MainThread] cura.CuraApplication.run [823]: Initializing machine error checker 2022-08-14 14:11:13,299 - WARNING - [MainThread] LocalContainerProvider.LocalContainerProvider._saveCachedDefinition [308]: The definition cache for definition snapmaker2_A350 failed to pickle. 2022-08-14 14:11:13,299 - INFO - [MainThread] cura.UI.MachineActionManager.addDefaultMachineActions [74]: Default machine actions added for machine definition [snapmaker2_A350] 2022-08-14 14:11:13,521 - WARNING - [MainThread] LocalContainerProvider.LocalContainerProvider._saveCachedDefinition [308]: The definition cache for definition snapmaker2 failed to pickle. 2022-08-14 14:11:13,718 - INFO - [MainThread] cura.Settings.GlobalStack.addExtruder [192]: Extruder[snapmaker_extruder_0 #2] added to [Snapmaker 2 A350] at position [0] 2022-08-14 14:11:13,723 - INFO - [MainThread] FirmwareUpdateChecker.FirmwareUpdateChecker.checkFirmwareVersion [79]: No machine with name Snapmaker 2 A350 in list of firmware to check. 2022-08-14 14:11:14,272 - DEBUG - [MainThread] cura.Machines.ContainerTree.__getitem__ [120]: Adding container tree for snapmaker2_A350 took 0.5477147102355957 seconds. 2022-08-14 14:11:14,289 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: ChangeAtZ 2022-08-14 14:11:14,289 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: ColorMix 2022-08-14 14:11:14,289 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: CreateThumbnail 2022-08-14 14:11:14,289 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: DisplayFilenameAndLayerOnLCD 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: DisplayProgressOnLCD 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: FilamentChange 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: InsertAtLayerChange 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: PauseAtHeight 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: RetractContinue 2022-08-14 14:11:14,304 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: SearchAndReplace 2022-08-14 14:11:14,320 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: Stretch 2022-08-14 14:11:14,320 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: TimeLapse 2022-08-14 14:11:14,320 - DEBUG - [MainThread] PostProcessingPlugin.PostProcessingPlugin.loadScripts [206]: Begin loading of script: UsePreviousProbeMeasurements 2022-08-14 14:11:14,508 - WARNING - [MainThread] LocalContainerProvider.LocalContainerProvider._saveCachedDefinition [308]: The definition cache for definition fdmprinter failed to pickle. 2022-08-14 14:11:14,524 - INFO - [MainThread] Snapmaker2Plugin.SM2OutputDeviceManager.start [108]: Snapmaker2Plugin started.

@brohirrim
Copy link

I have the same issue. My snapmaker is on the newest version. I even hacked the source code to find the correct IP of my printer (I could see in the above log that it wasn't finding my printers IP) and tried to add a socket for it but no luck:

for device in os.popen('arp -a'): if device.strip().startswith("192."): ip=device.strip().split()[0] if ip not in ips and not ip.endswith('.255'): Logger.log("i", "Hack discovering printers on network interface : {0}".format(ip)) ips.append(ip) ipAddress = QHostAddress(ip) socket = QUdpSocket() socket.bind(ipAddress) socket.readyRead.connect(lambda: self._udpProcessor(socket)) self._discover_sockets.append(socket)

@brohirrim
Copy link

This is not fixed. I followed the troubleshooting guide for hours. Firewall is correctly configured. Plugin used to work for me but now does not on snapmaker version 1.14.3.
In the log, I can see that it doesn't find the printer IP. My printer IP is 192.168.0.122 and I can ping it from my PC (so my PC can definitely connect to it), but the plugin doesn't find it:
Discovering printers on network interface: 169.254.176.115
Discovering printers on network interface: 169.254.238.95
Discovering printers on network interface: 192.168.56.1
Discovering printers on network interface: 169.254.76.242
Discovering printers on network interface: 169.254.205.54
Discovering printers on network interface: 169.254.10.226
Discovering printers on network interface: 192.168.0.119
Discovering printers on network interface: 169.254.205.171

@macdylan
Copy link
Owner

macdylan commented Sep 5, 2022

Hi, @brohirrim

Does LUBAN work correctly? If not, i can do nothing, I fully implemented the snapmakers protocol in this plugin.

@brohirrim
Copy link

brohirrim commented Sep 5, 2022 via email

@jallen2281
Copy link
Author

Wow, way to ignore issue request. This is not fixed. Additionally, @macdylan your response is insulting. You may as well be asking if we checked the power cord. Most of us on GitHub are professionals. Please reopen and actually fix this.

@macdylan macdylan reopened this Sep 20, 2022
@macdylan
Copy link
Owner

macdylan commented Sep 23, 2022

Wow, way to ignore issue request. This is not fixed. Additionally, @macdylan your response is insulting. You may as well be asking if we checked the power cord. Most of us on GitHub are professionals. Please reopen and actually fix this.

I recently contacted Snapmaker's software engineers and confirmed that there are some bugs in firmware version 1.14.x that cause the touchscreen to fail to respond broadcast messages, the solution is reconnect the network (usually restart the device).

They will soon release a firmware update to fix this issue, and i will also follow up.

Thanks for your fdbk.

@macdylan
Copy link
Owner

@jallen2281 Can you try the latest version?

@brohirrim
Copy link

Still doesn't seem to work for me

@macdylan
Copy link
Owner

Still doesn't seem to work for me

Can you post more information? Such as OS version, network connection type(wireless or wired), router model.

Thanks for your help.

@skyguy94
Copy link

skyguy94 commented Dec 12, 2022

The auto discovery mechanism isn't working for me either in the old version or new. I'm running Windows 11 on a Wifi connection using a Linksys Velop mesh.

I pulled up wireshark and when I start cura, I'm able to see the plugin send the UDP discover message.

image

I also see my snapmaker respond multiple times.

image

I added some log statements to the code and then tailed the cura log. I noticed that that the _udpProcesser lambda gets invoked, but hasPendingDatagrams() is never true.

    def _udpProcessor(self, socket):
        devices = set()
        while socket.hasPendingDatagrams():
            data = socket.receiveDatagram()
            if data.isValid() and not data.senderAddress().isNull():
                ip = data.senderAddress().toString()
                try:
                    msg = bytes(data.data()).decode("utf-8")
                    if "|model:" in msg and "|status:" in msg:
                        devices.add((ip, msg))
                    else:
                        Logger.log("w", "Unknown device %s from %s", msg, ip)
                except UnicodeDecodeError:
                    pass

I think its odd that readyRead is firing but hasPendingDatagrams() is false. I haven't had a chance to look through your new changes so I assume its still the same problem.

EDIT: Fixed some typos.

@macdylan
Copy link
Owner

@skyguy94 👍 Can you try the latest version?

https://github.com/macdylan/Snapmaker2Plugin/releases/tag/8.0.0

@skyguy94
Copy link

I just tried it and it doesn't work. I'll try some investigation in a bit, but a quick static review leaves me with some questions about the bind method:
(apologies if I'm just misunderstanding something, QT and python aren't my daily drivers).

        sock = QUdpSocket()

        bind_result = sock.bind(self._address_entry.ip(),
                                mode=QAbstractSocket.BindFlag.DontShareAddress
                                | QAbstractSocket.BindFlag.ReuseAddressHint)
        if not bind_result:
            return False

Would it be worth a trace or debug log if the bind fails?

        if Platform.isWindows():
            # On Windows, QUdpSocket is unable to receive broadcast data, we use original socket instead
            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                 socket.IPPROTO_UDP)
            sock.settimeout(0.2)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
            self._socket = sock

Should sock be wired to readyRead still? Without a lambda invocation, I don't see how the windows version is able to receive the socket data.

        else:
            # On Unix, we use socket interface provided by Qt 6
            self._socket = sock
            sock.readyRead.connect(self.__read)

        return True

@skyguy94
Copy link

Also, feel free to open a branch for team debugging. I've pulled this repo into my plugins folder for cura.

@parachvte
Copy link

parachvte commented Dec 12, 2022

@skyguy94

On Windows, the PyQt6 sock.readyRead is not triggered at all.

On my side, I've debugged with Wireshark, it turned out the broadcast reply was sent back by the server (the machine firmware). But PyQt6's socket's readyRead was not being emitted correctly.

So we use the low-level interface of python socket, it doesn't have readyRead signal.

Here is what we do the python socket:

  1. After sending discover message, we set a timer (0.2s delay) which triggers self.__collect() on timeout
  2. self.__collect() calls socket.recvfrom(128) to receive data.

@parachvte
Copy link

For debugging. I would suggest to add logs to

https://github.com/macdylan/Snapmaker2Plugin/blob/main/OutputDevicePlugin.py#L100

As the code below, I added 3 logs in the __collect() function, let's see what's going wrong with the data received.

def __collect(self) -> None:
    # the socket has abort and discover is cancelled
    if not self._socket:
        return

    if isinstance(self._socket, QUdpSocket):
        return

    Logger.debug("collecting data...")  # <-- add log here
    while True:
        try:
            msg, _ = self._socket.recvfrom(128)
        except (TimeoutError, ConnectionError) as e:
            # normal timeout, or ConnectionError (including ConnectionAbortedError, ConnectionRefusedError,
            # ConnectionResetError) errors raise by the peer
            Logger.debug("error receiving data... %s", e)  # <-- add log here
            break

        try:
            message = msg.decode("utf-8")
            self.dataReady.emit(message)
        except UnicodeDecodeError as e:
            Logger.debug("error decoding data... %s", e)  # <-- add log here
            pass

@skyguy94
Copy link

skyguy94 commented Dec 12, 2022

Ok, got it. The problem I had is here:


    def _onGlobalContainerStackChanged(self) -> None:
        if self._isSM2Container():
            self.start()
        else:
            self.stop()

    def _isSM2Container(self) -> bool:
        stack = Application.getInstance().getGlobalContainerStack()
        if not stack:
            return False
        machine_name = stack.getProperty("machine_name", "value")
        Logger.debug('machine name: %s', machine_name)
        return machine_name.startswith(MACHINE_SERIES)

where my machine_name returns Snapmaker A350 instead of Snapmaker 2 from MACHINE_SERIES

Here's the log where you can see what it returns and how the plugin just stops when its wrong.

2022-12-12 15:43:24,942 - INFO - [MainThread] UM.PluginRegistry.loadPlugin [493]: Loaded plugin Snapmaker2Plugin 8.0.0
2022-12-12 15:43:26,867 - DEBUG - [MainThread] Snapmaker2Plugin.OutputDevicePlugin._isSM2Container [274]: machine
name: Snapmaker A350
2022-12-12 15:43:26,867 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.stop [258]: Snapmaker discovering
stopped.

EDIT: I'm still not getting a printer, but the udp socket is getting data.

2022-12-12 15:58:56,067 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [94]: Started Collect
2022-12-12 15:58:56,068 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [99]: Checking Type
2022-12-12 15:58:56,068 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [105]: Receiving
2022-12-12 15:58:56,276 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [94]: Started Collect
2022-12-12 15:58:56,277 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [99]: Checking Type
2022-12-12 15:58:56,277 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [105]: Receiving
2022-12-12 15:58:56,278 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [113]: Decoding
2022-12-12 15:58:56,278 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__collect [115]:
A350@192.168.1.80|model:Snapmaker 2 Model A350|status:IDLE

With logging coming from custom log statements:


    def __collect(self) -> None:
        Logger.info("Started Collect")
        # the socket has abort and discover is cancelled
        if not self._socket:
            return

        Logger.info("Checking Type")
        if isinstance(self._socket, QUdpSocket):
            return

        while True:
            try:
                Logger.info("Receiving")
                msg, _ = self._socket.recvfrom(128)
            except (TimeoutError, ConnectionError):
                # normal timeout, or ConnectionError (including ConnectionAbortedError, ConnectionRefusedError,
                # ConnectionResetError) errors raise by the peer
                break

            try:
                Logger.info("Decoding")
                message = msg.decode("utf-8")
                Logger.info("%s", message)
                self.dataReady.emit(message)
            except UnicodeDecodeError:
                pass

EDIT2: Looks like its MACHINE_SERIES in __onData this time. The discovered machine series is Snapmaker 2 Model A350. Removing the check works around the problem for now.

2022-12-12 16:06:27,653 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__onData [229]: Model: Snapmaker 2
Model A350
2022-12-12 16:06:27,654 - INFO - [MainThread] Snapmaker2Plugin.OutputDevicePlugin.__onData [236]: Discovered Snapmaker
printer: A350@192.168.1.80 (token: '')

image

@macdylan
Copy link
Owner

I'm sorry for that mistake, It has been corrected, Please use 8.1.0

@skyguy94
Copy link

Closer. I had some edits in my comment that added more debugging info. There's a conflict for the value MACHINE_SERIES when its used in _isSM2Container and __onData

@brohirrim
Copy link

Sadly, 8.1 still does not work for me :(

@brohirrim
Copy link

brohirrim commented Feb 12, 2023

To add more details, I added this line in _isSM2Container:

Logger.debug('test stack: %s', stack)

and received this output:

2023-02-12 10:23:46,523 - DEBUG - [MainThread] Snapmaker2Plugin.OutputDevicePlugin._isSM2Container [275]: test stack: <GlobalStack 'Snapmaker 2.0 A350' containers=[<InstContainer 'Snapmaker 2.0 A350_user'>, <InstContainer 'custom_snapmaker_2.0_a350_(normal)'>, <InstContainer 'empty_intent'>, <InstContainer 'normal'>, <InstContainer 'empty_material'>, <InstContainer 'empty_variant'>, <InstContainer 'Snapmaker 2.0 A350_settings'>, <DefContainer 'custom'>]>
2023-02-12 10:23:46,523 - DEBUG - [MainThread] Snapmaker2Plugin.OutputDevicePlugin._isSM2Container [276]: machine name: Unknown

So it seems like my stack object does not have the machine name attribute. I am on the latest Snapmaker version (V1.15.12) and Cura 5.2.1. Again, Luban (4.5.1) connects to my printer with no issue. Is this just a config issue on my side?

editted: formatting and bad grammar

@parachvte
Copy link

Are you using a custom FFF printer?

If you added Snapmaker printer in Cura, you can check C:\Program Files\Ultimaker Cura\share\cura\resources\definitions, there are 4 files for Snapmaker printers: snapmaker.def.json, snapmaker2_A150.def.json, snapmaker2_A250.def.json, snapmaker2_A350.def.json.

e.g. In snapmaker2_A150.def.json, the machine name is specified

"overrides": {
    "machine_name": {
        "default_value": "Snapmaker A150"
    },
   ...
}

Once you activate a Snapmaker printer, the machine name should be defined name ("Snapmaker A150").

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants