<phyphox version="1.11" locale="en">
  <title>MQTT JSON IMU+GPS Buffered (no T)</title>
  <category>Net examples</category>
  <description>IMU at 10 Hz plus GPS, buffered JSON every 1 s. No timestamp arrays.</description>

  <data-containers>
    <!-- Accelerometer -->
    <container size="10">accX</container>
    <container size="10">accY</container>
    <container size="10">accZ</container>

    <!-- Gyroscope -->
    <container size="10">gyrX</container>
    <container size="10">gyrY</container>
    <container size="10">gyrZ</container>

    <!-- Magnetic field -->
    <container size="10">magX</container>
    <container size="10">magY</container>
    <container size="10">magZ</container>

    <container size="10">laccX</container>
    <container size="10">laccY</container>
    <container size="10">laccZ</container>

    <container size="10">gX</container>
    <container size="10">gY</container>
    <container size="10">gZ</container>

    <container size="10">attW</container>
    <container size="10">attX</container>
    <container size="10">attY</container>
    <container size="10">attZ</container>


    <!-- GPS / Location -->
    <container size="1">gpsLat</container>
    <container size="1">gpsLon</container>
    <container size="1">gpsAlt</container>
    <container size="1">gpsSpeed</container>
    <container size="1">gpsDir</container>
    <container size="1">gpsAcc</container>
  </data-containers>

  <network>
    <connection id="mqtt"
                address="vmtest01.dotvision.com:1883"
                service="mqtt/json"
                sendTopic="phyphox/imu_gps/buffered"
                privacy="https://phyphox.org/disclaimer/"
                autoConnect="true"
                interval="1">
      <!-- Accelerometer (m/s^2) -->
      <send id="acc_x" type="buffer" datatype="array" keep="true">accX</send>
      <send id="acc_y" type="buffer" datatype="array" keep="true">accY</send>
      <send id="acc_z" type="buffer" datatype="array" keep="true">accZ</send>

      <send id="lacc_x" type="buffer" datatype="array" keep="true">laccX</send>
      <send id="lacc_y" type="buffer" datatype="array" keep="true">laccY</send>
      <send id="lacc_z" type="buffer" datatype="array" keep="true">laccZ</send>


      <!-- Gyroscope (rad/s) -->
      <send id="gyr_x" type="buffer" datatype="array" keep="true">gyrX</send>
      <send id="gyr_y" type="buffer" datatype="array" keep="true">gyrY</send>
      <send id="gyr_z" type="buffer" datatype="array" keep="true">gyrZ</send>

      <!-- Magnetic field (uT) -->
      <send id="mag_x" type="buffer" datatype="array" keep="true">magX</send>
      <send id="mag_y" type="buffer" datatype="array" keep="true">magY</send>
      <send id="mag_z" type="buffer" datatype="array" keep="true">magZ</send>


      <send id="g_x" type="buffer" datatype="array" keep="true">gX</send>
      <send id="g_y" type="buffer" datatype="array" keep="true">gY</send>
      <send id="g_z" type="buffer" datatype="array" keep="true">gZ</send>

      <send id="att_w" type="buffer" datatype="array" keep="true">attW</send>
      <send id="att_x" type="buffer" datatype="array" keep="true">attX</send>
      <send id="att_y" type="buffer" datatype="array" keep="true">attY</send>
      <send id="att_z" type="buffer" datatype="array" keep="true">attZ</send>

      <!-- GPS / Location -->
      <send id="gps_lat"   type="buffer" datatype="number">gpsLat</send>
      <send id="gps_lon"   type="buffer" datatype="number">gpsLon</send>
      <send id="gps_alt"   type="buffer" datatype="number">gpsAlt</send>
      <send id="gps_speed" type="buffer" datatype="number">gpsSpeed</send>
      <send id="gps_dir"   type="buffer" datatype="number">gpsDir</send>
      <send id="gps_acc"   type="buffer" datatype="number">gpsAcc</send>
    </connection>
  </network>

  <input>
  <!--The accelerometer in m/s². This gives the earth's acceleration when the device is resting. (Usually named "acceleration with g" in phyphox)-->
    <sensor type="accelerometer" rate="10">
      <output component="x">accX</output>
      <output component="y">accY</output>
      <output component="z">accZ</output>
    </sensor>
    <!-- A virtual sensor giving the actual acceleration of the device. Should report zero when the device is resting. (Usually named "acceleration (without g)" in phyphox) -->
    <sensor type="linear_acceleration" rate="10">
      <output component="x">laccX</output>
      <output component="y">laccY</output>
      <output component="z">laccZ</output>
    </sensor>

    <sensor type="gyroscope" rate="10">
      <output component="x">gyrX</output>
      <output component="y">gyrY</output>
      <output component="z">gyrZ</output>
    </sensor>

    <sensor type="magnetic_field" rate="10">
      <output component="x">magX</output>
      <output component="y">magY</output>
      <output component="z">magZ</output>
    </sensor>
    <!--A virtual sensor giving the gravitational acceleration in the frame of reference of the device. This removes the device motion from the accelerometer readings and should 
        therefore be approximately the difference of accelerometer and linear_acceleration. (Depending on the implementation on each device.)-->
    <sensor type="gravity" rate="10">
      <output component="x">gX</output>
      <output component="y">gY</output>
      <output component="z">gZ</output>
    </sensor>

    <!--The orientation (absolute rotation) of the device as calculated by the device's own algorithms. This uses TYPE_ROTATION_VECTOR on Android and "CMAttitude" from Core Motion on iOS,
        which (depending on the device) fuses data from the accelerometer, gyroscope and magnetometer to calculate the attitude of the device. 
        The result is given as a quaternion in a reference system with y pointing towards magnetic North and z pointing upwards (the Android coordinate system, iOS attitude is converted to this system). 
        The x, y and z channels correspond to the last three components of the quaternion (w, x, y, z) and w can be retrieved through the abs channel. Available since file format 1.9 (phyphox 1.1.5) -->
    <sensor type="attitude" rate="10">
      <output component="abs">attW</output>
      <output component="x">attX</output>
      <output component="y">attY</output>
      <output component="z">attZ</output>
    </sensor>

    <!-- Location components: lat, lon, z (alt), v (speed), dir (bearing), accuracy -->
    <location>
      <output component="lat">gpsLat</output>
      <output component="lon">gpsLon</output>
      <output component="z">gpsAlt</output>
      <output component="v">gpsSpeed</output>
      <output component="dir">gpsDir</output>
      <output component="accuracy">gpsAcc</output>
    </location>
  </input>

  <views>
    <view label="Live">
      <value label="acc x" size="2" precision="3" unit="m/s^2"><input>accX</input></value>
      <value label="acc y" size="2" precision="3" unit="m/s^2"><input>accY</input></value>
      <value label="acc z" size="2" precision="3" unit="m/s^2"><input>accZ</input></value>

      <value label="gyr x" size="2" precision="3" unit="rad/s"><input>gyrX</input></value>
      <value label="gyr y" size="2" precision="3" unit="rad/s"><input>gyrY</input></value>
      <value label="gyr z" size="2" precision="3" unit="rad/s"><input>gyrZ</input></value>

      <value label="mag x" size="2" precision="3" unit="uT"><input>magX</input></value>
      <value label="mag y" size="2" precision="3" unit="uT"><input>magY</input></value>
      <value label="mag z" size="2" precision="3" unit="uT"><input>magZ</input></value>

      <separator/>

      <value label="lat" size="2" precision="6" unit="deg"><input>gpsLat</input></value>
      <value label="lon" size="2" precision="6" unit="deg"><input>gpsLon</input></value>
      <value label="alt" size="2" precision="1" unit="m"><input>gpsAlt</input></value>
      <value label="speed" size="2" precision="2" unit="m/s"><input>gpsSpeed</input></value>
      <value label="dir" size="2" precision="0" unit="deg"><input>gpsDir</input></value>
      <value label="acc" size="2" precision="1" unit="m"><input>gpsAcc</input></value>
    </view>
  </views>
</phyphox>
