Advanced Configuration
######################

.. _format-editor:

Format editor
+++++++++++++

To reduce the need for adding custom endpoints for various services there is an built in format editor that allows the user to customize the format being sent to the push target. 

.. warning::

   Since the format templates can be big this function can be quite slow on a small device such as the esp8266. 

.. image:: images/format.png
  :width: 800
  :alt: Format editor

You enter the format data in the text field and the test button will show an example on what the output would look like. If the data cannot be formatted in json it will just be displayed as a long string.
The save button will save the current formula and reload the data from the device. 

You can also select a template from the list and copy that to the current endpoint. 

Saving an empty formula will reset it to the default value.

.. tip::

   If you save a blank string the default template will be loaded.

These are the format keys available for use in the format.

.. list-table:: Directory structure
   :widths: 30 50 20
   :header-rows: 1

   * - key 
     - description
     - example
   * - ${mdns}
     - Name of the device
     - gravmon2
   * - ${token}
     - Token
     - any value
   * - ${token2}
     - Token 2
     - any value
   * - ${id}
     - Unique id of the device
     - e422a3
   * - ${sleep-interval}
     - Seconds between data is pushed
     - 900
   * - ${temp}
     - Temperature in format configured on device, one decimal
     - 21.2
   * - ${temp-c}
     - Temperature in C, one decimal
     - 21.2
   * - ${temp-f}
     - Temperature in F, one decimal
     - 58.0
   * - ${temp-unit}
     - Temperature format `C` or `F`
     - C
   * - ${battery}
     - Battery voltage, two decimals
     - 3.89
   * - ${rssi}
     - Wifi signal strength
     - -75
   * - ${run-time}
     - How long the last measurement took, two decimals
     - 3.87
   * - ${angle}
     - Angle of the gyro, two decimals
     - 28.67
   * - ${tilt}
     - Same as angle.
     - 28.67
   * - ${gravity}
     - Calculated gravity, 4 decimals for SG and 1 for Plato.
     - 1.0456
   * - ${gravity-sg}
     - Calculated gravity in SG, 4 decimals
     - 1.0456
   * - ${gravity-plato}
     - Calculated gravity in Plato, 1 decimal
     - 8.5
   * - ${corr-gravity}
     - Temperature corrected gravity, 4 decimals for SG and 1 for Plato.
     - 1.0456
   * - ${corr-gravity-sg}
     - Temperature corrected gravity in SG, 4 decimals
     - 1.0456
   * - ${corr-gravity-plato}
     - Temperature corrected gravity in Plato, 1 decimal
     - 8.5
   * - ${gravity-unit}
     - Gravity format, `G` or `P`
     - G
   * - ${app-ver}
     - Software version
     - 1.1.0
   * - ${app-build}
     - Software revision (git hash)
     - ..e456743

