-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
923ea14
commit c5fb826
Showing
6 changed files
with
299 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.IO; | ||
using System.Text.Json; | ||
|
||
[ApiController] | ||
[Route("api/settings")] | ||
public class SettingsController : ControllerBase | ||
{ | ||
private const string SettingsFilePath = "settings.json"; | ||
|
||
[HttpGet] | ||
public ActionResult<Settings> GetSettings() | ||
{ | ||
if (!System.IO.File.Exists(SettingsFilePath)) | ||
{ | ||
return new Settings(); | ||
} | ||
|
||
var json = System.IO.File.ReadAllText(SettingsFilePath); | ||
return JsonSerializer.Deserialize<Settings>(json); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult SaveSettings([FromBody] Settings settings) | ||
{ | ||
var json = JsonSerializer.Serialize(settings); | ||
System.IO.File.WriteAllText(SettingsFilePath, json); | ||
return Ok(); | ||
} | ||
} | ||
|
||
public class Settings | ||
{ | ||
public Updating Updating { get; set; } | ||
public Scanning Scanning { get; set; } | ||
public Counting Counting { get; set; } | ||
public Filtering Filtering { get; set; } | ||
public Calibration Calibration { get; set; } | ||
} | ||
|
||
public class Updating | ||
{ | ||
public bool AutoUpdate { get; set; } | ||
public bool PreRelease { get; set; } | ||
} | ||
|
||
public class Scanning | ||
{ | ||
public int? ForgetAfterMs { get; set; } | ||
} | ||
|
||
public class Counting | ||
{ | ||
public string IdPrefixes { get; set; } | ||
public double? StartCountingDistance { get; set; } | ||
public double? StopCountingDistance { get; set; } | ||
public int? IncludeDevicesAge { get; set; } | ||
} | ||
|
||
public class Filtering | ||
{ | ||
public string IncludeIds { get; set; } | ||
public string ExcludeIds { get; set; } | ||
public double? MaxReportDistance { get; set; } | ||
public double? EarlyReportDistance { get; set; } | ||
public int? SkipReportAge { get; set; } | ||
} | ||
|
||
public class Calibration | ||
{ | ||
public int? RssiAt1m { get; set; } | ||
public int? RssiAdjustment { get; set; } | ||
public double? AbsorptionFactor { get; set; } | ||
public int? IBeaconRssiAt1m { get; set; } | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { settings } from '$lib/stores'; | ||
let loading = true; | ||
let error: string | null = null; | ||
onMount(async () => { | ||
try { | ||
await settings.load(); | ||
} catch (e) { | ||
error = e.message; | ||
} finally { | ||
loading = false; | ||
} | ||
}); | ||
async function handleUpdate() { | ||
try { | ||
await settings.save($settings); | ||
} catch (e) { | ||
error = `Error updating settings: ${e.message}`; | ||
} | ||
} | ||
</script> | ||
|
||
|
||
<h1 class="h1">Settings</h1> | ||
<div class="container mx-auto p-8"> | ||
<h2 class="text-1xl">Globally Set Node Settings</h2> | ||
<p>These settings will be set in every node, even new nodes.</p> | ||
{#if loading} | ||
<div class="card p-4 variant-filled-surface"> | ||
<div class="flex items-center space-x-4"> | ||
<span class="loading loading-spinner loading-lg" /> | ||
<p>Loading settings...</p> | ||
</div> | ||
</div> | ||
{:else if error} | ||
<div class="card p-4 variant-filled-error"> | ||
<p>Error: {error}</p> | ||
</div> | ||
{:else if $settings} | ||
<div class="card p-4 variant-filled-surface"> | ||
<section class="p-4"> | ||
<h3 class="h3 mb-4">Updating</h3> | ||
<label class="label"> | ||
<input type="checkbox" class="checkbox" bind:checked={$settings.updating.autoUpdate} /> | ||
<span>Automatically update</span> | ||
</label> | ||
<label class="label"> | ||
<input type="checkbox" class="checkbox" bind:checked={$settings.updating.preRelease} /> | ||
<span>Include pre-released versions in auto-update</span> | ||
</label> | ||
</section> | ||
|
||
<section class="mb-8"> | ||
<h2 class="text-2xl font-semibold mb-4">Scanning</h2> | ||
<div class="space-y-4 ml-4"> | ||
<label class="label"> | ||
<span>Forget beacon if not seen for (in milliseconds):</span> | ||
<input type="number" class="input" min="0" bind:value={$settings.scanning.forgetAfterMs} placeholder="150000" /> | ||
</label> | ||
</div> | ||
</section> | ||
|
||
<section class="mb-8"> | ||
<h2 class="text-2xl font-semibold mb-4">Counting</h2> | ||
<div class="space-y-4 ml-4"> | ||
<label class="label"> | ||
<span>Include id prefixes (space separated):</span> | ||
<input type="text" class="input" bind:value={$settings.counting.idPrefixes} placeholder="" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Start counting devices less than distance (in meters):</span> | ||
<input type="number" class="input" step="0.01" min="0" bind:value={$settings.counting.startCountingDistance} placeholder="2.00" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Stop counting devices greater than distance (in meters):</span> | ||
<input type="number" class="input" step="0.01" min="0" bind:value={$settings.counting.stopCountingDistance} placeholder="4.00" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Include devices with age less than (in ms):</span> | ||
<input type="number" class="input" min="0" bind:value={$settings.counting.includeDevicesAge} placeholder="30000" /> | ||
</label> | ||
</div> | ||
</section> | ||
|
||
<section class="mb-8"> | ||
<h2 class="text-2xl font-semibold mb-4">Filtering</h2> | ||
<div class="space-y-4 ml-4"> | ||
<label class="label"> | ||
<span>Include only sending these ids to mqtt (eg. apple:iphone10-6 apple:iphone13-2):</span> | ||
<input type="text" class="input" bind:value={$settings.filtering.includeIds} placeholder="" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Exclude sending these ids to mqtt (eg. exp:20 apple:iphone10-6):</span> | ||
<input type="text" class="input" bind:value={$settings.filtering.excludeIds} placeholder="" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Max report distance (in meters):</span> | ||
<input type="number" class="input" step="0.01" min="0" bind:value={$settings.filtering.maxReportDistance} placeholder="16.00" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Report early if beacon has moved more than this distance (in meters):</span> | ||
<input type="number" class="input" step="0.01" min="0" bind:value={$settings.filtering.earlyReportDistance} placeholder="0.50" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Skip reporting if message age is less that this (in milliseconds):</span> | ||
<input type="number" class="input" min="0" bind:value={$settings.filtering.skipReportAge} placeholder="5000" /> | ||
</label> | ||
</div> | ||
</section> | ||
|
||
<section class="mb-8"> | ||
<h2 class="text-2xl font-semibold mb-4">Calibration</h2> | ||
<div class="space-y-4 ml-4"> | ||
<label class="label"> | ||
<span>Rssi expected from a 0dBm transmitter at 1 meter (NOT used for iBeacons or Eddystone):</span> | ||
<input type="number" class="input" bind:value={$settings.calibration.rssiAt1m} placeholder="-65" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Rssi adjustment for receiver (use only if you know this device has a weak antenna):</span> | ||
<input type="number" class="input" bind:value={$settings.calibration.rssiAdjustment} placeholder="0" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Factor used to account for absorption, reflection, or diffraction:</span> | ||
<input type="number" class="input" step="0.01" min="0" bind:value={$settings.calibration.absorptionFactor} placeholder="3.50" /> | ||
</label> | ||
|
||
<label class="label"> | ||
<span>Rssi expected from this tx power at 1m (used for node iBeacon):</span> | ||
<input type="number" class="input" bind:value={$settings.calibration.iBeaconRssiAt1m} placeholder="-59" /> | ||
</label> | ||
</div> | ||
</section> | ||
|
||
<div class="flex justify-end mt-8"> | ||
<button class="btn variant-filled-secondary" on:click={handleUpdate}>Update</button> | ||
</div> | ||
</div> | ||
{:else} | ||
<div class="card p-4 variant-filled-warning"> | ||
<p>No settings available.</p> | ||
</div> | ||
{/if} | ||
</div> |