Skip to main content

PyPI version Total Downloads PyPI - Downloads

async-httpd-data-collector

Note: This is an older university project and is not actively maintained. It works as-is, but is not extensively tested.

A Python library that acts as an asynchronous gateway between IoT sensor devices and InfluxDB. It fetches JSON readings from a device (like a NodeMCU/ESP8266) over HTTP, parses them, and stores them as time-series data. You can then query the data back as pandas DataFrames.

Started as a university project to get hands-on with async Python, asyncio, aiohttp, and time-series databases. The hardware side runs on an arduino-air-state-server - a NodeMCU board with air quality sensors (MQ135, BMP180, DHT22, DS18B20) that exposes readings at an HTTP endpoint.

Installation

pip install async-httpd-data-collector

Quick Start

from ahttpdc.read.database_interface import DatabaseInterface

# define which sensors and parameters to track
sensors = {
    'bmp180': ['altitude', 'pressure', 'seaLevelPressure', 'temperature'],
    'mq135': ['aceton', 'alcohol', 'co', 'co2', 'nh4', 'toulen'],
    'ds18b20': ['temperature'],
    'dht22': ['humidity', 'temperature'],
}

# connect to InfluxDB and the device
interface = DatabaseInterface(
    sensors,
    db_host='localhost',
    db_port=8086,
    db_token='your-influxdb-token',
    db_org='your-org',
    db_bucket='your-bucket',
    srv_ip='192.168.1.100',  # device IP
    srv_port=80,
    handle='circumstances',  # HTTP endpoint on the device
)

# start the background daemon - fetches and stores data continuously
interface.daemon.enable()

# query the last 30 days of data as a DataFrame
df = interface.query_historical('-30d')
print(df.head())

# stop the daemon when done
interface.daemon.disable()

How It Works

NodeMCU device          async-httpd-data-collector            InfluxDB
  (sensors)                                                  (storage)
     |                                                          |
     |--- HTTP GET /circumstances -->  AsyncFetcher             |
     |                                     |                    |
     |                              JSONInfluxParser            |
     |                                     |                    |
     |                              AsyncCollector  -------->   |
     |                                                          |
     |                              AsyncQuery     <--------    |
     |                                     |                    |
     |                               DataParser                 |
     |                                     |                    |
     |                              pandas DataFrame            |

The DatabaseInterface is the main entry point. It manages two things:

  • DataDaemon - a background process (via multiprocessing) that periodically fetches sensor data from the device and stores it in InfluxDB.
  • AsyncQuery - queries InfluxDB and returns results as pandas DataFrames with local timezone-adjusted timestamps.

Querying

# latest reading
df = interface.query_latest()

# last 3 hours
df = interface.query_historical('-3h')

# specific time range
df = interface.query_historical('2024-05-16T00:00:00Z', '2024-05-21T00:00:00Z')

# custom Flux query
df = interface.query_custom_sync('from(bucket:"my-bucket") |> range(start: -1d) |> last()')
  • arduino-air-state-server - the NodeMCU firmware that collects sensor readings and serves them over HTTP
  • air-quality-data-analysis - Jupyter notebooks with data analysis (heatmaps, correlations, anomaly detection) and SARIMAX time-series forecasting on the collected data

To the only God, be honour and glory for ever and ever.

Metadata

Release files for async-httpd-data-collector 2.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-httpd-data-collector 2.0.5
File Size Uploaded
async_httpd_data_collector-2.0.5.tar.gz 52.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-httpd-data-collector 2.0.5
File Interpreter ABI Platform
async_httpd_data_collector-2.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 90.4 kB

Release files / async_httpd_data_collector-2.0.5.tar.gz

Download URL async_httpd_data_collector-2.0.5.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a956d2aa7c2682e56b8c6aa7ae8cc3514ca589c79186000d6a72b76710f2f6c7
BLAKE2b-256 checksum
How to use checksums
10c5303f4d54d0ae386c6f1c21179673d3f25ad886c3cc9cdc09022ee93395b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / async_httpd_data_collector-2.0.5-py3-none-any.whl

Download URL async_httpd_data_collector-2.0.5-py3-none-any.whl
Size 37.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f94c68caf40bad2d4ed5e0251716cf72f4f1320b28bf664e8bb855baf2fc77a
BLAKE2b-256 checksum
How to use checksums
56c492941f3bbc90f23b82d6bb73eedce072730a025876408490e3bfa2ecc698
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

2.0.6

2 release files

This release

2.0.5 This release

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page