🤖
LinkIt 7697 BlocklyDuino 使用指南
  • LinkIt 7697 BlocklyDuino 使用指南
    • 認識 LinkIt 7697
    • 認識 BlocklyDuino
    • BlocklyDuino v2 & v3 比較
    • 安裝開發環境 (v2)
      • 安裝 Arduino 編輯器
      • 安裝驅動並連接開發板
      • 安裝 BlocklyDuino 編輯器
      • 連結兩個編輯器並上傳程式
    • 安裝開發環境 (v3)
    • BlocklyDuino 基礎操作
    • 實作範例教學
      • A01. 內建 LED 閃爍
      • A02. 外接 LED 閃爍
      • A03. 外接 LED 呼吸燈
      • A04. RGB LED 顏色變化
      • A05. 外部按鈕控制開關
      • A06. 蜂鳴器播放聲音
      • A07 .可變電阻控制電壓輸出
      • A08. 伺服馬達控制
      • A21. DHT: 溫濕度感應器
      • A22. HTU21D: 溫溼度感應器
      • A23. PMSX003: PM2.5 感測器
      • A24. HC-SR04P: 超音波測距
      • A25. ADXL345: 加速規(動態)
      • A26. ADXL345: 加速規(手勢)
      • A27. 1602/2004: 液晶顯示模組
      • A28. WS2812: RGB 彩色燈條
      • A29. MFRC522: RFID
      • B00. Grove 相關基礎知識
      • B01. Grove 光感應器
      • B02. Grove 超音波測距感應器
      • B03. Grove 溫溼度感應器
      • B04. Grove 繼電器
      • B05. Grove LED 燈條
      • B06. Grove OLED 顯示器
      • C01. 雲端控制 LED 開關
      • C02. 上傳溫溼度到雲端
      • D01. 手機透過 BLE 讀寫裝置資料
      • E01. 遙控器: 按鈕控制 LED
    • 資源鏈結
  • LinkIt 7697 - Arduino IDE 開發指南
    • 環境設定
      • 設定 Arduino IDE
      • 將 LinkIt 7697 連接到電腦
        • 在 Windows 上安裝 CP2102N 驅動程式
        • 在 macOS 上安裝 CP2102N 驅動程式
      • 執行第一個程式
    • 開發指南
      • GPIO
      • UART
      • ADC
      • EINT (外部中斷 / External Interrupt)
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (索引式儲存空間)
      • RTC (Real-Time Clock)
      • Software Serial
      • 使用 Wi-Fi 函式庫
      • 使用 MCS 函式庫
        • 連接到 MCS
        • 連接到 MCSLite
          • 建立可透過 MCS Lite 控制的 Beacon
        • MCS 函式庫 API 使用手冊
          • MCSDevice
          • MCSLiteDeviceMCSLiteDevice
          • MCSDataChannel 相關類別
      • 使用 BLE 低功耗藍牙
        • 藍牙信標
        • 主控裝置
        • 周邊裝置
        • 已知限制
        • LBLE API 指南
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • 使用 LinkIt Remote
        • LRemote API
        • LRemote 控制元件 API
      • LinkIt 7697 腳位的初始狀態
      • LinkIt 7697 供電說明
      • 更新 Bootloader 與韌體
      • Flash 燒錄工具
      • FOTA 更新
      • LinkIt 7697 的功能限制
      • 自行編譯 Arduino Package
      • 回報問題
    • 週邊元件連接教學
      • SMD 按鈕
      • RGB 三色 LED
      • 可變電阻
      • 九軸感應器 (MPU-9250)
      • 溫度與濕度感應器 (AM2302)
      • 超音波距離感應器
      • 光感應器 (LM358)
      • 0.96 吋 OLED 顯示模組 (SSD1308Z)
      • 長條型 LED 顯示模組 (MY9221)
      • 繼電器
      • 伺服馬達 (EMAX 9g ES08A Servo)
      • 使用 74HC595 驅動七段顯示器
      • 使用 MAX7219 驅動七段顯示器
      • 使用 MAX7219 驅動 8x8 矩陣式顯示器
      • 使用 OLED 模組 (如 SH1106 / SSD1306... 等模組)
      • 使用 PCF8574 / PCF8574A 驅動 1602 LCD
    • 開發套件與擴充板
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • 下載
    • 資源連結
    • BSP 版本更新資訊
  • LinkIt 7697 - Development Guide for Arduino IDE
    • Environment Setup
      • Setup Arduino IDE
      • Connecting LinkIt 7697 to Computer
        • Install CP2102N Driver on Windows
        • Install CP2102N Driver on macOS
      • Run Your First Sketch
    • Developer Guide
      • GPIO
      • UART
      • ADC
      • External Interrupt
      • I2C
      • SPI
      • EEPROM
      • Timer
      • Flash (Key-Pair Storage)
      • RTC (Real-Time Clock)
      • Software Serial
      • Using the Wi-Fi Library
      • Using MCS Library
        • Connecting to MCS
        • Connecting to MCSLite
          • Build a Beacon controlled by MCS Lite
        • MCS Library API Reference
          • MCSDevice
          • MCSLiteDevice
          • MCSDataChannel Classes
      • Using Bluetooth
        • Beacons
        • Central Devices
        • Peripheral Devices
        • Limitations of LBLE library
        • LBLE Library API Guide
          • LBLE
          • LBLECentral
          • LBLEPeripheral
          • LBLEAdvertisementData
          • LBLEService
          • LBLECharacteristic
          • LBLEAddress
          • LBLEUuid
          • LBLEClient
      • Using LinkIt Remote
        • LRemote
        • LRemote Control Classes
      • Initial Pin State of LinkIt 7697
      • Powering the LinkIt 7697
      • Update Bootloader and Firmware
      • Flash Uploading Tool
      • FOTA Update
      • Limitations of LinkIt 7697
      • Source Code of Arduino Package
      • Issue Report
    • Tutorial
      • SMD Buttons
      • RGB LED
      • Potentiometer
      • IMU 9DOF v2.0 (MPU-9250)
      • Temperature and Humidity Sensor Pro (AM2302)
      • Grove Ultrasonic Ranger
      • Light Sensor (LM358)
      • Grove OLED Display 0.96" (SSD1308Z)
      • LED Bar v2.0 (MY9221)
      • Relay
      • Mini Servo (EMAX 9g ES08A Servo)
      • Driving 7-segment Displays with 74HC595
      • Driving 7-segment Displays with MAX7219
      • Driving 8x8 Dot Matrices with MAX7219
      • Using OLED module (SH1106 / SSD1306... etc.)
      • Driving 1602 LCD with PCF8574 / PCF8574A
    • Kits and Shields
      • Grove Starter Kit
      • Robot Shield
        • OTTO97
    • Download
    • Resources
    • BSP Release Notes
