Consentium IoT
HomeTutorialsMain siteBlog
  • Getting Started
    • Consentium IoT Platform usage
    • Sensor Data API Documentation
    • Steps for Using Consentium IoT's OTA Service
    • Consentium Edge Machine Learning
    • ConsentiumNow Library Documentation
    • EdgeModelKit: Sensor Data Acquisition and Logging Library
  • Code usage
    • ConsentiumThings Python API
    • ConsentiumThings Arduino API
    • ConsentiumThings Arduino API with OTA Updates
    • WiFi auto connect API
    • ConsentiumThings Arduino Data Receiver API
    • ConsentiumNow Library API
  • Edge boards
    • Consentium Edge Dalton board
  • Tutorials
    • Receiving sensor data
      • Receiving Sensor Data from Consentium IoT Cloud and Controlling LED
    • Sending sensor data
      • Sending LM35 Sensor Data to Consentium IoT Cloud
      • Sending DHT11 Sensor Data to Consentium IoT Cloud
    • Edge machine learning
      • Sine wave predictor
      • Sine wave predictor with IoT
      • TinyML Occupancy Classification Example with Consentium IoT
  • Board support
    • Adding NodeMCU support to Arduino IDE
    • Adding ESP32 Support to Arduino IDE
    • Programming Raspberry Pi Pico with Arduino IDE (Pico W Compatible)
Powered by GitBook
On this page
  • Features
  • Usage Prerequisites
  • Installation
  • Quick Start
  • 1. Initialize the DataFetcher
  • 2. Fetch Sensor Data
  • 3. Log Sensor Data
  • CSV Logging Details
  • Real-Time Data Processing Example
  • Dependencies
  • Contributing
  • License
  • Support
  • About EdgeNeuron

Was this helpful?

  1. Getting Started

EdgeModelKit: Sensor Data Acquisition and Logging Library

PreviousConsentiumNow Library DocumentationNextCode usage

Last updated 4 months ago

Was this helpful?

EdgeModelKit is a Python library developed by EdgeNeuron, designed to simplify sensor data acquisition, logging, and real-time processing for IoT devices. It works seamlessly with the DataLogger script from the , making it ideal for edge computing and machine learning applications.


Features

  • Serial Communication: Supports data acquisition over serial ports with robust error handling.

  • Flexible Data Fetching: Retrieve sensor data as Python lists or NumPy arrays.

  • Customizable Logging: Log sensor data into CSV files with optional timestamps and counters.

  • Class-Based Organization: Log data with class labels to prepare datasets for machine learning tasks.

  • Error Handling: Gracefully handles data decoding errors and missing keys in sensor data packets.


Usage Prerequisites

This library is designed to work with the DataLogger script available in the . The DataLogger script configures your Arduino-based IoT device to send structured JSON sensor data over a serial connection.

Before using EdgeModelKit, ensure:

  1. Your Arduino device is programmed with the DataLogger script from the .

  2. The device is connected to your system via a serial interface.


Installation

Install EdgeModelKit using pip:

pip install edgemodelkit  

Quick Start

1. Initialize the DataFetcher

from edgemodelkit import DataFetcher  

# Initialize the DataFetcher with the desired serial port and baud rate  
fetcher = DataFetcher(serial_port="COM3", baud_rate=9600)  

2. Fetch Sensor Data

# Fetch data as a Python list  
sensor_data = fetcher.fetch_data(return_as_numpy=False)  
print("Sensor Data:", sensor_data)  

# Fetch data as a NumPy array  
sensor_data_numpy = fetcher.fetch_data(return_as_numpy=True)  
print("Sensor Data (NumPy):", sensor_data_numpy)  

3. Log Sensor Data

# Log 10 samples to a CSV file with timestamp and count columns  
fetcher.log_sensor_data(class_label="ClassA", num_samples=10, add_timestamp=True, add_count=True)  

CSV Logging Details

The CSV file is generated automatically based on the sensor name (e.g., TemperatureSensor_data_log.csv) and contains the following:

  • Timestamp: (Optional) Records the time when the data was logged.

  • Sample Count: (Optional) A sequential counter for each data sample.

  • Data Columns: Each element in the sensor data array is stored in separate columns (e.g., data_value_1, data_value_2, ...).

The data is saved under a folder named Dataset, with subfolders organized by class_label (if specified).


Real-Time Data Processing Example

from edgemodelkit import DataFetcher  

fetcher = DataFetcher(serial_port="COM3", baud_rate=9600)  

try:  
    while True:  
        # Fetch data as NumPy array  
        sensor_data = fetcher.fetch_data(return_as_numpy=True)  
        print("Received Data:", sensor_data)  

        # Perform custom processing (e.g., feed to a TensorFlow model)  
        # prediction = model.predict(sensor_data)  
        # print("Prediction:", prediction)  
finally:  
    fetcher.close_connection()  

Dependencies

EdgeModelKit requires the following Python packages:

  • numpy

  • pandas

  • pyserial

  • json

Install dependencies with:

pip install numpy pandas pyserial json  

Contributing


License

EdgeModelKit is licensed under the MIT License. See the LICENSE file for details.


Support


About EdgeNeuron


We welcome contributions to EdgeModelKit! Feel free to submit bug reports, feature requests, or pull requests on our .

For support and inquiries, contact us at [email protected] or visit our .

EdgeNeuron is a pioneer in edge computing solutions, enabling developers to build intelligent IoT applications with state-of-the-art tools and libraries. Learn more at .

EdgeNeuron Arduino library
EdgeNeuron Arduino library
EdgeNeuron Arduino library
GitHub repository
GitHub repository
edgeneuronai.com