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.
Fork of kpn_senml by
Diff: senml_string_record.cpp
- Revision:
- 0:a9259748d982
diff -r 000000000000 -r a9259748d982 senml_string_record.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/senml_string_record.cpp Sat May 19 17:35:20 2018 +0000 @@ -0,0 +1,40 @@ +/* _ __ ____ _ _ + * | |/ / | _ \ | \ | | + * | ' / | |_) | | \| | + * | . \ | __/ | |\ | + * |_|\_\ |_| |_| \_| + * + * (c) 2018 KPN + * License: MIT License. + * Author: Jan Bogaerts + * + * support for string sensors + */ + + +#include <senml_string_record.h> +#include <cbor.h> +#include <senml_helpers.h> + +void SenMLStringRecord::fieldsToJson() +{ + SenMLRecord::fieldsToJson(); + printText(",\"vs\":\"", 7); + String val = this->get(); + printText(val.c_str(), val.length()); + printText("\"", 1); +} +int SenMLStringRecord::fieldsToCbor() +{ + int res = SenMLRecord::fieldsToCbor(); + res += cbor_serialize_int(SENML_CBOR_VS_LABEL); + res += cbor_serialize_unicode_string(this->get().c_str()); + return res; +} + + + + + + +