modrzew / hass-flashforge-adventurer-3

Home Assistant integration providing support for the FlashForge Adventurer 3 3D printer.
20 stars 10 forks source link

Adventurer3X Support #2

Closed taikun114 closed 1 year ago

taikun114 commented 1 year ago

I am using Adventurer3X. (probably a Japan-only model) When I set it up with this custom integration, the camera, print progress, and status entities were added, but the temperature and other sensors do not show up. This 3D printer is almost identical to the Adventurer3 (the only difference is that it supports metal filaments) and I think I can do it by renaming the supported models like the person in this issue ( #1 ), but I have no coding skills and know nothing about it, so I don't really know.

スクリーンショット 2022-09-12 15 51 40 スクリーンショット 2022-09-12 15 52 25

I would be very happy to support this. Thanks.

modrzew commented 1 year ago

Hey there @taikun114! If the sensors don't work as expected then it most likely means Adventurer 3 and Adventurer 3X use different protocols to communicate with the outside world. It won't be as simple as changing the supported model in the dropdown. I only own Adventurer 3 so I can't help much with that. Sorry about that.

taikun114 commented 1 year ago

I tried manually installing the edited file in custom_components and reconfiguring it, but it did not work. The camera, print progress, and status entities still work fine, but no other temperature sensors, etc. were displayed at all.

スクリーンショット 2022-09-14 22 02 41 スクリーンショット 2022-09-14 22 02 03

I guess I'll just have to accept that Adventurer 3 and Adventurer 3X have different communication protocols with the outside world. Thank you very much!

taikun114 commented 1 year ago

Today I had the opportunity to print with a 3D printer and tried it out.

スクリーンショット 2022-09-16 21 05 56 I assumed that it was working because the print progress and status entities were displayed, but when I checked it while printing today, the print progress changed from "offline" to "online" but not to "printing", and the status entity, it did not progress from "0%" as far as the entity was concerned. So, as far as Adventurer 3X is concerned, I have found that this plugin does not work except for viewing the camera. That's all for the report of the behavior information. Thank you very much.

modrzew commented 1 year ago

Thanks for double checking that! If you want, you can try using Wireshark to analyse the traffic between your FlashForge app on your computer, and the printer.

Here are the commands this integration uses to interact with Adventurer 3: https://github.com/modrzew/hass-flashforge-adventurer-3/blob/master/custom_components/flashforge_adventurer_3/protocol.py#L9-L11. Once you have that, you can pretty much fork this repo or try to write your own integration 🙂

taikun114 commented 1 year ago

Thanks for the reply. I have absolutely no knowledge on such things, but I will try to see if there is anything I can do.

taikun114 commented 1 year ago

I installed Wireshark and checked it. I do not know how to use Wireshark, and I am not sure if I am analyzing it correctly, but I got the following results.

PRINT_JOB_INFO_COMMAND was exactly the same "M27". スクリーンショット 2022-09-17 20 25 38

TEMPERATURE_COMMAND was also exactly the same "M105". スクリーンショット 2022-09-17 20 25 58

However, the command "M601 S1" in STATUS_COMMAND was not found, but instead "M119" was found. However, I have a feeling that this is not a status command. スクリーンショット 2022-09-17 20 26 33

From the above, I think I can get the print progress and temperature, but is there anything you can find out? It was not clear to me.

modrzew commented 1 year ago

Ah, interesting. So the integration sends the status command (~M601 S1) but doesn't really care about the response. I based my code on another repository I found (https://github.com/Slugger2k/FlashForgePrinterApi/), where the status command was sent as the first one. I never checked if it could be skipped.

The responses you posted are pretty much the same as the ones the integration is expecting... so maybe it's just my poorly written regular expression not matching it correctly? Maybe it's the whitespace? ¯\(ツ)\

Do you have Python available in your environment? If so, can you try running this snippet, replacing 1.2.3.4 with the IP address of your printer:

import socket
with socket.socket() as s:
    s.connect(('1.2.3.4', 8899))
    s.sendall(b'~M105\r\n')
    data = s.recv(1024)
print(data)

It'll open the connection with the printer and send the ~M105\r\n command to get the temperature, and then print out the response in one line, hopefully as bytes instead of text. This is what I got for my printer:

b'CMD M105 Received.\r\nT0:23/0 B:14/0\r\nok\r\n'
taikun114 commented 1 year ago

I tried, but it didn't seem to work. スクリーンショット 2022-09-17 21 18 12

taikun114 commented 1 year ago

Oh, I disconnected the flashprint and tried the command again, and got a response similar to yours! But nothing changed on the plugin side (even after restarting Home Assistant). スクリーンショット 2022-09-17 21 46 42

taikun114 commented 1 year ago

Also, I ran a packet analysis on Wireshark when connecting to FlashPrint, and it appears it was receiving M601! スクリーンショット 2022-09-17 21 49 38

taikun114 commented 1 year ago

Sorry for repeating myself. I just checked my home assistant dashboard and the print status is in progress! Perhaps I disconnected from FlashPrint so it could connect to the Home Assistant plugin. However, as usual, the temperature sensor, etc. did not appear after restarting the Home Assistant and plugin. スクリーンショット 2022-09-17 21 55 22

modrzew commented 1 year ago

Oh, I disconnected the flashprint and tried the command again, and got a response similar to yours! But nothing changed on the plugin side (even after restarting Home Assistant). スクリーンショット 2022-09-17 21 46 42

I think I see the issue: for whatever the reason, there's an extra space before the first slash in the response. For Adventurer 3 it's T0:23/0, for Adventurer 3X it's T0:221 /220. I think the same applies for the progress one, I can see an extra space there as well. No clue why it suddenly started working when it was at 91% though.

Thanks for investigating this, fortunately it'll really easy to fix — and sorry for assuming earlier that these two printers are completely different 🙂

taikun114 commented 1 year ago

I see. Indeed, I did not notice the space in front of slash. As for the progress, I think it looks like there is a space because the Wireshark display is separated by every 8 characters, but I don't think there is actually a space. So I suspect that's why it worked. Anyway, I'm so glad to hear you can support this 3D printer! Thank you!

modrzew commented 1 year ago

Hey @taikun114, sorry for the delay. I just pushed a small change to the temperature regexp to the master branch: https://github.com/modrzew/hass-flashforge-adventurer-3/commit/a9d22dac73e76851853f4aa13d8cb65eff826550.

Do you mind trying it out in your Home Assistant? You should be able to redownload it, making sure to select master from the version dropdown. Let me know if it works — if it does, I'll release it as a new version and update the readme.

taikun114 commented 1 year ago

I tried it, but the temperature sensor, etc. is not displayed as before.

taikun114 commented 1 year ago

Sorry, I didn't check enough. I was just checking things out and I can confirm that the temperatures are showing up just fine! Seems to be working properly, as previously it was only showing "online" and "progress"! スクリーンショット 2022-09-23 21 42 43

Thank you!

taikun114 commented 1 year ago

I even got the Home Assistant dashboard card set up successfully! スクリーンショット 2022-09-23 22 18 02

Thank you very much for making my 3D printer compatible with your plugin!