Atmotube devices work with mobile phones via open Bluetooth API.
There are 2 ways to get data from Atmotube:
- 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.
The most common task is to get the data from Atmotube remotely. Atmotube devices do not have a Wi-Fi module so you need an extra bridge to connect it 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 MAC address.
- Write your own application to connect Atmotube via Bluetooth API for 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 BLE<>Wi-Fi router to push the data to your own cloud.
In this article we will describe BLE<>Wi-Fi router option. Router supports HTTP or MQTT. We will use MQTT as connection protocol and save data to the database.
Step 1. Get the router
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.
- Connect the router to the MQTT broker.
You will need to specify the following information (example is for a MINEW router):
- MQTT tcp IP and port
- MQTT client id
- MQTT QoS
- Topic 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.
To minimize the MQTT data you can use regex filter for raw Atmotube data. For Advertising packet you can use
^.*41544D4F54554245 (ATMOTUBE in hex). For Scan Response packet you can use
^.*7306.. (fw version for Atmotube PLUS) and
^.*7405.. (fw version for Atmotube PRO).
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).
Subscribe to the MQTT topic you specified at Step 3.
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 it to 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 source code here: https://github.com/atmotube/atmotube-mqtt-nodejs
As a result you can achieve complete and remote access to the data collected by Atmotube Wearable Air Pollution and Weather Trackers.