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

Committer:
kpniot
Date:
Sat May 19 17:35:20 2018 +0000
Revision:
0:a9259748d982
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kpniot 0:a9259748d982 1 /* _ __ ____ _ _
kpniot 0:a9259748d982 2 * | |/ / | _ \ | \ | |
kpniot 0:a9259748d982 3 * | ' / | |_) | | \| |
kpniot 0:a9259748d982 4 * | . \ | __/ | |\ |
kpniot 0:a9259748d982 5 * |_|\_\ |_| |_| \_|
kpniot 0:a9259748d982 6 *
kpniot 0:a9259748d982 7 * (c) 2018 KPN
kpniot 0:a9259748d982 8 * License: MIT License.
kpniot 0:a9259748d982 9 * Author: Jan Bogaerts
kpniot 0:a9259748d982 10 *
kpniot 0:a9259748d982 11 * unit and record names
kpniot 0:a9259748d982 12 */
kpniot 0:a9259748d982 13
kpniot 0:a9259748d982 14 #ifndef SENMLENUMS
kpniot 0:a9259748d982 15 #define SENMLENUMS
kpniot 0:a9259748d982 16
kpniot 0:a9259748d982 17
kpniot 0:a9259748d982 18 /**
kpniot 0:a9259748d982 19 * Lists all the data types that a value can have in senml.
kpniot 0:a9259748d982 20 * This is primarely used for actuator callbacks on SenMLPack objects when no appropirate SenMLRecord could be found for the acutator command.
kpniot 0:a9259748d982 21 */
kpniot 0:a9259748d982 22 enum SenMLDataType { //json data types:
kpniot 0:a9259748d982 23 SENML_TYPE_NR, SENML_TYPE_STRING, SENML_TYPE_BOOL, SENML_TYPE_DATA,
kpniot 0:a9259748d982 24 //cbor data types, which have already converted the data value
kpniot 0:a9259748d982 25 CBOR_TYPE_UINT, CBOR_TYPE_INT, CBOR_TYPE_STRING, CBOR_TYPE_FLOAT, CBOR_TYPE_DOUBLE, CBOR_TYPE_BOOL, CBOR_TYPE_DATA
kpniot 0:a9259748d982 26 };
kpniot 0:a9259748d982 27
kpniot 0:a9259748d982 28 extern const char* senml_units_names[];
kpniot 0:a9259748d982 29
kpniot 0:a9259748d982 30 /**
kpniot 0:a9259748d982 31 * Determines how data should be read/rendered to the stream: in the original format
kpniot 0:a9259748d982 32 * or converted to hex values. The latter is used for serial communication with a modem such as a lora modem.
kpniot 0:a9259748d982 33 */
kpniot 0:a9259748d982 34 enum SenMLStreamMethod {SENML_HEX, SENML_RAW};
kpniot 0:a9259748d982 35
kpniot 0:a9259748d982 36 /**
kpniot 0:a9259748d982 37 * Lists all the units of measurement that are supported by SenML.
kpniot 0:a9259748d982 38 */
kpniot 0:a9259748d982 39 enum SenMLUnit {SENML_UNIT_NONE,
kpniot 0:a9259748d982 40 SENML_UNIT_METER,
kpniot 0:a9259748d982 41 SENML_UNIT_KILOGRAM,
kpniot 0:a9259748d982 42 SENML_UNIT_GRAM,
kpniot 0:a9259748d982 43 SENML_UNIT_SECOND,
kpniot 0:a9259748d982 44 SENML_UNIT_AMPERE,
kpniot 0:a9259748d982 45 SENML_UNIT_KELVIN,
kpniot 0:a9259748d982 46 SENML_UNIT_CANDELA,
kpniot 0:a9259748d982 47 SENML_UNIT_MOLE,
kpniot 0:a9259748d982 48 SENML_UNIT_HERTZ,
kpniot 0:a9259748d982 49 SENML_UNIT_RADIAN,
kpniot 0:a9259748d982 50 SENML_UNIT_STERADIAN,
kpniot 0:a9259748d982 51 SENML_UNIT_NEWTON,
kpniot 0:a9259748d982 52 SENML_UNIT_PASCAL,
kpniot 0:a9259748d982 53 SENML_UNIT_JOULE,
kpniot 0:a9259748d982 54 SENML_UNIT_WATT,
kpniot 0:a9259748d982 55 SENML_UNIT_COULOMB,
kpniot 0:a9259748d982 56 SENML_UNIT_VOLT,
kpniot 0:a9259748d982 57 SENML_UNIT_FARAD,
kpniot 0:a9259748d982 58 SENML_UNIT_OHM,
kpniot 0:a9259748d982 59 SENML_UNIT_SIEMENS,
kpniot 0:a9259748d982 60 SENML_UNIT_WEBER,
kpniot 0:a9259748d982 61 SENML_UNIT_TESLA,
kpniot 0:a9259748d982 62 SENML_UNIT_HENRY,
kpniot 0:a9259748d982 63 SENML_UNIT_DEGREES_CELSIUS,
kpniot 0:a9259748d982 64 SENML_UNIT_LUMEN,
kpniot 0:a9259748d982 65 SENML_UNIT_LUX ,
kpniot 0:a9259748d982 66 SENML_UNIT_BECQUEREL,
kpniot 0:a9259748d982 67 SENML_UNIT_GRAY,
kpniot 0:a9259748d982 68 SENML_UNIT_SIEVERT,
kpniot 0:a9259748d982 69 SENML_UNIT_KATAL,
kpniot 0:a9259748d982 70 SENML_UNIT_SQUARE_METER,
kpniot 0:a9259748d982 71 SENML_UNIT_CUBIC_METER,
kpniot 0:a9259748d982 72 SENML_UNIT_LITER ,
kpniot 0:a9259748d982 73 SENML_UNIT_VELOCITY,
kpniot 0:a9259748d982 74 SENML_UNIT_ACCELERATION,
kpniot 0:a9259748d982 75 SENML_UNIT_CUBIC_METER_PER_SECOND,
kpniot 0:a9259748d982 76 SENML_UNIT_LITER_PER_SECOND,
kpniot 0:a9259748d982 77 SENML_UNIT_WATT_PER_SQUARE_METER,
kpniot 0:a9259748d982 78 SENML_UNIT_CANDELA_PER_SQUARE_METER,
kpniot 0:a9259748d982 79 SENML_UNIT_BIT ,
kpniot 0:a9259748d982 80 SENML_UNIT_BIT_PER_SECOND,
kpniot 0:a9259748d982 81 SENML_UNIT_DEGREES_LATITUDE,
kpniot 0:a9259748d982 82 SENML_UNIT_DEGREES_LONGITUDE,
kpniot 0:a9259748d982 83 SENML_UNIT_PH ,
kpniot 0:a9259748d982 84 SENML_UNIT_DECIBEL ,
kpniot 0:a9259748d982 85 SENML_UNIT_DECIBEL_RELATIVE_TO_1_W,
kpniot 0:a9259748d982 86 SENML_UNIT_BEL ,
kpniot 0:a9259748d982 87 SENML_UNIT_COUNTER,
kpniot 0:a9259748d982 88 SENML_UNIT_RATIO ,
kpniot 0:a9259748d982 89 SENML_UNIT_RELATIVE_HUMIDITY,
kpniot 0:a9259748d982 90 SENML_UNIT_PERCENTAGE_REMAINING_BATTERY_LEVEL,
kpniot 0:a9259748d982 91 SENML_UNIT_SECONDS_REMAINING_BATTERY_LEVEL,
kpniot 0:a9259748d982 92 SENML_UNIT_EVENT_RATE_PER_SECOND,
kpniot 0:a9259748d982 93 SENML_UNIT_EVENT_RATE_PER_MINUTE,
kpniot 0:a9259748d982 94 SENML_UNIT_BPM,
kpniot 0:a9259748d982 95 SENML_UNIT_BEATS,
kpniot 0:a9259748d982 96 SENML_UNIT_SIEMENS_PER_METER
kpniot 0:a9259748d982 97 };
kpniot 0:a9259748d982 98
kpniot 0:a9259748d982 99
kpniot 0:a9259748d982 100 #define KPN_SENML_PRESSURE "pressure"
kpniot 0:a9259748d982 101 #define KPN_SENML_ANGLE "angle"
kpniot 0:a9259748d982 102 #define KPN_SENML_LENGHT "lenght"
kpniot 0:a9259748d982 103 #define KPN_SENML_BREADTH "breadth"
kpniot 0:a9259748d982 104 #define KPN_SENML_HEIGHT "height"
kpniot 0:a9259748d982 105 #define KPN_SENML_WEIGHT "weight"
kpniot 0:a9259748d982 106 #define KPN_SENML_THICKNESS "thickness"
kpniot 0:a9259748d982 107 #define KPN_SENML_DISTANCE "distance"
kpniot 0:a9259748d982 108 #define KPN_SENML_AREA "area"
kpniot 0:a9259748d982 109 #define KPN_SENML_VOLUME "volume"
kpniot 0:a9259748d982 110 #define KPN_SENML_VELOCITY "velocity"
kpniot 0:a9259748d982 111 #define KPN_SENML_ELECTRICCURRENT "electricCurrent"
kpniot 0:a9259748d982 112 #define KPN_SENML_ELECTRICPOTENTIAL "electricPotential"
kpniot 0:a9259748d982 113 #define KPN_SENML_ELECTRICRESISTANCE "electricResistance"
kpniot 0:a9259748d982 114 #define KPN_SENML_TEMPERATURE "temperature"
kpniot 0:a9259748d982 115 #define KPN_SENML_ILLUMINANCE "illuminance"
kpniot 0:a9259748d982 116 #define KPN_SENML_ALTITUDE "altitude"
kpniot 0:a9259748d982 117 #define KPN_SENML_ACCELERATIONX "accelerationX"
kpniot 0:a9259748d982 118 #define KPN_SENML_ACCELERATIONY "accelerationY"
kpniot 0:a9259748d982 119 #define KPN_SENML_ACCELERATIONZ "accelerationZ"
kpniot 0:a9259748d982 120 #define KPN_SENML_HEADING "heading"
kpniot 0:a9259748d982 121 #define KPN_SENML_LONGITUDE "longitude"
kpniot 0:a9259748d982 122 #define KPN_SENML_LATTITUDE "lattitude"
kpniot 0:a9259748d982 123 #define KPN_SENML_CARBONMONOXIDE "carbonMonoxide"
kpniot 0:a9259748d982 124 #define KPN_SENML_CARBONDIOXIDE "carbonDioxide"
kpniot 0:a9259748d982 125 #define KPN_SENML_SOUND "sound"
kpniot 0:a9259748d982 126 #define KPN_SENML_FREQUENCY "frequency"
kpniot 0:a9259748d982 127 #define KPN_SENML_BATTERYLEVEL "batteryLevel"
kpniot 0:a9259748d982 128 #define KPN_SENML_HUMIDITY "humidity"
kpniot 0:a9259748d982 129
kpniot 0:a9259748d982 130 #endif // !SENMLENUMS
kpniot 0:a9259748d982 131
kpniot 0:a9259748d982 132
kpniot 0:a9259748d982 133
kpniot 0:a9259748d982 134
kpniot 0:a9259748d982 135
kpniot 0:a9259748d982 136
kpniot 0:a9259748d982 137