mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-20 03:52:39 +00:00
Merge pull request #502 from mc-hamster/master
Update to basic.js and add mime types.
This commit is contained in:
commit
b1dae3608e
@ -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); });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user