From 44aafd5b9ce5faf33a224fadc8018a365acfcb9e Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Mon, 26 Oct 2020 18:17:33 -0700 Subject: [PATCH] Update to basic.js and add mime types. --- data/static/basic.js | 56 +++++++++++++++++---------------------- src/meshwifi/meshhttp.cpp | 5 ++-- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/data/static/basic.js b/data/static/basic.js index 38fd5078..5cbb8d72 100644 --- a/data/static/basic.js +++ b/data/static/basic.js @@ -2,50 +2,42 @@ 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(); + var httpconn = new meshtasticjs.IHTTPConnection(); + + // Set connection params + let sslActive; + if (window.location.protocol === 'https:') { + sslActive = true; + } else { + sslActive = false; + } + let deviceIp = window.location.hostname; // Your devices IP here + // 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!')}); + httpconn.addEventListener('fromRadio', function (packet) { console.log(packet) }); // Connect to the device async, then send a text message - connectionOne.connect() - .then(result => { + httpconn.connect(deviceIp, sslActive) + .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'); + alert('device has been configured') + // 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 httpconn.sendText('meshtastic is awesome'); - }) - .then(result => { + }) + .then(result => { - // This gets called when the message has been sucessfully sent - console.log('Message sent!');}) + // This gets called when the message has been sucessfully sent + console.log('Message sent!'); + }) - .catch(error => { console.log(error); }); + .catch(error => { console.log(error); }); } - - - - - - - diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index f0303418..fb4dc059 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -69,8 +69,9 @@ uint32_t timeSpeedUp = 0; // We need to specify some content-type mapping, so the resources get delivered with the // right content type and are displayed correctly in the browser -char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}, {".js", "text/javascript"}, - {".png", "image/png"}, {".jpg", "image/jpg"}, {"", ""}}; +char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}, {".js", "text/javascript"}, + {".png", "image/png"}, {".jpg", "image/jpg"}, {".gz", "application/gzip"}, + {".gif", "image/gif"}, {".json", "application/json"}, {"", ""}}; void handleWebResponse() {