June 29, 2020

Connect Atmotube to the Cloud

Cloud

Atmotube devices work with mobile phones via open Bluetooth API.

There are 2 ways to get data from Atmotube portable air quality monitor:

  • 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

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.

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

BLE Active scanning setup

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

^.*7306..\|^.*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 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

Atmotube MQTT console example

As a result you can achieve complete and remote access to the data collected by Atmotube Wearable Air Pollution and Weather Trackers.

Post tags
Interested in monitoring indoor air quality and environmental comfort of your space?
Let's chat
Atmocube on the wall