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
    • cpp / c / 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++
  • JavaScript
  • TypeScript
  • Python
  • C

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.0.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

lionsc-2.0.2-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lionsc-2.0.2.tar.gz
Algorithm Hash digest
SHA256 9c62f9c7cd17ecfe50f942e1f01d341f2c3c4c3dcf767bb660e3d981a5c8c4b2
MD5 732e16a4d67958b259830b39dd8cbc15
BLAKE2b-256 10c6938ec0ba8a8017d4a9de2c8146f0d642553e5bd3026bda8b10721d6cb1fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lionsc-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.1 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.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 744078c2000a0a172be7e9e9e47825c55512dc9782306310575a5fe936297a01
MD5 9ab55fa5286cfa0e718ea51c75cc8dee
BLAKE2b-256 a26f0b80f853a8b8bc97476333a2884f33318ef6c0c937ddabe2576d8155fe5f

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