mirror of
https://github.com/meshtastic/firmware.git
synced 2025-05-12 16:10:48 +00:00
Merge pull request #501 from mc-hamster/master
Fixed typo. Updated js library. Update root file handler.
This commit is contained in:
commit
91756d1fec
51
data/static/basic.js
Normal file
51
data/static/basic.js
Normal file
@ -0,0 +1,51 @@
|
||||
var meshtasticClient;
|
||||
var connectionOne;
|
||||
|
||||
|
||||
// run init when DOM is ready
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
// Create new client instance
|
||||
meshtasticClient = new meshtasticjs.Client;
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Important: the connect action must be called from a user interaction (e.g. button press), otherwise the browsers won't allow the connect
|
||||
function connect() {
|
||||
|
||||
// Create new connection
|
||||
connectionOne = meshtasticClient.createBLEConnection();
|
||||
|
||||
// Add event listeners that get called when a new packet is received / state of device changes
|
||||
connectionOne.addEventListener('dataPacket', function(packet) { console.log(packet)});
|
||||
connectionOne.addEventListener('userPacket', function(packet) { console.log(packet)});
|
||||
connectionOne.addEventListener('positionPacket', function(packet) { console.log(packet)});
|
||||
connectionOne.addEventListener('connected', function() { console.log('connected!')});
|
||||
connectionOne.addEventListener('disconnected', function() { console.log('disconnected!')});
|
||||
|
||||
// Connect to the device async, then send a text message
|
||||
connectionOne.connect()
|
||||
.then(result => {
|
||||
|
||||
// This gets called when the connection has been established
|
||||
// -> send a message over the mesh network. If no recipient node is provided, it gets sent as a broadcast
|
||||
return connectionOne.sendText('meshtastic is awesome');
|
||||
|
||||
})
|
||||
.then(result => {
|
||||
|
||||
// This gets called when the message has been sucessfully sent
|
||||
console.log('Message sent!');})
|
||||
|
||||
.catch(error => { console.log(error); });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
18
data/static/index.html
Normal file
18
data/static/index.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html class="no-js" lang="">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
|
||||
<script src="/static/meshtastic.js"></script>
|
||||
<script src="/static/basic.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<button id="connect_button" onclick="connect()">Connect to Meshtastic device</button>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Binary file not shown.
Binary file not shown.
@ -323,7 +323,7 @@ void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res)
|
||||
}
|
||||
|
||||
res->println("<h2>Upload new file</h2>");
|
||||
res->println("<p>This interface is experemntal!</p>");
|
||||
res->println("<p><b>*** This interface is experimental ***</b></p>");
|
||||
res->println("<p>This form allows you to upload files. Keep your filenames very short and files small. Big filenames and big "
|
||||
"files are a known problem.</p>");
|
||||
res->println("<form method=\"POST\" action=\"/upload\" enctype=\"multipart/form-data\">");
|
||||
@ -350,7 +350,8 @@ void handleStaticBrowse(HTTPRequest *req, HTTPResponse *res)
|
||||
modifiedFile.remove((modifiedFile.length() - 3), 3);
|
||||
res->print("<a href=\"" + modifiedFile + "\">" + String(file.name()).substring(1) + "</a>");
|
||||
} else {
|
||||
res->print("<a href=\"" + String(file.name()).substring(1) + "\">" + String(file.name()).substring(1) + "</a>");
|
||||
res->print("<a href=\"" + String(file.name()).substring(1) + "\">" + String(file.name()).substring(1) +
|
||||
"</a>");
|
||||
}
|
||||
res->println("</td>");
|
||||
res->println("<td>");
|
||||
@ -699,9 +700,35 @@ void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res)
|
||||
void handleRoot(HTTPRequest *req, HTTPResponse *res)
|
||||
{
|
||||
res->setHeader("Content-Type", "text/html");
|
||||
res->setHeader("Content-Encoding", "gzip");
|
||||
|
||||
File file = SPIFFS.open("/static/index.html.gz");
|
||||
std::string filename = "/static/index.html";
|
||||
std::string filenameGzip = "/static/index.html.gz";
|
||||
|
||||
if (!SPIFFS.exists(filename.c_str()) && !SPIFFS.exists(filenameGzip.c_str())) {
|
||||
// Send "404 Not Found" as response, as the file doesn't seem to exist
|
||||
res->setStatusCode(404);
|
||||
res->setStatusText("Not found");
|
||||
res->println("404 Not Found");
|
||||
res->printf("<p>File not found: %s</p>\n", filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to open the file from SPIFFS
|
||||
File file;
|
||||
|
||||
if (SPIFFS.exists(filename.c_str())) {
|
||||
file = SPIFFS.open(filename.c_str());
|
||||
if (!file.available()) {
|
||||
DEBUG_MSG("File not available - %s\n", filename.c_str());
|
||||
}
|
||||
|
||||
} else if (SPIFFS.exists(filenameGzip.c_str())) {
|
||||
file = SPIFFS.open(filenameGzip.c_str());
|
||||
res->setHeader("Content-Encoding", "gzip");
|
||||
if (!file.available()) {
|
||||
DEBUG_MSG("File not available\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Read the file from SPIFFS and write it to the HTTP response body
|
||||
size_t length = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user