tools.js
A tools.js JavaScript facilitates programming, making code more transparent.
Examples
Establishing WebSocket Connection.
The system can handle a maximum of 4 WebSocket connections simultaneously!
startWS(0);
This function establishes a WebSocket connection. It does not handle connection loss.
startWS(1);
Uses the ReconnectingWebSocket('ws://....'); function to connect. Automatically reconnects after unsuccessful attempts. Takes ~10 sec.
startWS(2);
Also uses the above function, combined with the HEART command. If no (HEART) message is received from the module within 2.5 seconds, it reconnects.
startWS(3);
Creates a connection. If the page loses focus, it closes the connection; if it regains focus, it reopens it.
startWS(4);
Creates a connection if the value of document.getElementById("wspw").value matches the WebSocket password set in the Setup/Password menu. The function onMessage(msg) works even without a match.
closeWS();
Closes the connection.
sendWS("Message");
Sends a message to the module.
function onOpen() { }
Executes after successful connection.
function onClose() { }
Executes if the connection is lost.
function onMessage(msg) { }
Executes when a message is received from the module.
function onExit() { }
Executes before the page is closed.
These functions should only be added to the code if needed. Omitting any of them will not cause errors.
WebSocket startWS(2)
WebSocket startWS(3)
WebSocket startWS(4)
Loading File into Variable.
getFile("filename");
The function returns the content of the file. If the file does not exist, "Error 404" is returned.
STR[0]=blablabla|
STR[0]#example.txt
FILE
Sdiv
You can create a label (Slabel), button (Sbutton), toggle switch (Stoggle), indicator lamp (Slamp), slider (Srange), status bar (Sbar), analog gauge (Smeter), color picker (Scolor), graph (Sgraph), and popup alert (Salert) within a fully customizable container (Sdiv). Examples are available after uploading the Sdemo.tar file located in the plugins folder.