Storing Realtime IoT Timeseries Data in Python — Timescale DB + Raspberry Pi + Phidget Sensors

1. Introduction

2. Architecture Overview — Configuration

Configurations used in this instruction

3. Timescale DB Setup

psql -U postgres -h localhost
Connected to PostgreSQL
CREATE database homedata;
Database homedata created
\c homedata
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
Database connected to TimescaleDB now
psql -U postgres -h localhost -d homedata
Connecting to TimescaleDB instance, homedata, from terminal
CREATE TABLE sensor_data(
db_insert_time TIMESTAMPTZ NOT NULL,
room TEXT NOT NULL,
data_gen_time TIMESTAMPTZ NOT NULL,
sound1 REAL[] NOT NULL,
sound2 REAL[] NOT NULL,
temperature REAL NOT NULL,
humidity REAL NOT NULL,
light REAL NOT NULL
);
Data table creation
Created data table
SELECT create_hypertable('sensor_data', 'db_insert_time');
creating hypertable

4. A Python Server to Store IoT Timeseries Data

Github gist for python server program code
SELECT * FROM sensor_data;

Closing Remark

References

A computer scientist enthusiastic about enabling our surroundings smart and even autonomous! KAIST PhD, now at MIT as a Postdoc

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store