Skip to main content

No project description provided

Project description

🐀 Labrat Sensor Logger

Connect sensors and log data to a database, file, or both.

Current connection modes available:

Connection Description
MQTT Subscribe to an MQTT broker
serial Read from a wired serial port
http Receive data via a Flask API

Table of Contents


Quick Start

Not sure where to begin? Create a Secrets File. The minimum secrets file is:

[CONNECTIONS]

   [CONNECTIONS.FLASK]
   "KEY" = "" # this can be filled with anything for this step.
       [CONNECTIONS.FLASK.SETUP]
       "ROUTE" = "/setup"

then run the setup wizard.

python labrat_log.py -secrets "mypath/secrets.toml" -quick_start

This will open a browser window in which you can give a name for the database and add inator devices

All Options

usage: labrat_log.py [-h] [-sql SQL] [-secrets SECRETS] [-quick_start]
Flag Description
-secrets SECRETS Path to the TOML secrets file (logins, broker details, etc.)
-quick_start Run the quick start wizard 🧙

Setup & First Run

1. Create a Secrets File

Create a .toml file with your credentials and connection details: This has the following main sections which have their own sub-sections

[LOGGING] # Options to control logging
[CONNECTIONS] # Options to control the connections

These sections are then further broken up

[LOGGING]
    [LOGGING.SQLITE] # Settings for logging to SQLite database 
    "FILE" = "" # The path to sql database file
    "CREATE" = false # Whether to create the DB or not (true for quick set up)

    [LOGGING.FILE]  # Settings for logging to a text file
    "FILE" = "" # Path for the file
    "CREATE" = false # Whether to create the file or append

    [LOGGING.ELN] #Settings for connecting to an Electronic Laboratory notebook
    "NAME" = "RSpace" # Name of the ELN
    "KEY" = ""  # If required a key to logging to the ELN

[CONNECTIONS]
    [CONNECTIONS.MQTT] # MQTT connection details
        [CONNECTIONS.MQTT.NAME] # Details of a MQTT connection NAME should be changed and be unique
            "USERNAME" = "" # Any user names needed by broker
            "KEY" = ""  # Key needed to connect to broker
            "BROKER" = "" # Address of the broker
            "PORT" = 1883 # The port number of the broker, 8883 is traditional
            "TOPIC" = ""  # The Topic to subscribe to, adding # is normally useful
            "TLS" = true  # Whether the MQTT broker is using a TLS connection, i.e is encrypted. true or false
    
    [CONNECTIONS.SERIAL]  # Serial connection details
        [CONNECTIONS.SERIAL.NAME] # Details of a Serial connection NAME should be changed and be unique
            "PORT" = "" # The name of the serial port
            "BAUD" = "" # The baud rate for the port

   [CONNECTIONS.FLASK]  # Flask server connection details
   # Due to its nature Flask is treated differently to other connections, only one server per route
   "KEY" = "" # The key to connect to http logging
   "LOCAL_ON" = true  # Whether to run the routes through Flask, only safe on a local network
       [CONNECTIONS.FLASK.HTTP] # Route information for the HTTP server
       "ROUTE" = "/datalog" # The route to the HTTP logging server
   
       [CONNECTIONS.FLASK.DASH] # Route information for the display dashboard 
       "ROUTE" = "/dash"  # The route to the display dashboard

       [CONNECTIONS.FLASK.SETUP]  # Route information for the quick set up page
       "ROUTE" = "/setup" # The route to the quick setup page

All connections methods can run in parallel

2. Set Up Database Contents

Add devices to the database.

The device file must conform to the Inator DB schema. This can be done using the quick start page

Device file JSON schema
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "devices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "device_name":     { "type": "string" },
          "device_guid":     { "type": "string" },
          "num_sensors":     { "type": "integer" },
          "device_info":     { "type": "string" },
          "device_type":     { "type": "string" },
          "device_location": { "type": "string" },
          "device_active":   { "type": "integer" },
          "connection": {
            "type": "string",
            "enum": ["Serial", "MQTT", "Other"]
          },
          "sensors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "sens_name": { "type": "string" },
                "measures":  { "type": "string" },
                "returns":   { "type": "string" },
                "calib":     { "type": "string" },
                "range":     { "type": "string" },
                "info":      { "type": "string" },
                "comments":  { "type": "string" }
              },
              "required": ["sens_name", "measures", "returns", "calib", "range", "info", "comments"]
            }
          }
        },
        "required": [
          "device_name", "device_guid", "num_sensors", "device_info",
          "device_type", "device_location", "device_active", "connection", "sensors"
        ]
      }
    }
  },
  "required": ["devices"]
}

3. Run

To run file in the options in the settings/secrets file for what you want to do Then depending on your installationn method run using

python labrat_log.py -secrets path/to/secrets.toml

or

poetry run python labrat_log.py -secrets path/to/secrets.toml

Running as a Daemon

Run the logger as a persistent background service using Supervisor.

1. Install

sudo apt update && sudo apt install supervisor

2. Configure

Edit the provided supervisord.conf file, updating these fields:

Field What to set
command= Full command with all required paths and flags
user= System user to run the process as
stdout_logfile= Absolute path and filename for log output
directory= Working directory (home directory for MQTT)

3. Start

supervisord -c /path/to/supervisord.conf

4. Monitor & Control

Use supervisorctl to manage the process:

supervisorctl status          # check if running
supervisorctl restart labrat  # restart the service
supervisorctl stop labrat     # stop the service

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labrat_project-0.5.1.tar.gz (149.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labrat_project-0.5.1-py3-none-any.whl (160.2 kB view details)

Uploaded Python 3

File details

Details for the file labrat_project-0.5.1.tar.gz.

File metadata

  • Download URL: labrat_project-0.5.1.tar.gz
  • Upload date:
  • Size: 149.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.9 Windows/11

File hashes

Hashes for labrat_project-0.5.1.tar.gz
Algorithm Hash digest
SHA256 169978801a3215b77aa7ddb58c2ea63739482f1568d5e9824827e042748abd68
MD5 91bb7e5c57bde48077817d44eb34d5d5
BLAKE2b-256 660477223f5f0c68918857c18d01842de986317494c944134badb12d8e860ee2

See more details on using hashes here.

File details

Details for the file labrat_project-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: labrat_project-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 160.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.1 CPython/3.12.9 Windows/11

File hashes

Hashes for labrat_project-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6d40b2a485fbb2b75c8f95d066412838e0173ad26bda72b9b5d2bedb0f1f410
MD5 b636d412cbdd64b1827ff1e5af13588c
BLAKE2b-256 40f28eeb769f34e8008970f6cf0f3901c6d8df3c640307cc201f6f37f79be0dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page