I created a SmartREST template for measurements. Sometimes, individual data points within a single measurement don’t have a value so I would like to record them as null. I can do that via REST but via SmartREST I fail to do that.
I can leave out the timestamp as described but how to send null values for other non-mandatory values?
999,2025-12-31T11:22:33Z,1,2
- ok
999,,1,2
- ok, using server time
999,,,2
- not ok, gives
50,,Error of type: NullPointerException with message: null
999,,null,2
- not ok, no error message but message is ignored
Is there a way to do this? Maybe a flag in the template to mark a field as “optional” explicitly?
Thanks for your support!
Christoph
Custom templates in SmartREST do not support optional values besides time fields. All values that are declared in the template must be included in the payload.
declaring values as “null” (with or without the quotes) is interpreted as the 4-character string “null”. Leaving a field empty may work for fields of type Sting. However for measurements this is not a suitable option because measurement values must always be numerical and not null.
To solve this you either need to create a template for every case of fragment-value existing in your use case. Typically this is can be done in a dedicated template collection that uses the message ID to identify which value is present and which is not.
Another alternative is to use the static template for complex measurements (MQTT static templates - 201) that allows dynamic adding of values per message at the cost of increased transfer data volume
1 Like
Thanks for the clarification, Philipp!