Powered by GitBook
On this page
  • IoT Gateway - LinkIt Smart 7688 as a private cloud server and a Wi-Fi repeater
  • IoT Endpoint Node - LinkIt 7697 as a node device and a BLE beacon
  • User Platform Configuration
  • Appendix
  1. LinkIt 7697 - Development Guide for Arduino IDE
  2. Developer Guide
  3. Using MCS Library
  4. Connecting to MCSLite

Build a Beacon controlled by MCS Lite

PreviousConnecting to MCSLiteNextMCS Library API Reference

Last updated 3 years ago

In this tutorial, we'll show a scenario seen in common IoT application fields. Major components for this scenario are:

  1. 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.

  2. IoT endpoint nodes by LinkIt 7697, which provides light-weight and power-efficient devices for endpoint deployment.

  3. A user platform like a mobile phone, which is used to interact with endpoint nodes and/or the gateway control.

Credit

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.

IoT Gateway - LinkIt Smart 7688 as a private cloud server and a Wi-Fi repeater

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:

  • 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.

IoT Endpoint Node - LinkIt 7697 as a node device and a BLE beacon

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.

Configure the AP information

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.

// Assign AP ssid / password here 
#define _SSID "YOUR_AP_NAME" 
#define _KEY "YOUR_PASSWORD"

And the LinkIt 7697 will connect to the Wi-Fi AP in line 58, based on the information provided above:

Serial.print("WiFi.begin(");
Serial.print(_SSID);
Serial.print(",");
Serial.print(_KEY);
Serial.println(")...");
WiFi.begin(_SSID, _KEY);

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:

Assign the device information for MCS Lite and the address of the MCS Lite server

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:

