Technical

Connect Atmotube PRO to the Cloud via BLE<>Wi-Fi router

Atmotube devices communicate with smartphones via open Bluetooth API.

There are 2 ways to get data from an Atmotube PRO.

  • Read data from the Bluetooth advertising packet (while the device is not connected to the phone)
  • Connect to Atmotube and read data from GATT characteristics

In this article, we will parse the data from Bluetooth broadcast packets.

Atmotube Mobile BLE connection

Atmotube devices do not have a Wi-Fi module so you need an extra bridge to connect them to the cloud.

There are several options for connecting Atmotube devices to your own cloud:

  • If you are a research center or university, you can request access to the Atmotube cloud API directly and obtain a key to access data for your device's MAC address.
  • Write your own application to connect Atmotube via Bluetooth API to any device that has Internet connectivity (e.g., Android app (SDK), iOS app, Windows app, Raspberry Pi app, etc.) and connect it to your cloud.
  • Use a BLE<>Wi-Fi router to push the data to your own cloud.

In this article, we will describe the BLE<>Wi-Fi router option. The router supports HTTP or MQTT. We will use MQTT as the connection protocol and save data to a database.

Connect Atmotube to the Cloud via MQTT

Step 1. Get the router

There are a lot of BLE<>WiFi routers on the market. For example, MINEW G1. You can order it from Alibaba or another online marketplace.

Step 2. Deploy MQTT broker

You can use any managed MQTT broker (like https://www.cloudmqtt.com/) but the simplest way is to deploy your own instance of Mosquito - open-source MQTT broker. You will need one or several Linux cloud instances to deploy:

  • Mosquito MQTT broker
  • node.js to pull data from the broker and serve UI
  • Mongo DB to store the data

Step 3. Setup the router

  • Connect the router to your Wi-Fi network. The router works as the Access Point and has a simple HTTP configuration interface.
BLE to Wi-Fi router configuration
  • Connect the router to the MQTT broker.
Atmotube MQTT broker setup

You will need to specify the following information (example is for a MINEW router):

  • MQTT TCP IP and port
  • MQTT client ID
  • MQTT QoS
  • Topics for data publishing
  • We will use JSON format (long version) to capture RAW BLE packets
  • Filter duplicate data by MAC+type

The Atmotube BLE packet consists of two parts: Advertising packet and Scan Response packet. You will need both parts to parse the data. To catch Scan Response packets you will need to enable Active scanning.

BLE Active scanning setup

To minimize the MQTT data, you can use regex filter for raw Atmotube data. For Advertising packets, you can use ^.*41544D4F54554245 (ATMOTUBE in hex). For Scan Response packet, you can use ^.*7405.. (fw version for Atmotube PRO).

^.*7405..\|^.*41544D4F54554245

0201060FFFFFFF02D85C23241A00018F7A400F090941544D4F54554245
1107B38A324AD96ED7AD18489A8E010045DB0CFFFFFF89CA015D0000730619

Step 4. Check if you are receiving MQTT data

To check if your router sends data to the broker, you can use any MQTT client (like MQTTBox).

MQTT box connection setup

Subscribe to the MQTT topic you specified at Step 3.

MQTTBox Atmotube data

Step 5. Parse Atmotube data and save to database

At the last step, you have to combine Advertising packets and Scan Response packets and parse the data in order to save it to the database. We will use node.js to parse packets and save them to a MongoDB database.

  • Connect node.js to MQTT and subscribe to the topic:
  • Connect to Mongo DB
  • Parse incoming Atmotube MQTT data (BLE API description) and save it to the Mongo database. Optionally, you can send the realtime data to the web browser clients via socket.io.

NodeJS, socket.io and MongoDB are not part of this tutorial. You can find a complete example of the source code here: https://github.com/atmotube/atmotube-mqtt-nodejs

Atmotube MQTT console example

As a result, you can achieve complete and remote access to the data collected by Atmotube PROs.