What are Note Templates?
Note Templates are a description of a prescribed, flat data structure with pre-set sizes for data added to the body of Notes in a Notefile.
A Note Template names each field of the Note Body. Each named field must also describe the datatype of the field value.
For more information about how to create Note Templates, see the note.template request documentation.
Why should you use them?
Note Templates provide Notecard with way to store future Notes added to a Notefile as fixed-length binary records.
Using this type of storage enables:
Increased storage capability
Faster data syncs
With increased storage, you can enqueue more data on the Notecard, enabling longer periods between syncs with the cloud. This can help preserve power usage, by reducing the number of syncs.
Faster data syncs result in less time to sync data with Notehub. Once a connection is established to Notehub, more data can be moved much more quickly with fewer computing resources. The reduced connection time also helps conserve power usage.
When should you use Note Templates?
Most Notecard applications can and should use Note Templates to queue data.
Sensor data is ideal, as the number of recorded elements and data types are probably fixed.
For example, storing temperature data, each point will consist of a numeric value for temperature. Knowing this information prior to queuing each measurement value on the Notecard to store and transmit the data as raw bytes rather than including the JSON data structure for each data point.
When should you avoid Note Templates?
If the structure and size of the stored data elements cannot be known a priori, the data structure must change frequently, or the data structure must contain nested JSON elements, then Note Templates may not be a good fit.
A few Note Template tips
Flatten the JSON anyway
If the primary issue preventing you from using Note Templates is the nesting of the data structure elements, it is often worth flattening that data structure do you can leverage Note Templates.
If your cloud endpoints consuming the Notecard data require nested JSON elements, try flattening the data structure on Notecard and using Note Templates anyway. Then reconstruct the JSON as nested elements on Notehub when the data is routed to your cloud endpoint.
The flat JSON structure can be transformed into some arbitrary JSON structure by using Notehub Route JSON Transform with JSONata expressions. For more about JSON transformation, see this Notehub Route tutorial
Change Note Templates on the fly
If the structure of a Note Template needs to change to accommodate a change the JSON data structure, issue a new note.template request to the Notecard.
For example, imagine your application supports dynamically adding temperature sensors. You do not want to lose the information from previous temperature measurements from the existing sensors, but you want to accommodate data from the additional sensor in the same Notefile. In this case, reissue the Note Template request and include an additional field for the new temperature sensor.
However, if the data structure is changing every data point, then this probably is not worth the overhead.