The KPN SenML library helps you create and parse senml documents in both json and cbor format. The library can be used for sending sensor data and receiving actuator commands.

Revision:
0:a9259748d982
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/senml_binary_record.cpp	Sat May 19 17:35:20 2018 +0000
@@ -0,0 +1,56 @@
+/*  _  __  ____    _   _ 
+ * | |/ / |  _ \  | \ | |
+ * | ' /  | |_) | |  \| |
+ * | . \  |  __/  | |\  |
+ * |_|\_\ |_|     |_| \_|
+ * 
+ * (c) 2018 KPN
+ * License: MIT License.
+ * Author: Jan Bogaerts
+ * 
+ * support for binary sensors
+ */
+
+#include <senml_binary_record.h>
+#include <senml_helpers.h>
+#include <cbor.h>
+
+SenMLBinaryRecord::SenMLBinaryRecord(const char* name): SenMLRecord(name)
+{
+}
+
+SenMLBinaryRecord::SenMLBinaryRecord(const char* name, SenMLUnit unit): SenMLRecord(name, unit)
+{
+}
+
+bool SenMLBinaryRecord::set(unsigned char* value, unsigned int length, double time) 
+{
+    this->_value = (unsigned char*)malloc(length);
+    memcpy(this->_value, value, length);
+    this->_length = length;
+    return this->setTime(time);
+}
+
+
+void SenMLBinaryRecord::fieldsToJson()
+{
+    SenMLRecord::fieldsToJson();
+    printText(",\"vd\":\"", 7);
+    printBinaryAsBase64(this->_value, this->_length);
+    printText("\"", 1);
+}
+
+int SenMLBinaryRecord::fieldsToCbor()
+{
+    int res = SenMLRecord::fieldsToCbor();
+    res += cbor_serialize_int(SENML_CBOR_VD_LABEL);
+    res += cbor_serialize_byte_string((const char*)this->_value, this->_length);
+    return res;
+}
+
+
+
+
+
+
+