Welcome to Our Community

Some features disabled for guests. Register Today.

Tech support for Javascript Macros in CONTROL

Discussion in 'Control Software' started by sharmstr, Jan 4, 2021.

  1. Alain JBT

    Alain JBT Well-Known
    Builder

    Joined:
    Apr 23, 2023
    Messages:
    56
    Likes Received:
    40
    Hi @Misterg
    Happy to see you again, thank you for your answer
    If you tested the BIG THING I will test it as if it were Christmas :)
    And as the proverb says with us "everything comes in time for who knows how to wait":thumbsup:
    Thank you very much and take care !
     
    Misterg likes this.
  2. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    27
    Likes Received:
    4
    Question; if you have the doorsensor enabled in the firmware.
    When you run a job, it will succesfully trigger.
    But when youre not running anything, you wont see anything, but controls are locked and the console will state: [14:59:10] [ ] [MSG:Check Door]
    Would it be possible to have a json macro to trigger a popup either when the door is triggered (although that doesnt show in the console), or show a popup when that Check Door message is returned?
    (I dont always have the console in view, so i wont see it otherwise)
     
  3. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,497
    Likes Received:
    4,421
    You should be able to yes,those statusses are available in that laststatus global object inside CONTROL (look at laststatus.comms.runStatus)

    https://github.com/gnea/grbl/wiki/Grbl-v1.1-Interface

    upload_2025-2-24_16-20-36.png

    Here's how we parse it for the bottom bar, we do show door status there:

    upload_2025-2-24_16-23-39.png



    https://github.com/OpenBuilds/OpenB...fa2d2ff082edb4c/app/js/websocket.js#L643-L664

    (use laststatus in place of status if copying above)
     
  4. BASt_NL

    BASt_NL New
    Builder

    Joined:
    Sep 9, 2022
    Messages:
    27
    Likes Received:
    4
    That does state " upload_2025-2-24_15-37-20.png indeed, completely missed that, thx
     
    Peter Van Der Walt likes this.
  5. wienans

    wienans New
    Builder

    Joined:
    Yesterday
    Messages:
    3
    Likes Received:
    0
    Hey Guys,

    i have the following use case. I want to have only one PC controlling multiple Blackbox X32 in parallel. For that i found that normally the CONTROL Software only streams the data and i need to use the SD Card.

    Currently i have this:

    Code:
    let fileInput = document.createElement("input");
    fileInput.type = "file";
    fileInput.style.display = "none";
    document.body.appendChild(fileInput);
    
    fileInput.addEventListener("change", async function() {
        if (fileInput.files.length === 0) {
            console.log("No file selected.");
            return;
        }
        
        let file = fileInput.files[0];
        let formData = new FormData();
        
        // Add the path parameter
        formData.append("path", "/");
        
        // Add the file size (adjust key name as needed)
        formData.append(file.name + "S", file.size);
        
        // Append the file with correct field name and MIME type
        formData.append("myfiles", file, file.name);
        console.log(formData);
        try {
            let response = await fetch("http://192.168.0.56/sdfiles?t=" + Date.now(), {
                method: "POST",
                mode: "no-cors",
                headers: {
                    "Accept": "*/*",
                    "Origin": "http://192.168.0.56",
                    "Referer": "http://192.168.0.56/",
                    "Pragma": "no-cache",
                    "Cache-Control": "no-cache"
                },
                body: formData
            });
            console.log(response);
            if (!response.ok) {
                throw new Error("Upload failed with status " + response.status);
            }
            
            let result = await response.text();
            console.log("Upload successful:", result);
            alert("File uploaded successfully!");
        } catch (error) {
            console.error("Error uploading file:", error);
            alert("File upload failed: " + error);
        }
    });
    
    let uploadButton = document.createElement("button");
    uploadButton.textContent = "Upload File to SD Card2";
    uploadButton.addEventListener("click", function() {
        fileInput.click();
    });
    $("#controlBtnGrp").before(uploadButton);
    The biggest problem now is CORS as i get the opaque response from the WebUI Plugin. I found that the Web UI can be build with CORS Enabled, is there a reason why you ship the WEB UI in your Firmware without CORS, i think the risk is minimal as it is a local application and would enable easy access for more advanced usecases?

    Additionally the IP Address is hardcoded as you can see. I didn't find documentation about what variables might be usable. Is there a variable which already stores the ip address of the currently connected board, so i can easily use it here?

    Maybe is there a other way to upload data to the SD Card? Maybe such macros already exist but i couldn't find it?

    Thanks in advance
     
  6. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,497
    Likes Received:
    4,421
    We just use the standard download from https://github.com/grblHAL/Plugin_WebUI when preinstalling, and certainly encourage you to build with any custom options you need and upgrade WebUI every so often too (it is seperate from firmware update)


    Not that we know of at this time. For us its mainly CONTROL-over-Telnet OR SD/WebUI - never really meant to be mixed together, so nothing like that already exists

    Should be in laststatus too https://github.com/OpenBuilds/OpenB...3097f467e5933861fa2d2ff082edb4c/index.js#L501
     
    wienans likes this.
  7. wienans

    wienans New
    Builder

    Joined:
    Yesterday
    Messages:
    3
    Likes Received:
    0
    Hi Peter, thanks for your quick reply.

    As the Firmware Flashing Tool looks to be used for your Main firmware is there any chance that there is documentation on how to upload the new WebUI?
     
  8. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,497
    Likes Received:
    4,421
    See https://github.com/grblHAL/Plugin_WebUI for instructions (upload latests index.gz via web interface)
     
  9. wienans

    wienans New
    Builder

    Joined:
    Yesterday
    Messages:
    3
    Likes Received:
    0
    Ah okay now i think i get it and maybe we talked past each other. Actually the WebUI itself does not need to be changed, and i think that is the only thing which can be updated via the WebUI itself. Its the Plugin_WebUI which needs to be recompiled with CORS Enabled.
    https://github.com/grblHAL/Plugin_WebUI/blob/46343716473a2681d24e081e989082e1ddc880e5/server.c#L661

    Therefore i assume the base firmware needs to be updated?
     
  10. Peter Van Der Walt

    Peter Van Der Walt OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 1, 2017
    Messages:
    15,497
    Likes Received:
    4,421
    Yes, that seems to be inside firmware itself, so custom compile needed and doesn't seem to be an option in WebBuilder https://svn.io-engineering.com:8443/?driver=ESP32&board=BlackBox X32 so likely have to go through https://github.com/grblHAL/ESP32?tab=readme-ov-file#how-to-build-using-esp-idf-v43

    At which point, maybe skip the Macro / HTTP post in parallel to Telnet connection, etc idea entirely:

    Fork and work on the core CONTROL code, implement Y-Modem upload directly inside index.js https://github.com/grblHAL/Plugin_SD_card?tab=readme-ov-file#ymodem - that way everyone can upload via serial/telnet without having to http requests, no CORS issues etc.

    Also no need for custom firmware compiles and all that difficulty, can be enabled straight from Web Builder

    upload_2025-3-12_14-2-2.png

    Definately the easier (and more correct way) in the end.

    Happy to merge a pull request once you have it nicely working.

    You can add a SD button to toolbar, with dropdown menu items for mount, list (brings up popup to select file to run, or delete, etc), upload etc https://github.com/grblHAL/Plugin_SD_card?tab=readme-ov-file#sd-card

    Now that would be nicer, and in-band (same comms protocol as connection)

    Can move discussion to Github if you'd like to work on that. We already have xmodem as a depencency (was going to add that for fluidnc but never had time to work on that further and interest waned) https://github.com/OpenBuilds/OpenBuilds-CONTROL/issues/283 - sadly that particular point not worked on yet, but was sort of same design/same plan
     
    wienans likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice