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 KPN IoT

senml_string_record.cpp

Committer:
kpniot
Date:
2018-05-19
Revision:
0:a9259748d982

File content as of revision 0:a9259748d982:

/*  _  __  ____    _   _ 
 * | |/ / |  _ \  | \ | |
 * | ' /  | |_) | |  \| |
 * | . \  |  __/  | |\  |
 * |_|\_\ |_|     |_| \_|
 * 
 * (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;
}