function ready() {
    //machiineconnect("ws://localhost:8088");
    console.log('11111111111111111111111')
    //Ardublockly.initLanguage();
    $('.dropdown-trigger').dropdown();
    setTimeout(() => $('.modal').modal(), 0);

    blockpy = new BlockPy({
        blocklyPath: "blockly/",
        attachmentPoint: document.getElementById("blockpy-div"),
        instructor:
            !getQueryParams()["instructor"] ||
            getQueryParams()["instructor"] == "true",
        developer: true,
        editor: getQueryParams()["mode"] || "Split",
        urls: {

        }
    });


    setTimeout(() => {
        var _type = getLocalStorage("type") || 0;
        if (_type == 1) {
            $("#mode")[0].selectedIndex = 0;
            $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
            selectmode($("#mode")[0], true);
            appearExample(1);
        }
        else {
            $("#mode")[0].selectedIndex = 1;
            $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
            selectmode($("#mode")[0], true);
            appearExample(0);
        }
    }, 2000);

    function inIframe() {
        try {
            return window.self !== window.top;
        } catch (e) {
            return true;
        }
    }
    if (inIframe()) {
        $("#blockpy-container").width("100%");
        $("#blockpy-div").css("padding", 0);
    }
};


function selectmode(sel, isload) {
    var _type = getLocalStorage("type");
    if (sel.selectedIndex == 1 && (_type != 1 || isload === true)) {
        saveLocalStorageBlocks("pythonai-mode-blocks-xml");
        saveLocalStorage("type", 1);
        blockpy.setAssignment(
            // settings
            {},
            // assignment
            {
                modules: {
                    added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "MainBoard", "ExtendedFunction"],
                    removed: ['A.I.Board']
                }
            },
            // programs
            {
                __main__: ""
            }
        );
        loadLocalStorageBlocks("pythonmc-mode-blocks-xml")
    }
    else if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
        saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
        saveLocalStorage("type", 0);
        blockpy.setAssignment(
            // settings
            {},
            // assignment
            {
                modules: {
                    added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "'aaa", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "A.I.Board", "ExtendedFunction"],
                    removed: ['MainBoard']
                }
            },
            // programs
            {
                __main__: ""
            }
        );
        loadLocalStorageBlocks("pythonai-mode-blocks-xml")
    }
}

function getQueryParams() {
    try {
        url = window.location.href;
        query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
        r_params = query_str.split("&");
        params = {};
        for (i in r_params) {
            param = r_params[i].split("=");
            params[param[0]] = param[1];
        }
        return params;
    } catch (e) {
        return {};
    }
}


/*
var aiySocket = new WebSocket("ws://localhost:8089");

aiySocket.onopen = function (event) {
    // aiySocket.send("hello");
};

aiySocket.onmessage = function (event) {
    console.log(event.data);
    dataReceived = event.data;
}

function functionSSH() {
    aiySocket.send("ls");
    aiySocket.send("scp ~/Downloads/python-blockly.py pi@" + document.getElementById("aiyip_input").value + ":/home/pi/python-blockly.py");
    aiySocket.send("ssh -t pi@" + document.getElementById("aiyip_input").value + " 'python3 /home/pi/python-blockly.py'");
}

function functionSSHStop() {
    aiySocket.send("ssh -t pi@" + document.getElementById("aiyip_input").value + " 'pkill -f python-blockly.py'");
}

*/