Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-httpd-data-collector

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-httpd-data-collector

Gateway facilitating asyncronous communication between sensory data-emitting devices, InfluxDB and the user.

  • 2.0.2
  • PyPI
  • Socket score

Maintainers
1

async-httpd-data-collector

Interface handling the communication between sensory data-emitting devices, InfluxDB and the user.

The most important object that a user would use is DatabseInterface within ahttpdc.reads.interface module. This class facilitates the communication between the fetcher and the querying apis of InfluxDB.

In order to control fetching, there are two methods:

  • interface.daemon.enableg();
  • interface.daemon.disable().

Those methods control the thread within which fetching process is contained.

You can query data from the database using methods with query_ prefix. For now there are three:

  • interface.query_latest(), which queries the lastest measurement;
  • interface.query_historical(), which queries data from a given time range or relative time (eg. -3h);
  • interface.query(), which can takes user's given query as an argument.

Some examples will be presented below:

1.1 Connecting to the database

import json
from ahttpdc.reads.interface import DatabaseInterface

# load the secrets
with open('../../../secrets/secrets.json', 'r') as f:
    secrets = json.load(f)

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

# define the interface to the database
interface = DatabaseInterface(
    secrets['host'],
    secrets['port'],
    secrets['token'],
    secrets['organization'],
    secrets['bucket'],
    sensors,
    secrets['dev_ip'],
    80,
    secrets['handle'],
)

1.2 Extracting the dataframe from the database

import pandas as pd
import asyncio
from datetime import datetime, timedelta
from pathlib import Path

# if there is readings.csv file, load it
# if not - create it
readings_path = Path('../data/readings.csv')
if readings_path.is_file():
    sensor = pd.read_csv(readings_path)
else:
    sensor = await interface.query_historical('-30d')
    sensor.to_csv(readings_path)
sensor
timeacetonalcoholaltitudecoco2humiditynh4pressureseaLevelPressuretemperaturetoulen
02024-05-16 17:43:59.196399+00:000.411.17149.923.38402.5437.43.93999.351017.3124.400.48
12024-05-16 17:44:01.768738+00:000.471.32149.763.94402.8430.54.33997.611015.5624.030.55
22024-05-16 17:44:03.255309+00:000.962.62149.549.16405.2549.17.35999.141017.0823.161.15
32024-05-16 17:44:04.618203+00:000.300.86149.382.32401.9432.93.10999.091017.0223.050.35
42024-05-16 17:44:05.954714+00:001.313.50149.3713.13406.8248.89.21998.041015.9323.921.57
.......................................
2841222024-05-21 14:42:57.894312+00:001.353.62150.0813.68407.0347.69.46998.851016.8124.351.63
2841232024-05-21 14:42:59.277937+00:001.082.92149.8710.48405.7949.38.00998.581016.5323.411.29
2841242024-05-21 14:43:00.594968+00:000.381.09149.973.09402.3833.83.71999.591017.5424.880.44
2841252024-05-21 14:43:01.918239+00:001.413.77150.1314.38407.2944.49.76998.511016.4823.541.70
2841262024-05-21 14:43:03.248095+00:001.243.32150.5012.29406.5048.88.84998.851016.8522.441.49

284127 rows × 12 columns

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc