As of October 1, 2023, LINE has been rebranded as LY Corporation. Visit the new blog of LY Corporation here: LY Corporation Tech Blog

Blog


Trying out LINE’s IoT Platform through LINE Things Developer Trial

Have you heard of LINE’s latest IoT platform? Ever wanted to connect your Bluetooth LE device to LINE? LINE Things can do just that! A Developer Trial program has recently been announced at LINE Developer Day 2018, held in November 2018, which allows all developers to easily integrate their Bluetooth LE devices into LINE’s ecosystem through LINE Things. This article will walk you through the procedures to create your very own device to connect to LINE. We will be using the ESP32 sample code in this tutorial.

Please note that LINE Things is available only in Japan, Taiwan, Thailand and Indonesia.

What is LINE Things?

LINE Things is a platform that connects BLE (Bluetooth LE) enabled IoT devices to LINE’s ecosystem, allowing offline devices to connect to bots and Web services.

Traditionally, many BLE accessories require the user to either download a dedicated app or rely on Web Bluetooth to take full advantage of the device. LINE Things provides a platform that conveniently allows the user to not only setup their devices, but to unify and create bridges across multiple devices by combining them with bots and LIFF (LINE Frontend Framework).

Three major functions are provided with LINE Things:

  • Registering of LINE Things-compatible devices via BLE through LINE application
  • Operating LINE Things-compatible devices via Javascript API through LINE Front-end Framework (LIFF)
  • Automatic connection and communication with LINE Things-compatible devices to bots and Web services

Detailed documentation of LINE Things is provided on LINE Developers site. The LINE Things API provided allows you to use the BLE device’s Read, Write, and Notify Characteristic properties through JavaScript from within LIFF. The Javascript API for LINE Things is based off of the Web Bluetooth API and shares many similarities. While currently unavailable at this time, we’ve planned to include automatic communication between LINE Things devices and bots/Web services in the future. With these major functions, we can close the distance between bots and IoT devices. If you are not familiar with LIFF, please check out this blog article, LIFF, our latest product for third party developers.

LINE Things Developer Trial

We have recently opened a Developer Trial for LINE Things so that you can experience the endless possibilities, simplicity, and convenience of the platform. LINE Things Developer Trial allows developers to freely create BLE devices and LIFF applications to be fully compatible with LINE’s ecosystem while complying with LINE Things’ specifications. Check About the LINE Things Developer Trial (English translation coming soon!) for more information.

Developer Trial accounts come with some restrictions, such as the number of products and devices is limited to a finite number. Additionally, users will not be able to detect the product until the bot associated with the product has been added as a LINE friend. These limitations shouldn’t matter much to an individual as well as small-scale experiments.

To develop on LINE Things using Developer Trial, some preparation is required as follows. As I take you through the process, I will need to make a bot and LIFF and have additional steps to setup, but I believe it shouldn’t be too hard since the documentation is quite complete. Visit the LINE Developers site for the documents.

  • LINE account
  • Create a channel (bot)
  • Create a LIFF app and grant Bluetooth LE functionality
  • Create a LINE Things product
  • A BLE-enabled device to integrate with LINE Things

Of course, if you are ready to go beyond the Developer Trial and open up for more users, or if you intend to release a product, please contact us through this form. We can’t wait to see what you come up with!

Trying out LINE Things Starter

Have I convinced you how exciting LINE Things can be yet? Now, you might be reluctant to give it a go since many may be thinking “Gosh, it must be hard to develop a LINE Things compatible device”. Fear not! We have provided a starter kit to kickstart your development into the world of LINE Things. The starter kit includes the source code for firmware of popular BLE development boards and a sample code to our LIFF app, all available on GitHub.

In order to make a LINE Things Starter device, we have picked popular commercially-available development boards that should be easy to source from anywhere in the world. Espressif’s ESP32 module supports both Wi-Fi and BLE, allowing you to have both online and offline connections with the device. The M5Stack allows rapid prototyping with its modular/stackable peripherals. Nordic’s nRF52 allows low-power consumption to your project allowing you to create devices that are battery-powered. All firmware for each board is written using Arduino IDE.

For this walkthrough, we will be using the ESP32-DevKitC. While any ESP32 development board may work, your mileage may vary, please proceed at your own risk.

Alright, now that we have everything we need, let’s get started!

Flashing LINE Things Starter Firmware

Let’s start by creating a LINE Things Starter device with the ESP32-DevKitC. Flash the sample firmware from the repository using the Arduino IDE. If you haven’t setup Arduino yet, check the README file.

