Step 1: Program the MediaTek 7688 Duo MT7688
After connecting in Station mode to you LAN you can connect to the Duo with ssh. Since I am working on a windows machine I’m going to use Putty to connect. These steps are similar for a linux or mac.
Node, Express, DocumentDB, Git, and Screen are the software packages that you’ll need. Install these with Opkg. Connecting to git can be tricky. Here is how I did it from the command line in openWRT:
As a part of this recipe the source code has been made available to you. Now can clone the code from the git hub:
Once the software is uploaded to the Duo then you can just run:
and go to the ip address assigned to your Duo by the router at local port 3000
A successful command line output will look something like this:
The output on the website will look something like this:
Note that the output is blank because no data has been uploaded
This is a quick approach to get things up and running. But if you want to spin your own code here are some key components you’ll need.
If you are taking this route then you have git installed and can successfully push to your repository on git hub.
First make sure that the Duo is functioning correctly on your LAN by doing these steps:
1.Assuming you are currently connected via SSH
2.Use the express generator to generate a new application called seeedrecipe.
3.Open your new seeedrecipe directory and install dependencies.
4.Run your new application.
5.You can you view your new application by navigating your browser tohttp://
So let’s pause and reflect. The small device you have plugged into your computer is now hosting a website. That is pretty cool; but things are going to get much cooler before we are done with this recipe.
Now you’ll need to configure the Duo to upload data do a database. You can use the Vivaplanet SeeedRecipes database for free. This is a No SQL document DB database. You might want to try another database like mongo or something and this is also encouraged and possible. First you’ll need a few more modules to interface with documentDB. You can look at your package.json file to view the installed modules required for this node.js application. We still need to install two more packages for this recipe.
1.Install the async module via npm.
2.Install the documentdb module via npm. This module allows the Duo to use the DocumentDB package.
3.A quick check of the package.json file of the application should show the additional modules. This file will tell the Duo which packages to download and install when running this recipe. The dependencies should resemble the example below.
1.Create a new directory named models In the seeedrecipe directory.
2.First let’s make some utility functions to interact with the documentDB. In the models directory, create new file named docdbUtils.js. This file will contain some useful, reusable, code that we will use throughout our application.
3.Copy the following code in to docdbUtils.js
2.Next, in the models directory, create a file named taskDao.js. This file will contain the model for CRUD (CReate, Upload, Delete) in this recipe.
3.At the beginning of the taskDao.js file, add the following code to reference the DocumentDBClient and the docdbUtils.js we created above:
4.Next, you will add code to define and export the Task object. This is responsible for initializing our Task object and setting up the Database and Document Collection we will use.
5.Next, add the following code to define additional methods on the Task object, which allow interactions with data stored in DocumentDB.
6.Save and close the taskDao.jsfile.
1.In the routes directory of your project, create a new file named tasklist.js.
2.Add the following code to tasklist.js. This loads the DocumentDBClient and async modules, which are used by tasklist.js. This also defined the TaskList function, which is passed an instance of the Task object we defined earlier:
3.Continue adding to the tasklist.js file by adding the methods used to showTasks, addTask, and completeTasks:
4.Save and close the tasklist.jsfile.
1.In your project directory create a new file named config.js.
2.Add the following to config.js. This defines configuration settings and values needed for our application.
3.In the config.js file, update the values of HOST and AUTH_KEY using the values found in the Keys blade of your DocumentDB account on the Microsoft Azure Preview portal:
4.Save and close the config.jsfile.
1.In the project directory, open the app.js file. This file was created earlier when the Express web application was created.
2.Add the following code to the top of app.js
3.This code defines the config file to be used, and proceeds to read values out of this file in to some variables we will use soon.
4.Replace the following two lines in app.jsfile:
with the following snippet:
6.Finally, save and close the app.js file, we're just about done.
Now let’s turn our attention to building the user interface so a user can actually interact with our application. The Express application we created uses Jade as the view engine. For more information on Jade please refer to http://jade-lang.com/. You may think that you hate Jade. I hated Jade at first…but after working with it for a while I’ve come to appreciate it so now I don’t hate it as much. I wish you a faster journey than mine.
1.Thelayout.jade file in the views directory is used as a global template for other .jade files. In this step you will modify it to use Twitter Bootstrap, which is a toolkit that makes it easy to design a nice looking website.
2.Open the layout.jade file found in the views folder and replace the contents with the following;
This effectively tells the Jade engine to render some HTML for our application and creates a blockcalledcontent where we can supply the layout for our content pages. Save and close this layout.jadefile.
3. Now open the index.jade file, the view that will be used by our application, and replace the content of the file with the following:
This extends layout, and provides content for the content placeholder we saw in the layout.jade file earlier.
In this layout we created two HTML forms. The first form contains a table for our data and a button that allows us to update items by posting to /completetask method of our controller. The second form contains two input fields and a button that allows us to create a new item by posting to /addtask method of our controller.
This should be all that we need for our application to work.
4.Open the style.css file in public\stylesheets directory and replace the code with the following:
Save and close this style.cssfile.
Now your application is running but you don’t have any sensors plugged in and you haven’t configured the ATMega323 to upload data to the server yet. This is the focus for step two. The two types of sensors used in this recipe are the DHT11 and the Light sensor. Both are found on Seeed. The basic connection scheme will be shown but any sort of sensor can be used. First let’s look at the pinout of the DUO to for a strategy of where we will be connecting the sensors. The pins to connect the sensors to are shown below.
Since the DHT11 sensor had a digital PWM output you’ll want to connect it to one of the digital GIPO sensors. I picked D2. It really doesn’t matter which pin you connect the DHT11 to as long as the same pin is enabled in your software (see Step 3). Here is an image of what the board looks like when the sensors are connected.
The next step is programming the ATMega323 and testing the output. First plug in and connect to the Arduino board with the Arduino IDE. Make sure to get the latest copy of the Arduino driver from MediaTek.
There is some sample code that drives the DHT11 here: http://www.seeedstudio.com/wiki/Grove_-_Temperature_and_Humidity_Sensor .This code can be modified in the following way to accommodate the DUO’s configuration.