Skip to content

Multiple Device Management

Documentation in Progress

This documentation is currently being developed. The device factory and session management infrastructure for multiple devices is implemented.

Status: ✅ Core functionality complete, 📝 Documentation in progress
Expected completion: After Issue 002-106 (Cross-Component Integration Layer)

Coming Soon

This page will provide guidance for managing multiple MicroPython devices simultaneously, including:

  • Device Discovery: Automatic detection of multiple connected devices
  • Connection Pooling: Efficient management of multiple device connections
  • Parallel Operations: Coordinating operations across multiple devices
  • Device Groups: Organizing devices into logical groups or clusters
  • Load Balancing: Distributing workload across available devices
  • Failover Strategies: Handling device failures in multi-device scenarios
  • Resource Sharing: Managing shared resources between devices
  • Synchronization: Coordinating time-sensitive operations

Quick Preview

csharp
// Example of what's coming - multiple device coordination
public class MultiDeviceController
{
    private readonly IDeviceFactory _deviceFactory;
    private readonly ILogger<MultiDeviceController> _logger;
    private readonly List<Device> _devices = new();

    public MultiDeviceController(IDeviceFactory deviceFactory, ILogger<MultiDeviceController> logger)
    {
        _deviceFactory = deviceFactory;
        _logger = logger;
    }

    public async Task InitializeDevicesAsync()
    {
        // Discover all available devices
        var deviceInfos = await Device.DiscoverDevicesAsync();
        
        foreach (var deviceInfo in deviceInfos)
        {
            try
            {
                var device = Device.FromConnectionString(deviceInfo.ConnectionString);
                await device.ConnectAsync();
                _devices.Add(device);
                
                _logger.LogInformation("Connected to device: {DeviceId}", deviceInfo.DeviceId);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "Failed to connect to device: {DeviceId}", deviceInfo.DeviceId);
            }
        }
    }

    public async Task<Dictionary<string, float>> ReadAllTemperaturesAsync()
    {
        var tasks = _devices.Select(async (device, index) =>
        {
            try
            {
                var temperature = await device.ExecuteAsync<float>("sensor.read_temperature()");
                return new { DeviceId = $"Device_{index}", Temperature = temperature };
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to read temperature from device {Index}", index);
                return new { DeviceId = $"Device_{index}", Temperature = float.NaN };
            }
        });

        var results = await Task.WhenAll(tasks);
        return results.ToDictionary(r => r.DeviceId, r => r.Temperature);
    }

    public async Task BroadcastCommandAsync(string command)
    {
        var tasks = _devices.Select(device => device.ExecuteAsync(command));
        await Task.WhenAll(tasks);
    }
}

Need help now? Check our GitHub Discussions or review the session management guide.

Released under the Apache License 2.0.