Arduino KVComm  master
Key-Value pair communication library for Arduino
KVComm-Send.ino

KVComm-Send

Send a SLIP package with a dictionary of key-value pairs over the serial port every 5 seconds.

Boards:
AVR, AVR USB, Nano Every, Nano 33, Due, Teensy 3.x, ESP8266, ESP32
  1. Upload this sketch to one Arduino.
  2. Upload the KVComm-Receive.ino sketch to a second Arduino.
  3. Connect the TX pin of this Arduino to the RX pin of the second Arduino.
  4. Open the Serial monitor of the second Arduino.

It should print the following:


abc: 1, 2, 3

password: qwerty123

analog 0: 777

seconds: 12.07


For boards where Serial is not a hardware UART, use Serial1 as the stream for the SLIPStream.

Written by PieterP, 2020-02-08
https://github.com/tttapa/Arduino-KVComm

#include <KVComm.h>
#include <boost/crc.hpp>
// The CRC settings to use, must be the same as the receiver.
using CRC = boost::crc_optimal<16, 0x1021, 0xFFFF, 0, false, false>;
// The actual SLIP Stream: it sends and receives packets, adds framing
// bytes, and computes a checksum using the CRC specified above.
Serial, // stream
CRC(), // sender CRC
nullptr, // no parser
CRC(), // parser CRC
};
// The dictionary with data to send.
void setup() {
Serial.begin(115200);
// Add some data to the dictionary.
dict.add("abc", {1, 2, 3});
dict.add("password", "qwerty123");
}
void loop() {
// The following will be overwritten on each iteration.
dict.add("analog 0", analogRead(A0));
dict.add("seconds", millis() / 1000.0);
// Send the buffer over the SLIPStream
slip.writePacket(dict.getBuffer(), dict.getLength());
delay(2000);
}
KVComm.h
KV_Builder::add
bool add(const char *key, const T *data, size_t count)
Add a key-value pair to the dictionary, or update the existing value with the same key.
Definition: KV_Builder.hpp:142
KV_Builder::getBuffer
const uint8_t * getBuffer() const
Get the buffer containing the dictionary.
Definition: KV_Builder.hpp:421
AH::ExtIO::analogRead
analog_t analogRead(pin_t pin)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:86
Static_KV_Builder
KV_Builder with a static buffer.
Definition: KV_Builder.hpp:452
SLIPStreamCRC
Class that implements SLIP, a simple packet framing protocol, and that uses cyclic redundancy checks ...
Definition: SLIPStream.hpp:84
SLIPStream.hpp
KV_Builder::getLength
size_t getLength() const
Get the length of the used part of the buffer.
Definition: KV_Builder.hpp:425
SLIPStreamCRC::writePacket
size_t writePacket(const uint8_t *data, size_t len)
Sends a packet.
Definition: SLIPStream.ipp:6