Closed vivian-ng closed 5 years ago
Sorry, what the purpose of this PR? Unlike others porting of ESP3D, Marlin_esp32 does not support yet the M118 command for [ESPXXX], I did on purpose, because I wanted a direction for integration before implementing all features
Does your target is that ? because if WebUI is not open the command will be ignored. Better FW itself handle M118 output like I did for notifications : https://github.com/luc-github/ESP3D/wiki/Notifications#how-to-ask-printer-to-send-command-from-file-played-from-sd which works even WebUI is closed
@luc-github Actually it is specifically for the firmware to talk to the webUI. In my "example", if there is gcode M118 esp3d:eop
in the end gcode, it will cause the webUI to play a beep. This is useful for those who have the webUI open and want to be notified when a print has finished.
Additional uses include adding something to handle "heating done" to notify users after M109 or M190, users can add something like M118 esp3d:heated
to let the webUI know the required temperature has been reached.
Still, it is a "good to have" feature, so no issues if you don't want to merge this into the main repo.
I am not rejecting ^_^- I just try to understand - actually FW 'talk' already to webUI using websocket.
there are several messages sent to WebUI using SocketTXT : the connection ID the active ID the DHT temperature + humidity
the WsocketBin is used for the Serial output bridge.
I would like to understand the user cases, to see if no overlaping with other method. or if need more feature to complete it.
the idea is good as it does not need to modify FW to add new commands to webUI. The question is what kind of commands ? if many : It may need to add more to avoid WebUI to be rebuilted for each new command. may be command send Macro file name, present on flash, which is read by WebUI if it is just one command: it is just to do one or several beeps, the macro idea is overkill, and your PR is enough
So my questions ^_^
Your idea is just to do beep ? or your have something else in mind?
I originally just wanted the beep to let me know when my print is done. Which was why I did this. But I thought this can then be further expanded upon by others who may want to customize their webUI, so I thought this can serve as an example. ESP3D features should not be here; this is just an example/template for people who may want to add their own custom stuff.
ok in that case what about replace :
if (response.startsWith("esp3d:eop")) {
by
response = response.replace("esp3d:","");
if (response.startsWith("beep(")) {
and replace :
beep(dur, freq);
by
eval(response);
this make command flexible for freq and dur and prevent bad code injection I did not tested but should work
Okay, I will give it a try and if it works, I will update this.
I have tested the function handling and it works. What I have done is left both methods in the custom.js
file so that they can serve as examples for people who want to modify custom.js
to handle their custom messages/functions.
Also, changed to use [esp3d]
instead of esp3d:
as the colon, when used in a gcode file, was triggering Marlin to think it is a separate command.
Functionality tested with a gcode file having the following:
G4 S10
M118 [esp3d]eop
G4 S2
M118 [esp3d]beep(1000,261)
The sounds will play as long as the webUI is opened on any web browser tab, even if it is not the current active tab.
nice addition - thank you ^_^
@all-contributors please add @vivian-ng for code improvement
@luc-github
I've put up a pull request to add @vivian-ng! :tada:
I added a handler for custom messages. This allows the printer to send custom messages to the webUI via M118. In the "example", when the printer sends
esp3d:eop
on serial, the webUI will beep to signify end of the print. This means a gcode likeM118 esp3d:eop
can be added to the end gcode.As long as the message starts with
esp3d:
, the function to handle custom messages will be invoked. How the custom message is handled needs to be defined in thecustom.js
file.