Skip to main content

A federated learning package for IoT devices and aggregation server communication.

Project description

kehe-fl

A federated learning package for IoT devices and aggregation server communication using MQTT.

Features

  • Distributed, federated learning orchestration using MQTT
  • Device-side and server-side reference implementations
  • Asyncio-based for efficient concurrency
  • Modular design for custom ML or IoT projects

Quick Start

Installation

pip install kehe-fl

Example Usage

Device Side

import asyncio
from kehe_fl.comms.mqtt_device import MQTTDevice

mqttConnection: MQTTDevice | None = None

async def main():
    global mqttConnection

    mqttConnection = MQTTDevice(broker="192.168.1.193", deviceId="device123")

    mqtt_task = asyncio.create_task(mqttConnection.connect_and_listen())

    await asyncio.gather(mqtt_task)

asyncio.run(main())

Aggregation Server Side

import asyncio
from kehe_fl.comms.mqtt_agg_server import MQTTAggServer

mqttConnection: MQTTAggServer | None = None

async def handleMessaging():
    global mqttConnection
    loop = asyncio.get_running_loop()

    while True:
        if mqttConnection.is_connected and not mqttConnection.working:
            message = await loop.run_in_executor(None, input, "Enter a command to send to the clients: ")
            await mqttConnection.send_command(message)
        else:
            await asyncio.sleep(2)

async def main():
    global mqttConnection

    mqttConnection = MQTTAggServer(broker="localhost")

    mqtt_task = asyncio.create_task(mqttConnection.connect_and_listen())
    input_task = asyncio.create_task(handleMessaging())

    await asyncio.gather(mqtt_task, input_task)

asyncio.run(main())

Adapt

Communication

You can adapt the device and server code to your specific ML or IoT project needs by modifying the MQTTDevice and MQTTAggServer or even MQTTProvider classes. These classes provide a foundation for communication and can be extended with custom logic for model training, data handling, and more.

Machine Learning

You can integrate your preferred machine learning libraries (like TensorFlow, PyTorch, etc.) into the device and server implementations with modifying ModelService. The provided classes can be used to send model updates, receive commands, and manage the training process across devices.

Data Collection

You can implement custom sensor classes in common/<your sensor>.pyand also modify the DataCollectionService for your needs. This allows you to collect and process data from various IoT sensors and devices, which can then be used for training machine learning models.

Project Constants

You can modify the project_constants.py file to change the MQTT topic structure, message formats, and other constants used throughout the package. This allows you to tailor the communication protocol to your specific requirements.

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

kehe_fl-0.1.11.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

kehe_fl-0.1.11-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file kehe_fl-0.1.11.tar.gz.

File metadata

  • Download URL: kehe_fl-0.1.11.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for kehe_fl-0.1.11.tar.gz
Algorithm Hash digest
SHA256 d4bb9575f6c7cc46c7cae8b69ea5ffd137f5d0a6c80b059b3c5187f2093f96ec
MD5 d94761c2a39d3ea459eac58f8b50d02c
BLAKE2b-256 a5d1a804d1df11f10d284d0bae09d5d5fa8dfb4d64f0a941d1e6c61ff3eb48d8

See more details on using hashes here.

File details

Details for the file kehe_fl-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: kehe_fl-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for kehe_fl-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 fe13e6cd9c77275e8c3550c74fd737a77754ebd13f0589b4c39cd790ef7603d9
MD5 db4ea4061d337bc1f264cd4d80ca02c3
BLAKE2b-256 851fdd5004df80f3040499a09e67971dc61e72a6fee9b0c390898809a14a2b0a

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