Hello Everyone! This is my first post on Hackster.io and I'd like to share with you various applications on LinkIt Smart 7688 using MediaTek Cloud Sandbox.
Today, I'd like to start with how to upgrading the firmware on your LinkIt Smart 7688 development board. LinkIt Smart 7688 development board is very easy to start with, it supports Node.js, Pytho, C and Arduino.
Ok now, let's start.
Step 1: Pre-requisiteHere is the items that you will needed:
1. A LinkIt Smart 7688 or LinkIt Smart 7688 DUO development board.
2. An MCS account. You can register one here.
3. The firmware files you would like to upgrade to. Here I use the Arduino IDE to to export the .hex file using the Export compiled Binary function.
Step 2: Create your first prototype on MCSIn Step 1, you've signed up to MCS, now log in to your account.
Click Development on the top menu bar, and click Prototype.
Enter the prototype information as you wished and Save.
Click Detail to enter the prototype detail page, then click firmware tab.
Add two firmware files you've saved in Step 2.
Note: Select default setting when adding firmware.
After adding the firmware to MCS, now create a test device. This test device is just like your development board. When your development board is connected to MCS, you can received data from your development board and also give command to your device as well.
Here you need to keep the deviceId and deviceKey which is unique for each device. You will need them when calling MCS RESTful APIs in the code on your development board.
Make sure your LinkIt Smart 7688 development board is powered and connected.
Using the ssh tool to access your LinkIt Smart 7688 console.
Create a folder using the following command:
mkdir app && cd app
Install the following modules using the following commands:
npm install mcsjs
npm install superagent
Create app.js file to run the FOTA application on the development board by:
vim app.js
Type i and copy/paste the following code in the editor and type :wq to save and exit.
var mcs = require('mcsjs');
var spawn = require('child_process').spawn;
var fs = require('fs');
var request = require('superagent');
var fwName = 'fw.hex';
var myApp = mcs.register({
deviceId: 'Input your deviceID',
deviceKey: 'Input your deviceKey',
});
var download = function(url, dest, cb) {
var file = fs.createWriteStream(dest);
var sendReq = request.get(url);
// verify response code
sendReq.on('response', function(response) {
if (response.statusCode !== 200) {
return cb('Response status was ' + response.statusCode);
}
});
// check for request errors
sendReq.on('error', function (err) {
fs.unlink(dest);
if (cb) {
return cb(err.message);
}
});
sendReq.pipe(file);
file.on('finish', function() {
file.close(cb); // close() is async, call cb after close completes.
});
file.on('error', function(err) { // Handle errors
fs.unlink(dest); // Delete the file async. (But we don't check the result)
if (cb) {
return cb(err.message);
}
});
};
myApp.on('FOTA', function(data, time) {
console.log(data);
var Data = data.split(',');
var firmwareUrl = Data[2];
download(firmwareUrl, fwName, function(){
var update = spawn('avrdude', ['-p', 'm32u4', '-c', 'linuxgpio', '-v', '-e', '-U', 'flash:w:/root/'+ fwName, '-U', 'lock:w:0x0f:m']);
update.stdout.on('data', function(data) { console.log(data) });
update.stderr.on('data', function(data) { console.log(data.toString()) });
});
});
Step 6: Run your application and upgrading firmware using MCSYou are now ready to execute the Node.js program. In the system console, type the following command:
node app.js
Go back to MCS console, click Development on top menu bar, and click test device.
Go to the test device you just created.
You will see the light for the test device is turining green which means your device is connected and online.
Cick the firmware tab, and you will see the firmware files and you are able toPush the firmware to the development board.
MCS enables you to push the firmware to various development boards, however, it does not handle the firmware upgrade on the development board. You have to write your own code to deal with it.
Using the MCS, it is very convenient to have a platform to recieve and save the data from your development board; also to control and upgrade the firmware all at once.
Comments