Skip to content

Instantly share code, notes, and snippets.

@Jerware
Created June 7, 2016 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jerware/513ef19e03699ff1239a21f130dc7bfd to your computer and use it in GitHub Desktop.
Save Jerware/513ef19e03699ff1239a21f130dc7bfd to your computer and use it in GitHub Desktop.
<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