Connecting your LINE Things device with LINE

Once the firmware has been flashed to your board, you are now ready to connect it with LINE! In order to use LINE Things, please scan the following QR code with your smartphone (with LINE installed). You will need to agree to the terms and conditions first to activate the functionality of LINE Things on your LINE app.

Note that LINE Things is available only in Japan, Taiwan, Thailand and Indonesia. Scanning this QR code with a LINE account bound to a non-servicing country does not take you to the LINE Things device page.

Once activated, you will now be able to see the device link screen as below. Subsequent access to this page can be accessed through Settings > LINE Things. Now you can turn on your BLE device with the firmware flashed. On the device link screen, your LINE Things device will be detected as LINE Things Trial (Default Firmware) under Available Devices. If it is not detected, please make sure you have your Bluetooth switched to ON on your smartphone.

Tap on the device name and you will be asked to pair with the device. Once paired, tap on the Use device now button to launch the LIFF app, that had been prepared for the starter kit.

Upon a successful connection to the device, the LIFF app will display the information of the device connected and the details of the device will be shown. The details of the device are obtained via the Read characteristic.

There are two physical buttons on the ESP32-DevKitC board, BOOT and EN. While running on the starter firmware, the BOOT button is used as a user-defined button. If pushed, the Button state of the LIFF app reflects the state of the physical button. Please bear in mind that by pushing the EN button, the device will reset. Thus disconnecting the device from the LIFF app, if connected. However, if your device does not seem to work, you may want to reset the device using the EN button.

Making the LIFF app reflect the button state is implemented using the Notify function from one of the three BLE characteristics. It allows the user to immediately see any activity when an event occurs from the device. LINE Things allows communication between you and your device to be both easy and seamless.

Let there be light

Let’s bring some flair to our device, shall we? You will need a 220Ω resistor, an LED, a breadboard, and some jumper cables. Refer to the picture below for all the necessary connections.

Here’s my setup.

Now head back to the LIFF app and try tapping on Switch LED ON and watch the LED light up! Pressing the button again will turn off the LED. Haver you ever thought you’d be able to control your IoT devices in such a simple manner? The possibilities are endless! We can’t wait to see what you can do with LINE Things!

Making it yours

Previously, we’ve tested LINE Things with the default firmware and LIFF app. Which means that the features were limited to the default GATT Services and Characteristics. To truly make your LINE Things device uniquely yours, or if you would like to develop your own firmware and LIFF app, you will need to use LINE Things Developer Trial. As mentioned earlier, in Developer Trial, you will need to create your own bot, register your own LIFF, and obtain your unique GATT Service UUID. Let’s try replicating the LINE Things Starter in our own development environment with our own Service UUID and LIFF.

Creating a new channel (bot) and LIFF app

To create a channel and LIFF app, see Preparation for accepting BLE-compatible devices on the LINE Platform. Due to the simplicity of our LINE Things Starter LIFF app, it can be hosted via GitHub Pages without a needing an external Web server. You will first need to fork the LINE Things Starter repository on GitHub. Next, head on over to the GitHub Pages section under settings and change the source to the master branch. You should now see a “Your site is published at {URL}”. Copy the URL and add “liff-app/” to the end (without quotes) to use as your LIFF endpoint URL.

Normally, when creating LIFF, you can use the Web UI on the LINE Developers site, but in order to use LIFF with LINE Things, you will need to grant yourself the Bluetooth LE feature. Since the Web UI currently does not allow you to add any additional features to your LIFF, you will need to use the Add LIFF app API directly using your own channel access token. See example below. Don’t for get to set “features":{"ble":true}.

  • curl -XPOST
  • -H 'Authorization: Bearer {channel access token}'
  • -H "Content-Type: application/json"
  • -d '{
  • "view": {
  • "description": "{liff name}",
  • "type": "full",
  • "url": "{LIFF endpoint URL (GitHub Pages)}"
  • },
  • "features": { "ble": true }
  • }'
  • https://api.line.me/liff/v1/apps

Creating a LINE Things product

Now that we have our LIFF app, we can now create a LINE Things product through an API available exclusively to LINE Things Developer Trial. The following is an example of the curl command to create a product.

  • curl -X POST https://api.line.me/things/v1/trial/products
  • -H 'Authorization: Bearer {channel access token}'
  • -H 'Content-Type:application/json'
  • -d '{
  • "name": "{trial product name}",
  • "liffId": "{LIFF APP ID}"
  • }'

