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 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.
- 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
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
- Python 3.6 or higher
- Stack4Things IoTronic framework
- Lightning-rod agent on target devices
- Docker (required for Docker management plugin)
# Clone the repository
git clone <repository-url>
cd chapter13-stack4things-services
# Install dependencies
pip install -r requirements.txt# 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 # WindowsThe web interface will be available at: http://localhost:8080
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
Operate continuously in the background:
- Worker Async Plugin: Continuous message logging
- Weather Station Plugin: Environmental monitoring
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
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
Comprehensive documentation is available in the docs/ directory:
- Chapter 13 Overview: Complete chapter summary and learning objectives
- Plugin Development Guide: Detailed guide for creating S4T plugins
- Fleet Management: Fleet management concepts and operations
- Web Services Integration: Web services setup and configuration
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
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)- Access the Stack4Things Horizon dashboard
- Navigate to the Plugins panel
- Click "Create Plugin" to upload new plugins
- Fill in plugin metadata and source code
- Select execution mode (synchronous/asynchronous)
- Use "Inject Plugin" to deploy to devices
The weather station implementation demonstrates a complete IoT application as described in Chapter 13:
- 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
GET /- Main dashboard interfaceGET /sensors- JSON sensor dataGET /led/status- Current LED statusPOST /led/toggle- Toggle LED state
# 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/toggleThis repository is designed to accompany Chapter 13 of the book. When using the provided code:
- Follow the established plugin template structure
- Review the comprehensive documentation in the
docs/directory - Use the provided configuration examples as reference
- Test implementations on target IoT devices
- Refer to the Stack4Things documentation for advanced features
Primary Authors: Giuseppe Tricomi and Maurizio Giacobbe
Collaboration: Dr. Aamod Vyas and Prof. Luca D'Agati
This repository accompanies Chapter 13 of the book: "Assembling Smart Cyber-Physical Systems: heterogeneous, diffuse and green technological infrastructures for cities and industries"
This project is part of the Stack4Things framework. Please refer to the main project documentation for licensing information.
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