updated readme

This commit is contained in:
Nick Leeman 2021-05-01 20:24:28 +02:00
parent ae2a092fab
commit 929f4042e0
2 changed files with 9 additions and 16 deletions

View File

@ -38,25 +38,21 @@ SimpleSerialProtocol has a very simple API so it should be very easy to implemen
The protocol works as following, each packet has 3 seperate stages.
### ID
This could be the device or service you want to reach.
ID of packet (device)
### Command
This is the command you want to send to the device or service.
### Type
Type of packet (action)
### Data
This is the data you want to send to the device or service.
Data of packet (data)
Of course you could change the use of any of these values to fit your needs.
A complete packet would look like this:
```
<ID_HERE:COMMAND_HERE:DATA_HERE>
ID - TYPE - DATA
```
As you can see the packet starts and ends with ``< - >`` characters and the stages are seperated with `` : `` characters.
`This means you can't use any of these characters as data in the packets!!`
Include SSP and define a new device.
```c++
#include <SimpleSerialProtocol.h>
@ -80,7 +76,7 @@ Now create a method (with a packet parameter) which will be called when a packet
void onPacket(Packet packet) {
Serial.println("Received Packet!");
Serial.println(packet.id);
Serial.println(packet.command);
Serial.println(packet.type);
Serial.println(packet.data);
Serial.println("----------------");
}
@ -92,7 +88,7 @@ void loop() {
```
To send packets you can use the ``sendPacket`` method.
```c++
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
deviceOne.sendPacket("IDPacket", "Typehere", "testtest");
```
## Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

View File

@ -8,12 +8,12 @@ SimpleSerialProtocol deviceOne;
void onPacket(Packet packet) {
Serial.println("Received Packet!");
Serial.println(packet.id);
Serial.println(packet.command);
Serial.println(packet.type);
Serial.println(packet.data);
Serial.println("----------------");
// To send a packet
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
deviceOne.sendPacket("IDPacket", "TypeHere", "testtest");
}
void setup() {
@ -25,8 +25,5 @@ void loop() {
// Call receive packets function (looping) to handle incoming serial packets.
// If a complete packet has been received it will call the callback function (onPacket).
deviceOne.receivePackets(onPacket);
// Small delay to not over overwork CPU.
delay(1);
}