<phyphox xmlns="https://phyphox.org/xml" version="1.18">
  <title>Kens 250207 GPS</title>
  <category>Kens Beta</category>
  <color>224f77</color>
  <description>
        Get raw position data from satellite navigation.

        Note that the available data may depend on the implementation on your smartphone. Some devices may not provide vertical accuracy or the number of satellites.

        Also, by default there is location information from other typically less accurate sources (like wifi or mobile data networks) mixed into the data from satellite navigation. Again, depending on your device, you may be able to disable these sources from the experiment menu by enabling the setting to only collect data from satellite navigation.

        Speed and direction are typically given by the device and are based on two or more consecutive position fixes.
    
  </description>
  <data-containers>
    <container size="0">lat</container>
    <container size="0">lon</container>
    <container size="0">z</container>
    <container size="0">zwgs84</container>
    <container size="0">v</container>
    <container size="0">dir</container>
    <container size="0">accuracy</container>
    <container size="0">zAccuracy</container>
    <container size="0">t</container>
    <container>status</container>
    <container size="0">satellites</container>
    <container init="0">countT</container>
    <container size="0">d</container>
    <container size="0">dist</container>
    <container size="0">dnew</container>
    <container init="0">countUpdated</container>
    <container init="1">countUpdated+1</container>
    <container size="0">subLat</container>
    <container size="0">subLon</container>
    <container size="0">dLat</container>
    <container size="0">dLon</container>
    <container>startLat</container>
    <container>startLon</container>
    <container>diststart</container>
  </data-containers>
  <input>
    <location>
      <output component="lat">lat</output>
      <output component="lon">lon</output>
      <output component="z">z</output>
      <output component="zwgs84">zwgs84</output>
      <output component="v">v</output>
      <output component="dir">dir</output>
      <output component="accuracy">accuracy</output>
      <output component="zAccuracy">zAccuracy</output>
      <output component="t">t</output>
      <output component="satellites">satellites</output>
      <output component="status">status</output>
    </location>
  </input>
  <analysis sleep="0.1">
    <count>
      <input as="buffer" keep="true">t</input>
      <output append="true">countT</output>
    </count>
    <count>
      <input as="buffer" keep="true">d</input>
      <output>countUpdated</output>
    </count>
    <add>
      <input keep="true">countUpdated</input>
      <input type="value">1</input>
      <output>countUpdated+1</output>
    </add>
    <subrange>
      <input as="from" keep="true">countUpdated</input>
      <input as="in" keep="true">lat</input>
      <output as="out">subLat</output>
    </subrange>
    <subrange>
      <input as="from" keep="true">countUpdated</input>
      <input as="in" keep="true">lon</input>
      <output as="out">subLon</output>
    </subrange>
    <differentiate>
      <input as="in" keep="true">subLat</input>
      <output>dLat</output>
    </differentiate>
    <differentiate>
      <input as="in" keep="true">subLon</input>
      <output>dLon</output>
    </differentiate>
    <formula formula="0.01745329252*sqrt((cos(0.01745329252*[1_])*[3_])^2+[2_]*[2_])*6371">
      <input keep="true">subLat</input>
      <input>dLat</input>
      <input>dLon</input>
      <output>dnew</output>
    </formula>
    <if greater="true">
      <input as="a" keep="true">countT</input>
      <input as="b" keep="true">countUpdated+1</input>
      <input as="true" keep="true">dnew</input>
      <output append="true">d</output>
    </if>
    <integrate>
      <input as="in" keep="true">d</input>
      <output>dist</output>
    </integrate>
    <first>
      <input as="value" keep="true">lon</input>
      <output as="first">startLon</output>
    </first>
    <first>
      <input as="value" keep="true">lat</input>
      <output as="first">startLat</output>
    </first>
    <formula formula="6371*acos(sin(0.01745329252*[1])*sin(0.01745329252*[3])+cos(0.01745329252*[1])*cos(0.01745329252*[3])*cos(0.01745329252*([2]-[4])))">
      <input>startLat</input>
      <input>startLon</input>
      <input keep="true">lat</input>
      <input keep="true">lon</input>
      <output>diststart</output>
    </formula>
    
  </analysis>
  <views>
    <view label="Position">
      <value label="Status">
        <input>status</input>
        <map max="-1">GPS disabled</map>
        <map min="0">GPS active</map>
      </value>
      <separator height="1"></separator>
      <graph label="Latitude" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="[[quantity_short_latitude]]" unitX="[[unit_short_second]]" unitY="[[unit_short_degree]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">lat</input>
      </graph>
      <graph label="Longitude" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="[[quantity_short_longitude]]" unitX="[[unit_short_second]]" unitY="[[unit_short_degree]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">lon</input>
      </graph>
      <graph label="Altitude" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="[[quantity_short_altitude]]" unitX="[[unit_short_second]]" unitY="[[unit_short_meter]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">z</input>
      </graph>
    </view>
    <view label="Movement">
      <value label="Status">
        <input>status</input>
        <map max="-1">GPS disabled</map>
        <map min="0">GPS active</map>
      </value>
      <separator height="1"></separator>
      <graph label="Speed" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="[[quantity_short_velocity]]" unitX="[[unit_short_second]]" unitY="[[unit_short_meter_per_second]]" unitYperX="[[unit_short_meter_per_square_second]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">v</input>
      </graph>
      <graph label="Direction" style="dots" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="Direction" unitX="[[unit_short_second]]" unitY="[[unit_short_degree]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">dir</input>
      </graph>
      <graph label="Distance travelled" partialUpdate="true" labelX="[[quantity_short_time]]" labelY="[[quantity_short_distance]]" unitX="[[unit_short_second]]" unitY="[[unit_short_kilo_meter]]" timeOnX="true">
        <input axis="x">t</input>
        <input axis="y">dist</input>
      </graph>
    </view>
    <view label="Simple">
      <value label="Status">
        <input>status</input>
        <map max="-1">GPS disabled</map>
        <map min="0">GPS active</map>
      </value>
      <separator height="1"></separator>
      <value precision="6" unit="[[unit_short_degree]]" label="Latitude">
        <input>lat</input>
      </value>
      <value precision="6" unit="[[unit_short_degree]]" label="Longitude">
        <input>lon</input>
      </value>
      <value precision="1" unit="[[unit_short_meter]]" label="Altitude">
        <input>z</input>
      </value>
      <value precision="1" unit="m (WGS84)" label="Altitude">
        <input>zwgs84</input>
      </value>
      <separator height="1"></separator>
      <value precision="1" unit="[[unit_short_meter_per_second]]" label="Speed">
        <input>v</input>
      </value>
      <value precision="1" unit="[[unit_short_kilo_meter_per_hour]]" factor="3.6" label="Speed">
        <input>v</input>
      </value>
      <separator height="1"></separator>
      <value precision="1" unit="[[unit_short_degree]]" label="Direction">
        <input>dir</input>
      </value>
      <value label="Compass">
        <input>dir</input>
        <map max="-157.5">[[direction_short_south]]</map>
        <map max="-112.5">[[direction_short_south_west]]</map>
        <map max="-67.5">[[direction_short_west]]</map>
        <map max="-22.5">[[direction_short_north_west]]</map>
        <map max="22.5">[[direction_short_north]]</map>
        <map max="67.5">[[direction_short_north_east]]</map>
        <map max="112.5">[[direction_short_east]]</map>
        <map max="157.5">[[direction_short_south_east]]</map>
        <map max="202.5">[[direction_short_south]]</map>
        <map max="247.5">[[direction_short_south_west]]</map>
        <map max="292.5">[[direction_short_west]]</map>
        <map max="337.5">[[direction_short_north_west]]</map>
        <map>[[direction_short_north]]</map>
      </value>
      <separator height="1"></separator>
      <value precision="3" unit="[[unit_short_kilo_meter]]" label="Distance travelled">
        <input>dist</input>
      </value>
      <value precision="3" unit="[[unit_short_kilo_meter]]" label="Distance from start">
        <input>diststart</input>
      </value>
      <separator height="1"></separator>
      <value precision="1" unit="[[unit_short_meter]]" label="Horizontal Accuracy">
        <input>accuracy</input>
      </value>
      <value precision="1" unit="[[unit_short_meter]]" label="Vertical Accuracy">
        <input>zAccuracy</input>
      </value>
      <value precision="0" label="Satellites">
        <input>satellites</input>
        <map max="-1">unknown</map>
      </value>
      <separator height="1"></separator>
      <info label="Note, that some devices do not have a GPS sensor, but provide location data through mobile or WIFI connections. These data sources produce data with bad accuracy."></info>
      <separator height="1"></separator>
      <info label="Also make sure that your system's location setting is not set to &quot;Power saving&quot; because this usually turns off the precise GPS source."></info>
      <separator height="1"></separator>
      <info label="The horizontal accuracy is the uncertainty of your location, while the vertical accuracy is the (usually worse) uncertainty of your altitude. If the accuracy is zero, this information is not available."></info>
    </view>
  </views>
  <export>
    <set name="Raw Data">
      <data name="Time (s)">t</data>
      <data name="Latitude (°)">lat</data>
      <data name="Longitude (°)">lon</data>
      <data name="Altitude (m)">z</data>
      <data name="Altitude WGS84 (m)">zwgs84</data>
      <data name="Speed (m/s)">v</data>
      <data name="Direction (°)">dir</data>
      <data name="Distance (km)">dist</data>
      <data name="Horizontal Accuracy (m)">accuracy</data>
      <data name="Vertical Accuracy (m)">zAccuracy</data>
      <data name="Satellites">satellites</data>
    </set>
  </export>
<network>
  <connection id="gps_stream" service="http/post" address="http:--.--.1.--/sensor-data" interval="1">
    <send id="gps_latitude" type="buffer" datatype="number" keep="false">lat</send>
    <send id="gps_longitude" type="buffer" datatype="number" keep="false">lon</send>
    <send id="gps_longitude" type="buffer" datatype="number" keep="false">z</send>
  </connection>
</network>
</phyphox>