Skip to content

AssemblingSmartCPS/ch13

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chapter 13: Stack4Things Services

Source Code Repository for Chapter 13 of "Assembling Smart Cyber-Physical Systems: heterogeneous, diffuse and green technological infrastructures for cities and industries"

This repository contains the complete source code implementations, plugins, and examples referenced in Chapter 13 of the book.

Chapter Content

Chapter 13 examines the range of functionalities and services offered by Stack4Things (S4T), focusing on S4T's capability to inject customized business logic directly into remote IoT nodes, enabling tailored behavior and domain-specific processing at the network edge.

Key Concepts Covered

  • Plugin Architecture: Modular and extensible components orchestrated by Lightning-rod agent
  • Fleet Management: Coordinated control of heterogeneous IoT device groups
  • Web Services Integration: Secure exposure of IoT resources over the web
  • Synchronous vs Asynchronous Operations: Different execution models for various use cases

Repository Structure

chapter13-stack4things-services/
├── plugins/                    # Stack4Things plugins
│   ├── templates/             # Plugin templates and skeletons
│   │   └── plugin_skeleton.py
│   ├── synchronous/          # Synchronous plugins
│   │   ├── hello_name_plugin.py
│   │   ├── led_control_plugin.py
│   │   └── docker_lifecycle_plugin.py
│   └── asynchronous/         # Asynchronous plugins
│       ├── worker_async_plugin.py
│       └── weather_station_plugin.py
├── demos/                     # Demonstration applications
│   └── weather_web_server.py
├── examples/                  # Configuration examples
│   ├── docker_plugin_examples.json
│   ├── hello_plugin_example.json
│   ├── worker_plugin_example.json
│   ├── weather_station_example.json
│   └── led_control_examples.json
├── scripts/                   # Utility scripts
│   ├── start_weather_server.sh
│   └── start_weather_server.bat
├── docs/                      # Documentation
│   ├── CHAPTER_13_OVERVIEW.md
│   ├── PLUGIN_DEVELOPMENT_GUIDE.md
│   ├── FLEET_MANAGEMENT.md
│   └── WEB_SERVICES_INTEGRATION.md
├── requirements.txt           # Python dependencies
├── .gitignore                # Git ignore rules
└── README.md                 # This file

Prerequisites

  • Python 3.6 or higher
  • Stack4Things IoTronic framework
  • Lightning-rod agent on target devices
  • Docker (required for Docker management plugin)

Installation

# Clone the repository
git clone <repository-url>
cd chapter13-stack4things-services

# Install dependencies
pip install -r requirements.txt

Running the Weather Station Implementation

# Start the weather station web server
python3 demos/weather_web_server.py 8080

# Alternative startup methods
./scripts/start_weather_server.sh    # Linux/Mac
scripts/start_weather_server.bat      # Windows

The web interface will be available at: http://localhost:8080

Plugin Types

Synchronous Plugins

Execute on-demand when explicitly invoked:

  • Hello Name Plugin: Generates personalized greetings
  • LED Control Plugin: Controls LED actuators via GPIO
  • Docker Lifecycle Plugin: Manages Docker containers

Asynchronous Plugins

Operate continuously in the background:

  • Worker Async Plugin: Continuous message logging
  • Weather Station Plugin: Environmental monitoring

Fleet Management

Stack4Things supports fleet management for orchestrating groups of heterogeneous IoT devices:

  • Device Grouping: Organize devices into logical groups
  • Coordinated Operations: Perform synchronized operations across fleets
  • Scalable Management: Handle large-scale IoT deployments
  • Unified Control: Manage multiple devices as single entities

Web Services Integration

S4T enables exposure of IoT services through web endpoints:

  • DNS Integration: Automatic subdomain assignment
  • Reverse Proxy: NGINX-based tunneling
  • Secure Access: HTTPS-enabled communication
  • NAT Traversal: Access devices behind firewalls

Documentation

Comprehensive documentation is available in the docs/ directory:

Examples

Configuration examples are provided in the examples/ directory:

  • Docker Plugin Examples: Container management operations
  • Hello Plugin Example: Simple synchronous plugin configuration
  • Worker Plugin Example: Asynchronous plugin configuration
  • Weather Station Example: Environmental monitoring setup
  • LED Control Examples: LED control operations

Plugin Development

Basic Plugin Structure

from iotronic_lightningrod.modules.plugins import Plugin
from oslo_log import log as logging

LOG = logging.getLogger(__name__)

class MyPlugin(Plugin.Plugin):
    def __init__(self, uuid, name, q_result, params=None):
        super(MyPlugin, self).__init__(uuid, name, q_result, params)

    def run(self):
        # Plugin logic here
        result = {"message": "Hello from plugin"}
        self.q_result.put(result)

Plugin Deployment

  1. Access the Stack4Things Horizon dashboard
  2. Navigate to the Plugins panel
  3. Click "Create Plugin" to upload new plugins
  4. Fill in plugin metadata and source code
  5. Select execution mode (synchronous/asynchronous)
  6. Use "Inject Plugin" to deploy to devices

Weather Station Implementation

The weather station implementation demonstrates a complete IoT application as described in Chapter 13:

Implementation Features

  • Sensor Data Collection: Temperature, humidity, and pressure readings
  • LED Control: Remote LED control via HTTP POST requests
  • Web Interface: Auto-refreshing dashboard for real-time monitoring
  • RESTful API: Complete API for data access and device control

Available Endpoints

  • GET / - Main dashboard interface
  • GET /sensors - JSON sensor data
  • GET /led/status - Current LED status
  • POST /led/toggle - Toggle LED state

Usage Examples

# Start the server
python3 demos/weather_web_server.py 8080

# Access the dashboard
open http://localhost:8080

# Retrieve sensor data
curl http://localhost:8080/sensors

# Control LED state
curl -X POST http://localhost:8080/led/toggle

Usage Guidelines

This repository is designed to accompany Chapter 13 of the book. When using the provided code:

  1. Follow the established plugin template structure
  2. Review the comprehensive documentation in the docs/ directory
  3. Use the provided configuration examples as reference
  4. Test implementations on target IoT devices
  5. Refer to the Stack4Things documentation for advanced features

Authors

Primary Authors: Giuseppe Tricomi and Maurizio Giacobbe
Collaboration: Dr. Aamod Vyas and Prof. Luca D'Agati

Book Reference

This repository accompanies Chapter 13 of the book: "Assembling Smart Cyber-Physical Systems: heterogeneous, diffuse and green technological infrastructures for cities and industries"

License

This project is part of the Stack4Things framework. Please refer to the main project documentation for licensing information.

Related Resources

Additional Resources

For further information and technical details:

  • Review the documentation in the docs/ directory
  • Consult the plugin development guide
  • Examine the provided configuration examples
  • Refer to the Stack4Things project documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published