# gl-inet/ble2mqtt: BLE 2 MQTT bridge on GL.iNet IoT gateway
Canonical: https://social-archive.org/escap0/MBxGkTWu30
Original URL: https://github.com/gl-inet/ble2mqtt
Author: gl-inet
Platform: web
Share mode: full
## Content
## BLE MQTT Bridge ## Introduction Bluetooth Low Energy (BLE) is widely used for smart home, wearable and IoT sensors. This guide provide a simple but useful tool that send your BLE data to MQTT servers, which is the underling mechanism for popular IoT solution. In this guide we will introduce two GL.iNet BLE gateway, `GL-X750 Spitz` and `GL-S1300 convexa S` which has built-in BLE modules and how to use them to forward your BLE data to the cloud based on MQTT protocol, including GL.iNet `GoodCloud` and `AWS IoT`. ## Hardware Required Both GL-X750 and GL-S1300 comes with a Silicon BLE 5.0 module with the following specs. It connects to the main board using `UART`. The same module support BLE and Zigbee. However you need to change the firmware on the module (not the gateway). There is no way to change the firmware from BLE to Zigbee or vice versa on the air. So you have to select the correct module when you purchase the correct product. | Item | Specification | | --- | --- | | Product Name | Bluetooth & Zigbee Module | | Model | GL-EFR32S/GL-EFR32H | | CPU | Silicon Labs EFR32MG1P232F256GM48-CR0 | | Protocol | Support Zigbee、BLE | | Storage | RAM:32KB/ Flash:256KB | | Tx Power | 19 dBm | | Antenna | On-board antenna (external antenna IPEX reserved) | | Internal Interface | 17*GPIO (could be configured to UART、SPI、JTAG、I2C, etc.) | | Module Interface Type | Stamp interface/Pin interface | | Supply Voltage | 3.3 V | | Power Consumption | support low power consumption, standby power＜50uW | | Module Dimenstion | 25mm*20mm | | Operation Temperature | 0℃~75℃ | | Storage Temperature | -40℃~85℃ | | Operating Humidity | 10%~90% | You must use the gateway with BLE devices. There are two kinds of BLE devices. One kind of BLE device use beacons to send data, e.g a BLE thermometer. Another kind of device need to pair first, e.g. BLE smart watch. For BLE beacon device, you can just scan the beacon and get the data. The data is generally encrypted. It is depends on you to decrypted the data. You can decrypt locally on the gateway or just send the encrypted data to your cloud to decrypt there. For BLE devices that needs to pair first, you need to know how they can pair with the gateway. Generally this is provided by the device maker. There are a lot of devices that accept standard connection so you can pair without problem. A list of compatible devices will be collected and posted here. ***TBD: a list of compatible BLE device.*** ## BLE Tools Both GL-X750 and GL-S1300 come with OpenWrt and our BLE tools. In your current firmware for S1300, there may be a BLE tool which comes with a UI. But we are further developing this and you need to use the new BLE tool. ``` root@GL-S1300:~# opkg remove gl-ble-daemon gl-ble-api root@GL-S1300:~# opkg install bletool Installing bletool (1-2) to root... Downloading http://download.gl-inet.com/releases/packages-3.x/ipq40xx/glinet/bletool_1-2_ipq806x.ipk. Configuring bletool. ``` Now you can use the bletool to test your BLE function. ``` root@GL-S1300:~# bletool on root@GL-S1300:~# bletool discovery_type 1 1 OK root@GL-S1300:~# bletool discovery 1 1 0 OK af000045d1e43df801ff1f0201061bff570100a0c931e781473f364824a724d7d3380402f83de4d1 4500 af040045d1e43df801ff0f0a094d492042616e6420320302e0fe d0009238c444f07001ff0e02011a0aff4c001005031802dcbd d0049238c444f07001ff00 ``` You can find a detailed documentation about `bletool` ***[https://github.com/gl-inet/ble2mqtt](https://github.com/gl-inet/ble2mqtt)***. ## MQTT MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. You can find official document in [mqtt.org](https://github.com/gl-inet/ble2mqtt/blob/master/mqtt.org). This guide will give you a step to step guide of how to send message to GL.iNet GoodCloud and AWS. ### Send Data to GoodCloud GoodCloud is our Cloud based on MQTT under development. Now you can use it for demo purpose related to BLE. You can contact us if you have any suggestions by sending an email to [admin@goodcloud.xyz](mailto:admin@goodcloud.xyz). All you need to do is to register an account in GoodCloud.xyz and bind your X750 or S1300 to your account. **Register your device on [GoodCloud.xyz](https://www.goodcloud.xyz/)** Follow [this docs](https://docs.gl-inet.com/en/3/app/cloud/#setup) to add devices on GoodCloud. **Where is the config file** The config file for cloud is in UCI. You will need to modify this directly if you want to connect to your own MQTT cloud. ``` root@GL-S1300:~# cat /etc/config/glconfig .... config service 'cloud' option enable '1' option check_status '1' option serverzone 'gslb-jp.goodcloud.xyz' option username 'your name' option email 'your@email.address' option bindtime '1558928701947' ``` **Forward data to GoodCloud** To forward data to GoodCloud, you can use simple shell script. After your device is connected to your cloud account, you can [SSH](https://docs.gl-inet.com/en/3/app/ssh/) to the router, try the following command. ``` root@GL-S1300:~# ubus call mqtt pub '{"api":"/user/data", "data":"hello from S1300" }' { "code": 0 } root@GL-S1300:~# ``` Login the GoodCloud， [https://www.goodcloud.xyz，find](https://www.goodcloud.xyz,find/) the registered device in"device list", click the device name and you will find your message in timeline. [![Image](https://camo.githubusercontent.com/9b65d7422f67578b6088225c7637a4dc56b71e97bfe0c4ae357700cad650dbbc/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f66696e642d6465766963652e706e67)](https://camo.githubusercontent.com/9b65d7422f67578b6088225c7637a4dc56b71e97bfe0c4ae357700cad650dbbc/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f66696e642d6465766963652e706e67) [![Image](https://camo.githubusercontent.com/a849db18a9c1fa0752da07c3059e32857d3b976912202b83aa792235a7d415a8/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f66696e642d6c6f672e6a7067)](https://camo.githubusercontent.com/a849db18a9c1fa0752da07c3059e32857d3b976912202b83aa792235a7d415a8/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f66696e642d6c6f672e6a7067) ### Send Data to AWS IoT Amazon AWS IoT is a good choice for business applications. AWS seems to have good security and privacy protection. Here we will give an example of how to send your data to AWS IoT platform. It is a little complicated but still OK for IT specialist. ####1. Setting up your AWS IoT environment 1. On the **Welcome to the AWS IoT Console** page, in the navigation pane, choose **Manage->Things**, then **Register a thing**. [![Image](https://camo.githubusercontent.com/3c161135f264c9503020c05c01d0b474e935e6dd21fc1fdcf1cd9a7951eab9c8/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030312e706e67)](https://camo.githubusercontent.com/3c161135f264c9503020c05c01d0b474e935e6dd21fc1fdcf1cd9a7951eab9c8/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030312e706e67) 2. On the **Creating AWS IoT things** page, choose **Create a single thing**. [![Image](https://camo.githubusercontent.com/266f76b192c7af91e9257cbca51355ef87db9f07e21a7febe10b56caf65a2fa4/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030322e706e67)](https://camo.githubusercontent.com/266f76b192c7af91e9257cbca51355ef87db9f07e21a7febe10b56caf65a2fa4/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030322e706e67) 3. On the **Create a thing** page, in the **Name** field, type a name for your thing, such as **x750**. Choose **Next**. [![Image](https://camo.githubusercontent.com/7f3f01f5a2cabafbddddeda8d63850a34eea137f09425541e0de1264de46f7c9/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030332e706e67)](https://camo.githubusercontent.com/7f3f01f5a2cabafbddddeda8d63850a34eea137f09425541e0de1264de46f7c9/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030332e706e67) 4. On the **Add a certificate for your thing** page, choose **Create certificate**. This generates an X.509 certificate and key pair. [![Image](https://camo.githubusercontent.com/6dd063fca56984a1697c5139871cb62ab6c349ac44aceba819cefa5ec4209fb0/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030342e706e67)](https://camo.githubusercontent.com/6dd063fca56984a1697c5139871cb62ab6c349ac44aceba819cefa5ec4209fb0/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030342e706e67) 5. On the **Certificate created!** page, download your public and private keys, certificate, and root certificate authority (CA): - Choose **Download** for your certificate. - Choose **Download** for your private key. - Choose **Download** for the Amazon root CA. This will display a new web page. Choose **RSA 2048 bit key: Amazon Root CA 1**. This opens another web page with the text of the root CA certificate. Copy this text and paste it into a file named `Amazon_Root_CA_1.pem`. Most web browsers save downloaded files into a Downloads directory. You will copy these files to a different directory when you run the sample applications. Choose **Activate** to activate the X.509 certificate, and then choose **Attach a policy**. [![Image](https://camo.githubusercontent.com/244b1ef2cb68fbffb7bc2de3a75b1779e910c3b7f08b402ba4ab055f860b0c0e/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030352e706e67)](https://camo.githubusercontent.com/244b1ef2cb68fbffb7bc2de3a75b1779e910c3b7f08b402ba4ab055f860b0c0e/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030352e706e67) The **RSA 2048 bit key: Amazon Root CA1** download web page: [![Image](https://camo.githubusercontent.com/52a616857c51c940ca99a75a25679ad11290baa6fa81711f809cd08c057b67bb/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030372e706e67)](https://camo.githubusercontent.com/52a616857c51c940ca99a75a25679ad11290baa6fa81711f809cd08c057b67bb/687474703a2f2f7374617469632e676c2d696e65742e636f6d2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030372e706e67) 6. Active your thing Back to the previous site, click " **Activate** ", then click " **Done** ". [![Image](https://camo.githubusercontent.com/240d29eb7cf0f18cd53fc8fa79baaeb8618e9c719ae566bc13f3aa770f23c318/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030382e706e67)](https://camo.githubusercontent.com/240d29eb7cf0f18cd53fc8fa79baaeb8618e9c719ae566bc13f3aa770f23c318/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030382e706e67) **2. Attach Policy** 7. After you register your thing, you will need to create and attach a new **policy** to the **certificate**.[![Image](https://camo.githubusercontent.com/c9e616c565ec9abecd8fb797d06705cff59ff7aa248d4e41f57846c8d5c48a1c/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030392e706e67)](https://camo.githubusercontent.com/c9e616c565ec9abecd8fb797d06705cff59ff7aa248d4e41f57846c8d5c48a1c/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653030392e706e67) 2. Enter a Name for the policy,such as x750_policy, then **Advance mode** [![Image](https://camo.githubusercontent.com/572d989e73baa42c5d99458bd80fb68c427770f9c690f5b9b9daf4db737c734a/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031302e706e67)](https://camo.githubusercontent.com/572d989e73baa42c5d99458bd80fb68c427770f9c690f5b9b9daf4db737c734a/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031302e706e67) 3. Delete the automatically created policy code, then paste the policy below. ``` { "Version": "2012-10-17", "Statement": [ { "Action": [ "iot:Publish", "iot:Subscribe", "iot:Connect", "iot:Receive" ], "Effect": "Allow", "Resource": [ "*" ] } ] } ``` 4. **Create** Policy after you pasted policy code. [![Image](https://camo.githubusercontent.com/5bd392f2692910f3a810ac9ab7cb3d1d763f24cb6abd9fa5bf385a747ee28840/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031322e706e67)](https://camo.githubusercontent.com/5bd392f2692910f3a810ac9ab7cb3d1d763f24cb6abd9fa5bf385a747ee28840/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031322e706e67) 5. On the left side, Secure --> Certificates, Select the certificate you just created, Actions --> Attach policy [![Image](https://camo.githubusercontent.com/8870ded632da997743303bfe5fc804a9e599ef3860e0675b2b2135962ea86606/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031332e706e67)](https://camo.githubusercontent.com/8870ded632da997743303bfe5fc804a9e599ef3860e0675b2b2135962ea86606/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031332e706e67) 6. Chose the policy you created(x750_policy) and choose **Attach**. [![Image](https://camo.githubusercontent.com/4ff4ac7bedf6caad368d52fb699ee3036320d0e1741338c9de69017138d1a6e4/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031342e706e67)](https://camo.githubusercontent.com/4ff4ac7bedf6caad368d52fb699ee3036320d0e1741338c9de69017138d1a6e4/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031342e706e67) ####2. Config GL.iNet devices to connect to AWS IoT **1) Upload your certificate to the router** Rename the downloaded certificate files: AmazonRootCA1.pem --> root_CA.crt xxxxxxxxxx.private.pem.key --> client.key xxxxxxxxxx. certificate.pem.crt --> client.crt Windows User use [SSH and WinScp](https://docs.gl-inet.com/en/3/app/ssh/) to transfer these three certificate files to `/etc/aws/` on router, please create new folder if you cannot find `/etc/aws/`. ``` mkdir /etc/aws/ ``` **2) Update mqtt package on GL.iNet routers.** You can check if your router comes with updated MQTT package. If it is not, please upgrade it if you want to use AWS. Download the updated [mqtt package](https://1drv.ms/u/s!AgvZCliGPjk-saQ_3HbKiRGo_WsSSQ), file name is ' **gl-mqtt_3.0.37-1_mips_24kc.ipk** ‘ Use WinSCP/SSH to transfer the package to /tmp/, then delete the old package. ``` opkg remove gl-mqtt --force-depends ``` Then install the package: ``` opkg install gl-mqtt_3.0.37-1_mips_24kc.ipk ``` **3) Setup config file for your router** Edit `/etc/config/glconfig` Add the following code to your **glconfig** file. ``` config service 'cloud' option enable '1' option sub_topic '/a1rLNyG2VK5/mqtt_demo/user/get' option pub_topic '/sys/a1rLNyG2VK5/mqtt_demo/thing/event/property/post' option service_pride '2' option address 'ssl://xxxxxxxxxxxxxx-ats.iot.us-east-1.amazonaws.com:8883' option clientid 'iotconsole-xxxxxxxxxxxxxx' option log '1' ``` The sample of glconfig file: [![Image](https://camo.githubusercontent.com/a3b0beaaa9476aaab6dec7e7c92a09ca8cc1f6ffffb1fb2f8778659385b24743/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031362e706e67)](https://camo.githubusercontent.com/a3b0beaaa9476aaab6dec7e7c92a09ca8cc1f6ffffb1fb2f8778659385b24743/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031362e706e67) If you already setup GoodCloud on router before, just add the code at the end of **config service 'cloud'** [![Image](https://camo.githubusercontent.com/2147b34ed4067fb0a758a8c4623f31eace23b4af20b33339ec49fd4abe89e83f/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031372e706e67)](https://camo.githubusercontent.com/2147b34ed4067fb0a758a8c4623f31eace23b4af20b33339ec49fd4abe89e83f/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031372e706e67) ``` option log '1' ``` must be contained in the config file. Note** The topic ARN follows this format: ``` arn:aws:iot:*your-region*:*your-aws-account*:topic/** ``` For example: ``` arn:aws:iot:us-east-1:123456789012:topic/my/topic ``` **Topics** The message broker uses topics to route messages from publishing clients to subscribing clients. The forward slash (/) is used to separate topic hierarchy. **Note** We do not recommend using personally identifiable information in your topics. The following table lists the wildcards that can be used in the topic filter when you subscribe. **Topic Wildcards** | Wildcard | Description | | --- | --- | | # | Must be the last character in the topic to which you are subscribing. Works as a wildcard by matching the current tree and all subtrees. For example, a subscription to `Sensor/#` receives messages published to `Sensor/`, `Sensor/temp`, `Sensor/temp/room1`, but not the messages published to `Sensor`. | | + | Matches exactly one item in the topic hierarchy. For example, a subscription to `Sensor/+/room1` receives messages published to `Sensor/temp/room1`,`Sensor/moisture/room1`, and so on. | **4) HTTP: API Endpoints add to router config file** The message broker supports clients connecting with the HTTP protocol using a REST API. Clients can publish by sending a POST message to `**/topics/**?qos=1"`. [![Image](https://camo.githubusercontent.com/bd77d8c7db5e364d2784b82af68d6b107b15d6c6395e15ea5bfe6a23efdc7158/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031392e706e67)](https://camo.githubusercontent.com/bd77d8c7db5e364d2784b82af68d6b107b15d6c6395e15ea5bfe6a23efdc7158/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653031392e706e67) [![Image](https://camo.githubusercontent.com/74723bb05e3f0a78c6f736641a81106592135b00b596897970a02afa96ae2776/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032302e706e67)](https://camo.githubusercontent.com/74723bb05e3f0a78c6f736641a81106592135b00b596897970a02afa96ae2776/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032302e706e67) [![Image](https://camo.githubusercontent.com/38e99e427a484ac72d2f1c47c719ff42d20ad1347e1a2404e4c3136c64f3a72e/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032312e706e67)](https://camo.githubusercontent.com/38e99e427a484ac72d2f1c47c719ff42d20ad1347e1a2404e4c3136c64f3a72e/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032312e706e67) [![Image](https://camo.githubusercontent.com/582fe490ba512c4a854cc3bd0fc217bdba9a54b2f60cfac575ab15664d88eb3d/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032322e706e67)](https://camo.githubusercontent.com/582fe490ba512c4a854cc3bd0fc217bdba9a54b2f60cfac575ab15664d88eb3d/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032322e706e67) [![Image](https://camo.githubusercontent.com/a3c50f17607fc1b1d68e6fff432a0ab077b5cc438b974abe99ee8a63e6e06b08/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032332e706e67)](https://camo.githubusercontent.com/a3c50f17607fc1b1d68e6fff432a0ab077b5cc438b974abe99ee8a63e6e06b08/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032332e706e67) [![Image](https://camo.githubusercontent.com/b8feb35320f58343893f87775e148148e11f8e8f43887ce8c3a5f67829c7f6e5/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032342e706e67)](https://camo.githubusercontent.com/b8feb35320f58343893f87775e148148e11f8e8f43887ce8c3a5f67829c7f6e5/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032342e706e67) [![Image](https://camo.githubusercontent.com/168bf05f8349d841cabc35c57575b3c4992081611a135fec6b30393a7220bc6b/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032352e706e67)](https://camo.githubusercontent.com/168bf05f8349d841cabc35c57575b3c4992081611a135fec6b30393a7220bc6b/687474703a2f2f7374617469632e676c2d696e65742e636f6d2e2f646f63732f656e2f332f6170702f424c455f6272696467652f696d6167653032352e706e67) ## Application and Demo ### Read BLE Thermal Sensor The following demo show how to read data from a thermal sensor, pack the data in JSON format and send to the GoodCloud. ``` #!/usr/bin/sh . /usr/share/libubox/jshn.sh while true do sleep 5 bletool on bletool discovery_type 1 1 bletool discovery 1 1 0 | awk '/0d09536d6172745f426561636f6e02/{print $0; exit}' > /tmp/blesniffer.log bletool end_procedure adv_data=`awk '{print $1}' /tmp/blesniffer.log` date=`date +"%Y%m%d%H%M%S"` json_init json_add_string "api" "/user/data" json_add_object "data" json_add_string "date" "$date" json_add_string "advertising data" "$adv_data" json_close_object json_close_object data=`json_dump` ubus call mqtt pub "$data" rm /tmp/blesniffer.log done ```
## Media
1. image: https://social-archiver-api.social-archive.org/media/archives/escap0/eHj76hI4V1/media/0.png
