Skip to main content

LIONS is a communication protocol coupled with a compiler (lionsc), specifically designed for low-bandwidth IoT mesh and ad hoc networks.

Project description

LIONS (Lightweight IoT Network Specification)

Index

Description

LIONS is a communication protocol coupled with a compiler (lionsc), specifically designed for low-bandwidth IoT mesh and ad hoc networks. Originally tailored for LoRa, LIONS is versatile enough to be adapted to various communication standards, thanks to its protocol-agnostic message encoding approach.

The core of LIONS lies in its efficient message encoding system. Messages are compactly encoded into byte arrays, ensuring that each value occupies only the necessary space required by its type, thus minimizing space.

Message structures are defined using YAML files (.lmsg.yaml), which detail the message name, ID, and its data fields. These files serve as input for the LIONS compiler, which generates the necessary code for accurate message encoding and decoding.

This protocol is ideal for developers looking to implement efficient, data-constraint communications in their IoT network projects.

Install

$ pip install lionsc

Usage

$ lionsc <msg_files_dir> <output_dir> <target_language>
  • msg_files_dir: Directory containing your .lmsg.yaml files
  • output_dir: Directory to place the generated code
  • target_language: Target language for the generated code
    • c / cpp / js / ts / py

Raw Message format

The message structure is composed of a 6-byte header, followed by a variable-length payload. The payload length can range from 0 to 244 bytes, allowing for flexible data encapsulation. Fields within the payload are tightly packed, with no intervening spaces, to maximize message efficiency and minimize overhead.

Byte Index Field Size (Bytes) Description
0 src 1 Source identifier
1 dst 1 Destination identifier
2 next_hop 1 Next hop identifier (used for message forwarding)
3 msg_id 1 Message identifier
4-5 checksum 2 Checksum for error checking
6-249 payload 244 Actual data payload

Code representation

Defining Messages

LIONS uses .lmsg.yaml files to define message specifications for IoT networks. Each file can contain multiple message definitions that are used by the LIONS compiler to generate C++ code for message handling.

Structure of Message Files

  • Name of the Message: Unique identifier for each message type.
  • ID: Identifier unique to each message ()can be given in hexadecimal, decimal, or binary.
  • Period: Used to generate a constant for message scheduling (implementation needs to be done by teh user).
  • Description: Brief explanation of the message's purpose.
  • Fields:
    • Type: Data type (float, int16_t, string, etc.).
    • Size: Size in bytes, variable for strings.
    • Description: Explanation of the field's purpose.
accelerometer:
    id: 0x01
    period: 1000
    description: "Accelerometer data"

    fields:
        acc_x:
            type: float
            size: 4
            description: "Acceleration in x-axis m/s^2"

        acc_y:
            type: float
            size: 4
            description: "Acceleration in y-axis m/s^2"

        acc_z:
            type: float
            size: 4
            unit: "m/s^2"
            description: "Acceleration in z-axis m/s^2"

microphone:
    id: 0x02
    period: 0
    description: "Microphone data"

    fields:
        message:
            type: string
            size: 100
            description: "Speach-to-text message"

ping:
    id: 0x03
    period: 1000
    description: "Ping message"

Generated code

The LIONS compiler auto-generates code to facilitate handling, encoding and decoding of messages defined in .lmsg.yaml files. Below is an example of how part of the generated code might look for the yaml file above.

Constants

The code defines namespaces to hold constants for message IDs and periods, ensuring easy reference throughout the codebase:

C++ example:

namespace msg_id {
    constexpr uint8_t ACCELEROMETER = 1;
    constexpr uint8_t MICROPHONE = 2;
    constexpr uint8_t PING = 3;
}  // namespace msg_id

namespace msg_period {
    constexpr uint8_t ACCELEROMETER = 1000;
    constexpr uint8_t MICROPHONE = 0;
    constexpr uint8_t PING = 1000;
}  // namespace msg_period

Message struct/class

For each message type defined in the YAML files, the LIONS compiler generates a corresponding struct/class. This class includes the specific fields of the message, two constructors, and an encode method.

  1. Initialization Constructor

    • Used to create a new instance of the message class with predefined field values. This constructor initializes the message with specific data relevant to its type.
  2. Decoding Constructor

    • Transforms a generic, raw-form message (LMsg) into the structured format of the class. This conversion facilitates easier manipulation and interpretation of the message contents within the application.
  3. Encode Method

    • Converts the structured message back into its raw binary form (LMsg) for transmission. This method ensures that the message is properly packaged with its header and payload according to the protocol specifications before being sent over the network.

Generated message classes examples:

Examples

Target Language Support

  • C
  • C++
  • JavaScript
  • TypeScript
  • Python

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

lionsc-2.1.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

lionsc-2.1.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file lionsc-2.1.0.tar.gz.

File metadata

  • Download URL: lionsc-2.1.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for lionsc-2.1.0.tar.gz
Algorithm Hash digest
SHA256 452fff252daf53f8568d39b4988ba2d2928223f3cdd9ae9a9bafe8ae3864ab39
MD5 5c0f1635ffe961d2bacb13c5f31c2bd5
BLAKE2b-256 d7d3b8807602bce08e688ec996a5a3144cafb40378de46cb260896682c431f3d

See more details on using hashes here.

File details

Details for the file lionsc-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: lionsc-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.0

File hashes

Hashes for lionsc-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8bfb7ae44183331089490696474fd17c1653e78e7840d8d0c2a450ac725b0a9
MD5 738bc55fe5ad6fad87db67e3a5806f30
BLAKE2b-256 a59927574c9b232711a2525ec597e00d7e631e3bdd689a6233956b8507608ace

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page