# Signals

## Data format

Signal data must be in the following JSON format:

<pre class="language-json"><code class="lang-json">{
    "now": long,
    "signals": [
        {
            "uuid": quoted string,
            "freq": int,
<strong>            "rssi_f": int,
</strong><strong>            "rssi_r": int,
</strong>            "name": quoted string,
            "desc": quoted string
        },
        ...
    ]
}
</code></pre>

### Definitions

#### Main object

<mark style="color:yellow;">**"now"**</mark>*<mark style="color:yellow;">**:**</mark>*  a UNIX epoch timestamp in either seconds or milliseconds.  It's important that this timestamp is updated whenever the signals.json file is updated, so that JBV1 can know when it has been updated.  Accuracy of the timestamp is unimportant.

<mark style="color:yellow;">**"signals":**</mark>  an array of zero or more signal objects.

#### Signal object

<mark style="color:yellow;">**"uuid":**</mark>  a quoted string that uniquely identifies the signal.

<mark style="color:yellow;">**"freq":**</mark>  an integer representing the signal frequency in MHz.  For example, a 35.500 GHz signal would be represented as 35500, while an 800 MHz signal would be represented as 800.

<mark style="color:yellow;">**"rssi\_f":**</mark>  the front signal strength in dBm, represented as a single negative integer when there is a front signal strength.  Set to 0 when there is a rear signal strength (<mark style="color:yellow;">**rssi\_r**</mark>) but no front signal strength.

<mark style="color:yellow;">**"rssi\_r":**</mark>  the rear signal strength in dBm, represented as a single negative integer when there is a rear signal strength.  Set to 0 when there is no rear signal strength.  If your signals do not have front and/or rear orientations, use <mark style="color:yellow;">**rssi\_f**</mark> for signal strength and either omit <mark style="color:yellow;">**rssi\_r**</mark> or set it to 0 for all signals.

<mark style="color:yellow;">**"name":**</mark>  an optional quoted string that names the signal.  If provided, JBV1 can use this name for filtering.

<mark style="color:yellow;">**"desc":**</mark>  an optional quoted string that describes the signal.  If provided, JBV1 can use this description for filtering.

## Location

Signal data must be written to the following path on your carputer:

```
/run/lighttpd/signals.json
```

Lighttpd must be installed on your carputer so that JBV1 can access your signals data.  If you have already installed PiAware for ADS-B, then lighttpd is already installed.

A bit of lighttpd configuration is required so that your signals data is available to JBV1 via the following URL:

```
http://<carputer ip address>/jbv1/signals.json
```

To configure lighttpd on your carputer:

```bash
sudo su # this switches you to a root user shell, so be careful what you type after this, until you exit
cd /etc/lighttpd/conf-available
rw # only if you see "(ro)" in your prompt
```

Now use a text editor that you're comfortable with to create and edit a file named <mark style="color:yellow;">**81-jbv1.conf**</mark> in the current directory (<mark style="color:yellow;">/etc/lighttpd/conf-available</mark>).

In this file, paste the following:

```bash
# Allows access to the dynamically-generated json files that contain various
# data periodically written by JBV1 carputer services.

alias.url += (
  "/jbv1/" => "/run/lighttpd/",
)

# redirect the slash-less URL
url.redirect += (
  "^/jbv1$" => "/jbv1/"
)

# Add CORS header
server.modules += ( "mod_setenv" )
$HTTP["url"] =~ "^/jbv1/.*\.json$" {
  setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
}
```

Save the file, exit the text editor, and then:

```bash
cd ../conf-enabled
ln -s ../conf-available/81-jbv1.conf .
ro # only if you see "(rw)" in your prompt
systemctl restart lighttpd
exit # this exits out of your root user shell and returns you to a pi user shell
```

When you have a process writing signal data to <mark style="color:yellow;">/run/lighttpd/signals.json</mark>, you can confirm your lighttpd changes worked by visiting this URL from a computer on the same network as your carputer:

```
http://<carputer ip address>/jbv1/signals.json
```