Your channel access token can be obtained from the LINE Developers site, and your LIFF ID can be obtained from the command earlier. As for the name, you are free to name your product to anything of your choice. If successful, you will receive the following response.

  • {
  • "id": {productId},
  • "name": "{trial product name}",
  • "actionUri": "{LIFF APP URL}",
  • "channelId": {channelId},
  • "type": "BLE",
  • "serviceUuid": "{serviceUuid}",
  • "psdiServiceUuid": "{psdiServiceUuid}",
  • "psdiCharacteristicUuid": "{psdiCharacteristicUuid}"
  • }

Upon creation of a LINE Things product through Developer Trial, a dedicated and unique Bluetooth LE GATT Service UUID will be issued to you. The service uuid included in the response above is your unique UUID. By advertising this Service UUID in Advertising Packet, LINE app will be able to detect and identify your device in the device link page (don’t forget that you will need to add your bot as a LINE friend first!).

To create a LINE Things compatible product, a Product Specific Device ID (PSDI) Service and Characteristic is required for LINE Things to identify each device. Currently in Developer Trial, the psdiServiceUUID and psdiCharacteristicUUID are fixed. However, the return value must be unique for each device. For detailed specifications, please see Creating LINE Things-compatible devices.

Even though Bluetooth LE specific standards may be complex to understand, all requirements for LINE Things product specifications have already been implemented within the LINE Things Starter sample code. So all you would need to do to get started with your own product is to replace the default service UUID with your unique Service UUID from earlier.

Modifying LINE Things Starter

To modify the default starter firmware into your own custom product, you will need to replace the Service UUID at USER_SERVICE_UUID from the sample code.

  • #define USER_SERVICE_UUID "91E4E176-D0B9-464D-9FE4-52EE3E9F1552"

After making the change, flash the firmware onto your development board. Next, we will modify the LIFF JavaScript file. Similar to the firmware, replace the Service UUID at USER_SERVICE_UUID to your own UUID and upload the modified JavaScript file.

  • const USER_SERVICE_UUID = '91E4E176-D0B9-464D-9FE4-52EE3E9F1552'; // LED, Button

Putting it all together

First and foremost, please make sure you have added your bot as a LINE friend, since Developer Trial only allows you to detect your product only if your bot is a friend. To add your bot as a friend, open up the channel basic settings page from the LINE Developers site. Scroll down until you come across a QR code. Scan the code with your smartphone and tap on Add to add your bot as a friend.

You can now switch your LINE Things product device on. If the device is detected, you will see your registered product’s name on the Available Devices list from the device link screen. You can tap of the name of the device to pair with it and proceed to testing it with your LIFF app. Congratulations! You now have a your own custom product fully compatible with LINE Things!

⚠ iOS users please note. When making any changes to your device’s firmware, you may not be able to detect the device or some characteristics may not function properly. iOS caches a BLE device’s information when paired, and will not be able to detect the changes. To resolve the issue, please follow the steps below.

  1. Unlink your device from LINE Things on the device link page.
  2. Unpair your device from your smartphone’s Settings -> Bluetooth page.
  3. Switching your Bluetooth off and then back on.

If the device still fails to function properly, please ensure you have the correct Service UUID written in both the firmware file and LIFF JavaScript file. We also find the application “nRF Connect for Mobile” (iOS | Android)to be quite useful for debugging Bluetooth LE devices.

If you have gotten this far, you are now ready to develop your very own product for LINE Things! With a quick study of the sample code from the LINE Things Starter repository, you may have noticed that the only main requirements is to ensure you have the issued Service UUID advertised before connection and the PSDI Service for connection. From this point onwards, you are free to add additional standardized GATT Services or create your very own GATT Service.

Endless possibilities

With LINE Things, the Starter sample code is just the beginning of limitless possibilities! The two devices featured below are what we have as Proof of Concept while developing LINE Things. The first of the two is a weight scale prototype and the latter is an E-ink badge. Both run on a simple CR2032 battery! Perhaps one day, you may be able to record your daily weight via Bluetooth and get recommendations for your diet. Or perhaps you like to travel and you can easily update your luggage tag straight from LINE! The sky is the limit and you can easily start developing your product using Developer Trial today! Please note, however, that we do not have any plans to commercialize these proofs of concepts, they were merely made to test the platform.

Finally, to conclude this blog post, on behalf of the LINE Things team, I would like to thank you for making it this far with us on this journey to the bottom of this page and we sincerely hope you have as much fun with Developer Trial, if not more, as we did making it. We hope to hear and see all your ideas and products you’ve made with LINE Things.

Thank you!

LINE Things Team