Java ❤️ Supla
jSupla is an implementation of the Supla protocol for Java, designed to facilitate the development of IoT (Internet of Things) applications. The Supla protocol is used for communication between smart devices, enabling them to interact seamlessly within a connected environment. With jSupla, developers can create servers that communicate with Supla-compatible devices, handling various operations such as data exchange, command execution, and device status monitoring.
The project provides two main modules: protocol
and server
. The protocol
module includes the necessary data
structures and serialization/deserialization mechanisms for the Supla protocol, while the server
module offers a
robust server implementation using Reactor and Netty. This combination allows for efficient, asynchronous communication
with Supla devices, making it easier to build scalable and responsive IoT solutions.
Module | Description |
---|---|
protocol | Contains structures that are sent in the Supla environment and decoders/encoders for them. The code generation is done during the Gradle build. |
server | Implements a server for Supla devices and clients. Internally, it uses Reactor and Netty. |
Both modules are deployed to Maven Central.
The protocol module can be found at Maven Repository - Protocol:
<dependency>
<groupId>pl.grzeslowski.jSupla</groupId>
<artifactId>protocol</artifactId>
<version>X.Y.Z</version>
</dependency>
implementation group: 'pl.grzeslowski.jSupla', name: 'protocol', version: 'X.Y.Z'
The server module can be found at Maven Repository - Server:
<dependency>
<groupId>pl.grzeslowski.jSupla</groupId>
<artifactId>server</artifactId>
<version>X.Y.Z</version>
</dependency>
implementation group: 'pl.grzeslowski.jSupla', name: 'server', version: 'X.Y.Z'
This section provides examples of how to use the jSupla library to set up a server and handle communication with Supla devices.
The proto module provides the necessary structures and codecs for communication in the Supla environment. Below is an example of how to use these structures.
Here is a basic example of encoding and decoding a Supla protocol message:
import pl.grzeslowski.jsupla.protocol.api.decoders.DecoderFactoryImpl;
import pl.grzeslowski.jsupla.protocol.api.encoders.EncoderFactoryImpl;
import pl.grzeslowski.jsupla.protocol.api.structs.sd.SuplaRegisterDeviceResult;
public class ProtoExample {
public static void main(String[] args) {
// Create encoder and decoder factories
EncoderFactoryImpl encoderFactory = new EncoderFactoryImpl();
DecoderFactoryImpl decoderFactory = new DecoderFactoryImpl();
// Example structure
SuplaRegisterDeviceResult result = new SuplaRegisterDeviceResult(
1, // resultCode
2, // activityTimeout
3, // version
4 // minVersion
);
// Encode the structure
byte[] encodedData = encoderFactory.getEncoder(SuplaRegisterDeviceResult.class).encode(result);
// Decode the structure
SuplaRegisterDeviceResult decodedResult = (SuplaRegisterDeviceResult) decoderFactory.getDecoder(SuplaRegisterDeviceResult.class).decode(encodedData);
// Print the decoded result
System.out.println("Decoded Result: " + decodedResult);
}
}
To create a server using the server
module, you can refer to the Server
class provided in the project. This class
demonstrates how to initialize and run a server that communicates with Supla devices.
Check example code
in Server
class:
If you find jSupla helpful and would like to support the author of this project, consider buying him a coffee: