Using Intel Edison with MODE
In Creating a MODE Project, we simulated a virtual device from the Developer Console. Now we will use a real hardware device from Intel and build a “smart” light – an LED light that can be turned on and off via MODE, from anywhere in the world.
Step 1: Boot up an Intel Edison
Connect two USB cables to an Intel Edison hardware and boot the Edison. Please access its serial console. On a Mac, you can connect with following steps:
First, find usb serial devices on Mac’s file system:
$ ls /dev/tty.usb* /dev/tty.usbmodem1411 /dev/tty.usbserial-AJ035JTA /dev/tty.usbmodem1413
tty.usbserial-AJ035JTA is the USB-serial interface that you can access your Edison’s console.
$ screen /dev/tty.usbserial-AJ035JTA 115200 <press enter> Poky (Yocto Project Reference Distro) 1.7.2 edison2 ttyMFD2 edison login:
You can use
screen command to access to Edison’s console. The command line specifies that you are connecting to
/dev/tty.usbserial-AJ035JTA at 115,200 bits per second(bps).
115,200 is the default speed. You will see a blank screen and you want to press enter key a few times and you should see a login prompt.
You can login as user
root with no password.
Step 2: Configure Edison’s WiFi
Wifi settings of Intel Edisons can be done with
edison# configure_edison --wifi
Follow the instruction on the screen and you should be able to connect to your local WiFi.
edison# ifconfig wlan0 wlan0 Link encap:Ethernet HWaddr 78:4b:87:9f:79:10 inet addr:192.168.1.222 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:22 errors:0 dropped:0 overruns:0 frame:0 TX packets:62 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3310 (3.2 KiB) TX bytes:9972 (9.7 KiB)
Note that older versions of Edison firmware don’t persist wifi settings. Please update Edison’s firmware in this case.
Step 3: Download LED Controller Code
edison$ wget https://dev.tinkermode.com/docs/edison/app.js edison$ wget https://dev.tinkermode.com/docs/edison/package.json
Once you’ve downloaded the files, run the following command to install the mode-device library.
mode-device takes care of MODE Could API connection.
edison$ npm install
If you don’t see any error messages, the
mode-device library has been correctly installed.
Step 4: Configure Device Information and API Key
For a device to communicate to MODE, we need two pieces of information. One is
Device ID and the other is
Since you’ve already created a project for smart_light device class in Getting Started with MODE guide, we will use that project for this tutorial too.
Launch Developer Console and select Devices section.
From DEVICE CLASSES, choose
By clicking the previously created device from the DEVICE LIST,
you can find the
Device ID and
API Key in the details page of the device. These are the information you need to copy to your Edison.
Also make sure the device is attached to a home (you see an id in Home ID field).
Please open the
app.js file with your favorite editor (
nano) and find the following lines:
var DEVICE_ID = 1; var API_KEY = 'v1.cccc.bbbbbbbbbbbbbbbbbb.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
Please replace your
DEVICE_ID number and
API_KEY according to your device information. Once you’ve filled in the information, your device program is ready to run.
As you are starting a real device, make sure you close Device Simulator window if you previously used.
Step 5: Test the Device Connection
To make sure your configuration is correct, go to the Developer Console, locate the app you created in the Creating a MODE Project tutorial, and launch its App Simulator. On the simulator, select the home you have previously created. The simulator is now listening to events coming from devices of this home.
Once the app simulator is ready, run the following command from your Edison terminal:
edison$ node app.js
If your setup is correct, You should see the following output on your Edison:
Reconnect websocket in 0 seconds Reconnecting websocket Connecting to wss://api.tinkermode.com:443/devices/1/command Event is triggered WebSocket client is Cconnected
This means your Edison has succeeded in connecting to MODE, and is waiting for commands from MODE.
Also, in the INCOMING: EVENTS panel of the App Simulator, you should see something similar to the following because the program will send an event right after it has connected to MODE:
The event Origin may vary according to your device ID. This means Edison succeeded in sending an event to MODE.
Now the application settings are ready, we can start the hardware assembly.
Step 6: Send Commands from App Simulator to Edison
Sending a Command to Edison
Let’s send a command from the App Simulator to turn on your light. Go to the OUTGOING: COMMANDS panel, select the device from the Target drop-down list and provide the command details.
The sample program implements the
light command. So enter
light for action and for parameters, use
on for key, and
1 for value:
Once you’ve entered all the data, click the Send Command button. The command is then sent from the App Simulator to the MODE cloud, and delivered to the Edison.
Now you should see the LED switching on.
If you want to turn it off, simply re-enter a value of
0 for the
And click the Send Command button again. The LED is now turned off.
Congratulations! Your Edison is now controllable via MODE. You can send command from anywhere from your office, your home, or even from your mobile phone.
In the next tutorial, you will build an iOS app to control the smart light you just created.