Build a Beacon controlled by MCS Lite
Last updated
Last updated
In this tutorial, we'll show a scenario seen in common IoT application fields. Major components for this scenario are:
An IoT gateway by LinkIt Smart 7688, which equips rich resources for data manipulation and transmission. All nodes connected to it inside this field rely on this gateway to the internet.
IoT endpoint nodes by LinkIt 7697, which provides light-weight and power-efficient devices for endpoint deployment.
A user platform like a mobile phone, which is used to interact with endpoint nodes and/or the gateway control.
Credit
Icons made by Freepik and Gregor Cresnar from www.flaticon.com are licensed by CC 3.0 BY.
In the following sections, the setup of each component listed above will be explained and we hope this example helps developers to build your own system. Based on this configuration, it can be extended to a more generic setup for fitting into different IoT application scenarios.
A gateway is a more powerful device comparing to endpoint nodes. It is usually in charge of the data manipulation and transmission. Here a LinkIt Smart 7688 is set up as a MCS Lite server, which provides a local and private cloud service for handing data points generating within this private network. Moreover, this LinkIt Smart 7688 is configured as a Wi-Fi repeater for providing Internet connection to all devices in its local network. Two tutorials are listed below for configuring the LinkIt Smart 7688 as a MCS Lite server and a Wi-Fi repeater:
And you need to refer to another tutorial for building a test device with MCS Lite for controlling the onboard LED of the LinkIt 7697, which is the setup will be used in this tutorial. The test device consists of
A device id,
A device key,
An ON/OFF type display channel named switch_display, and
An ON/OFF type control channel named switch_controller.
These information is needed when you prepare the Arduino sketch codes for the LinkIt 7697.
There are two related tutorials for this topic:
Configure 7697 as an Eddystone URL beacon
Here an integrated example is shown for making a LinkIt 7697, which is controlled by MCS Lite, become a BLE beacon advertising the URL of the MCS Lite control page. As a result, whenever a user platform (e.g. a mobile phone) comes across with this node, the user can get the MCS Lite control page for this node automatically without typing the URL manually. The source codes come from the combination of the two 7697 tutorials mentioned above with modifications. In the following sections, all major modifications will be explained. For accessing the complete Arduino sketch file, go to the Appendix section in the end of this article.
At the beginning, you need to specify the SSID and password information about the IoT gateway so that the LinkIt 7697 can join the private network and access the local cloud service provided by MCS Lite.
And the LinkIt 7697 will connect to the Wi-Fi AP in line 58, based on the information provided above:
Although it's not recommended and is with security concern, if you somehow want to connect to a Wi-Fi AP without requiring a password, you can modify the line 58 to make the LinkIt 7697 connect to it without a password:
In order to connect to the MCS Lite server, you need to specify the address for the server and the device id and the device key for making this LinkIt 7697 recognizable by the server. Edit line 14 in the sketch file for assigning correct information:
The first and the second fields are for the device id and device key shown in the MCS Lite control console. The third and the fourth fields are the address and port information about the MCS Lite server. You can get these information after you've launched the service.
When building the test device for this example, two channels are defined for displaying and controlling. Therefore they need to be declared in the sketch file for making the server identify them correctly:
For making users easily access the control console of the MCS Lite service, the IoT endpoint node will advertise the URL of the MCS Lite control page via the BLE beacon mechanism. When your user platform (e.g. a mobile phone) supports BLE and has an APP which understands the Eddystone URL beacon, you can automatically get the URL of the MCS Lite control page for this endpoint device. In line 44, you need to assign the URL you want to advertise with the Eddystone format:
Since there is a limitation about the allowable length of an Eddystone URL (17 bytes), you can use any URL shortening services to create a simplified URL used in the advertisement. In this example, the URL "http://mylinkit.local:3000" is mapped to "goo.gl/evYXvt". For detailed explanation for configuring an Eddystone URL, you can visit the "Using LinkIt 7697 as an Eddystone-URL Beacon" section in the 7697 Beacon tutorial.
Note
Make sure the Wi-Fi and the BLE functions are turned on for the user platform and confirm it has connected to the IoT gateway before going into the following steps.
For recognizing the Eddystone advertisement, you need to install an application which supports the Eddystone URL beacon discovery. The Physical Web APP is one of those choices for getting this function in your mobile phone:
After the installation is done, when you launch the APP and your phone is close to the LinkIt 7697, you can see the URL advertisement as below:
It is also available in the widget mode so you can see the advertisement in the widget view:
When you click the URL discovered by this APP, you'll be redirected to the link for accessing the control page:
After signing into the MCS Lite service, you can use your mobile phone to see and control the status of the onboard LED of the LinkIt 7697:
Here is the complete Arduino sketch file for the program running on the LinkIt 7697: