33 lines
899 B
C++
33 lines
899 B
C++
#include <Arduino.h>
|
|
#include <SimpleSerialProtocol.h>
|
|
|
|
// Define new device
|
|
SimpleSerialProtocol deviceOne;
|
|
|
|
// Gets called when a complete packet has been received.
|
|
void onPacket(Packet packet) {
|
|
Serial.println("Received Packet!");
|
|
Serial.println(packet.id);
|
|
Serial.println(packet.command);
|
|
Serial.println(packet.data);
|
|
Serial.println("----------------");
|
|
|
|
// To send a packet
|
|
deviceOne.sendPacket("IDPacket", "Commandhere", "testtest");
|
|
}
|
|
|
|
void setup() {
|
|
// Initialize (deviceOne) serial device on index 0 with a baud rate of 115200.
|
|
deviceOne.init(0, 115200);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|