Merge pull request #502 from mc-hamster/master

Update to basic.js and add mime types.
This commit is contained in:
Jm Casler 2020-10-26 18:18:16 -07:00 committed by GitHub
commit b1dae3608e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 34 deletions

View File

@ -2,50 +2,42 @@ var meshtasticClient;
var connectionOne; 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 // 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() { function connect() {
// Create new connection // 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 // Add event listeners that get called when a new packet is received / state of device changes
connectionOne.addEventListener('dataPacket', function(packet) { console.log(packet)}); httpconn.addEventListener('fromRadio', 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 // Connect to the device async, then send a text message
connectionOne.connect() httpconn.connect(deviceIp, sslActive)
.then(result => { .then(result => {
alert('device has been configured')
// This gets called when the connection has been established // 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 // -> 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'); return httpconn.sendText('meshtastic is awesome');
}) })
.then(result => { .then(result => {
// This gets called when the message has been sucessfully sent // This gets called when the message has been sucessfully sent
console.log('Message sent!');}) console.log('Message sent!');
})
.catch(error => { console.log(error); }); .catch(error => { console.log(error); });
} }

View File

@ -70,7 +70,8 @@ uint32_t timeSpeedUp = 0;
// We need to specify some content-type mapping, so the resources get delivered with the // 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 // right content type and are displayed correctly in the browser
char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}, {".js", "text/javascript"}, char contentTypes[][2][32] = {{".txt", "text/plain"}, {".html", "text/html"}, {".js", "text/javascript"},
{".png", "image/png"}, {".jpg", "image/jpg"}, {"", ""}}; {".png", "image/png"}, {".jpg", "image/jpg"}, {".gz", "application/gzip"},
{".gif", "image/gif"}, {".json", "application/json"}, {"", ""}};
void handleWebResponse() void handleWebResponse()
{ {