MCSLiteDevice mcs("YOUR_DEVICE_ID", "YOUR_DEVICE_KEY", "MCS_LITE_SERVER_ADDRESS", MCS_LITE_SERVICE_PORT);

Define the MCS Lite channel information

MCSControllerOnOff led("switch_controller"); 
MCSDisplayOnOff remote("switch_display");

Setup the Eddystone URL for BLE advertisement

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:

beaconData.configAsEddystoneURL(EDDY_HTTPS, "goo.gl/evYXvt");

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.

User Platform Configuration

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:

Appendix

Here is the complete Arduino sketch file for the program running on the LinkIt 7697:

#include <LWiFi.h>
#include <WiFiClient.h>
#include "MCS.h"

#include <LBLE.h>
#include <LBLEPeriphral.h>

// Assign AP ssid / password here
#define _SSID "YOUR_AP_NAME"
#define _KEY  "YOUR_PASSWORD"

// Assign device id / key of your test device
//MCSDevice mcs("YOUR_DEVICE_ID", "YOUR_DEVICE_KEY");
MCSLiteDevice mcs("YOUR_DEVICE_ID", "YOUR_DEVICE_KEY", "MCS_LITE_SERVER_ADDRESS", MCS_LITE_SERVICE_PORT);

// Assign channel id 
// The test device should have 2 channel
// the first channel should be "Controller" - "On/Off"
// the secord channel should be "Display" - "On/Off"
MCSControllerOnOff led("switch_controller");
MCSDisplayOnOff    remote("switch_display");

#define LED_PIN 7

void setup() {
  // setup Serial output at 9600
  Serial.begin(9600);

  // setup LED/Button pin
  pinMode(LED_PIN, OUTPUT);

  // Initialize BLE subsystem
  Serial.println("BLE begin");
  LBLE.begin();
  while (!LBLE.ready()) {
    delay(100);
  }
  Serial.println("BLE ready");
  
  // configure our advertisement data as iBeacon.
  LBLEAdvertisementData beaconData;

  // make an Eddystone-URL beacon that this board casts
  beaconData.configAsEddystoneURL(EDDY_HTTPS, "goo.gl/evYXvt");
  Serial.print("Start advertising Eddystone-URL");

  // start advertising it
  LBLEPeripheral.advertiseAsBeacon(beaconData);
  
  // setup Wifi connection
  while(WL_CONNECTED != WiFi.status())
  {
    Serial.print("WiFi.begin(");
    Serial.print(_SSID);
    Serial.print(",");
    Serial.print(_KEY);
    Serial.println(")...");
    WiFi.begin(_SSID);
  }
  Serial.println("WiFi connected !!");

  // setup MCS connection
  mcs.addChannel(led);
  mcs.addChannel(remote);
  while(!mcs.connected())
  {
    Serial.println("MCS.connect()...");
    mcs.connect();
  }
  Serial.println("MCS connected !!");

  // read LED value from MCS server
  while(!led.valid())
  {
    Serial.println("read LED value from MCS...");
    led.value();
  }
  Serial.print("done, LED value = ");
  Serial.println(led.value());
  digitalWrite(LED_PIN, led.value() ? HIGH : LOW);
}

void loop() {
  // call process() to allow background processing, add timeout to avoid high cpu usage
  mcs.process(100);
  
  // updated flag will be cleared in process(), user must check it after process() call.
  if(led.updated())
  {
    Serial.print("LED updated, new value = ");
    Serial.println(led.value());
    digitalWrite(LED_PIN, led.value() ? HIGH : LOW);
    if(!remote.set(led.value()))
    {
      Serial.print("Failed to update remote");
      Serial.println(remote.value());
    }
  }
  
  // check if need to re-connect
  while(!mcs.connected())
  {
    Serial.println("re-connect to MCS...");
    mcs.connect();
    if(mcs.connected())
      Serial.println("MCS connected !!");
  }
}

Icons made by and from are licensed by .

And you need to refer to 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

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 .

When 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:

Freepik
Gregor Cresnar
www.flaticon.com
CC 3.0 BY
Configure 7688 as a MCS Lite server
Switch 7688 to Repeater Mode
another tutorial
Control 7697 LED with MCS Lite
launched the service
building the test device
Android download link
iOS download link