-
-
Save Jerware/513ef19e03699ff1239a21f130dc7bfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Particle JS SDK Test</title> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/particle-api-js/5/particle.min.js"> | |
</script> | |
<script> | |
var particle = new Particle(); | |
var accessToken; | |
var deviceIdentifier; | |
function loginToParticle() | |
{ | |
particle.login({username: 'XXXXXXXX', password: 'XXXXXXXX'}).then( | |
function(data){ | |
accessToken = data.body.access_token; | |
console.log("accessToken=" + accessToken); | |
listParticleDevices(); | |
}, | |
function(err) { | |
console.log('API call completed on promise fail: ', err); | |
} | |
); | |
} | |
function listParticleDevices() | |
{ | |
var devicesPr = particle.listDevices({ auth: accessToken }); | |
devicesPr.then( | |
function(devices){ | |
console.log('Devices: ', devices); | |
deviceIdentifier = devices.body[0].id; | |
console.log("deviceId: " + deviceIdentifier); | |
flashParticleFirmware(); | |
}, | |
function(err) { | |
console.log('List devices call failed: ', err); | |
} | |
); | |
} | |
function flashParticleFirmware() | |
{ | |
var flashPr = particle.flashDevice({ deviceId: deviceIdentifier, | |
files: { file1: './file.bin' }, | |
auth: accessToken }); | |
flashPr.then( | |
function(data) { | |
console.log('Device flashing started successfully:', data); | |
}, function(err) { | |
console.log('An error occurred while flashing the device:', err); | |
}); | |
} | |
</script> | |
</head> | |
<body> | |
<h2>Hi.</h2> | |
<script>loginToParticle();</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment