Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Docs/Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ WiFi commands return JSON (`{"success":true}` or `{"success":false,"message":"
| `R8` — Set Default State | `R8:3=1` | Power-on default state for relay `idx`: `0`=off, `1`=on. |
| `R9` — Link Relays | `R9:3=4` (link) — `R9:3=255` (unlink) | Link two relays so toggling one toggles the other. `255` to unlink. |
| `R10` — Set Action Type | `R10:2=0` / `R10:2=1` / `R10:2=2` | Set relay action type: `0`=Default, `1`=Horn (activates sound system), `2`=NightRelay (activates at night per light sensor). Only one relay per type at a time. |
| `R11` — Set Pin | `R11:2=15` | Set GPIO pin for relay `idx`. Must be a valid non-zero pin number. |
| `R11` — Set Pin | `R11:2=15` | Set GPIO pin for relay `idx`. Must be a valid non-zero pin number or 255 to disable |

### WiFi relay commands
Route: `/api/relay/{command}`
Expand Down
62 changes: 32 additions & 30 deletions PowerControlHub/ConfigNetworkHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,11 +1027,12 @@ void ConfigNetworkHandler::formatStatusJson(IWifiClient* client)

client->print("\"config\":{");

// Name
// C3 Name
client->print("\"name\":\"");
client->print(config->location.name);
client->print("\",");

// C4 Spi Pins
client->print("\"spiPins\":{");
client->print("\"sck\":");
client->print(config->spiPins.sckPin);
Expand All @@ -1043,22 +1044,22 @@ void ConfigNetworkHandler::formatStatusJson(IWifiClient* client)
client->print(config->spiPins.misoPin);
client->print("},");

// Vessel type
client->print("\"vesselType\":");
client->print(static_cast<uint8_t>(config->location.locationType));
// C6 Xpdz Tone
client->print("\"xpdzPin\":");
client->print(static_cast<uint8_t>(config->xpdzTone.pin));
client->print(",");

// Sound relay ID
client->print("\"hornRelayIndex\":");
client->print(static_cast<uint8_t>(config->sound.hornRelayIndex));
// C7 Location type
client->print("\"locationType\":");
client->print(static_cast<uint8_t>(config->location.locationType));
client->print(",");

// Sound start delay
// C9 Sound start delay
client->print("\"soundStartDelayMs\":");
client->print(static_cast<uint16_t>(config->sound.startDelayMs));
client->print(",");

// Bluetooth, WiFi, SSID, Password, Port, AccessMode
// C10 - C17 Bluetooth, WiFi, SSID, Password, Port, AccessMode
client->print("\"bluetoothEnabled\":");
client->print(config->network.bluetoothEnabled ? "true" : "false");
client->print(",");
Expand Down Expand Up @@ -1110,6 +1111,26 @@ void ConfigNetworkHandler::formatStatusJson(IWifiClient* client)

client->print("\",");

// C18 RTC DS1302 pins
client->print("\"rtcPins\":{");
client->print("\"dat\":");
client->print(config->rtc.dataPin);
client->print(",\"clk\":");
client->print(config->rtc.clockPin);
client->print(",\"rst\":");
client->print(config->rtc.resetPin);
client->print("},");

// C19 Network auth
client->print("\"auth\":{");
client->print("\"enabled\":");
client->print(config->auth.enabled ? "true" : "false");
client->print(",\"apiKey\":\"");
client->print(config->auth.apiKey);
client->print("\",\"hmacKey\":\"");
client->print(config->auth.hmacKey);
client->print("\"},");

// C20 Timezone offset
client->print("\"timezoneOffset\":");
client->print(static_cast<int>(config->system.timezoneOffset));
Expand Down Expand Up @@ -1206,6 +1227,8 @@ void ConfigNetworkHandler::formatStatusJson(IWifiClient* client)
client->print(config->sound.badRepeatMs);
client->print("},");

// C29, C30 Serial only

// C31 SD Card Initialize Speed
client->print("\"sdCardInitializeSpeed\":");
client->print(config->sdCard.initializeSpeed);
Expand All @@ -1214,27 +1237,6 @@ void ConfigNetworkHandler::formatStatusJson(IWifiClient* client)
// C32 SD Card CS pin
client->print("\"sdCardCsPin\":");
client->print(config->sdCard.csPin);
client->print(",");

// C18 RTC DS1302 pins
client->print("\"rtcPins\":{");
client->print("\"dat\":");
client->print(config->rtc.dataPin);
client->print(",\"clk\":");
client->print(config->rtc.clockPin);
client->print(",\"rst\":");
client->print(config->rtc.resetPin);
client->print("},");

// C19 Network auth
client->print("\"auth\":{");
client->print("\"enabled\":");
client->print(config->auth.enabled ? "true" : "false");
client->print(",\"apiKey\":\"");
client->print(config->auth.apiKey);
client->print("\",\"hmacKey\":\"");
client->print(config->auth.hmacKey);
client->print("\"}");

client->print("}");
}
Expand Down
4 changes: 4 additions & 0 deletions PowerControlHub/RelayNetworkHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,23 @@ void RelayNetworkHandler::formatWifiStatusJson(IWifiClient* client)
if (config != nullptr)
{
client->print(",\"homeMap\":[");

for (uint8_t i = 0; i < ConfigHomeButtons; i++)
{
if (i > 0)
client->print(",");
client->print(config->relay.homePageMapping[i]);
}

client->print("]");

client->print(",\"linked\":[");

for (uint8_t i = 0; i < ConfigMaxLinkedRelays; i++)
{
if (i > 0)
client->print(",");

client->print("[");
client->print(config->relay.linkedRelays[i][0]);
client->print(",");
Expand Down
1 change: 1 addition & 0 deletions PowerControlHubApp/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public AppShell()
Routing.RegisterRoute(nameof(RtcSettingsPage), typeof(RtcSettingsPage));
Routing.RegisterRoute(nameof(NetworkSecurityPage), typeof(NetworkSecurityPage));
Routing.RegisterRoute(nameof(NextionSettingsPage), typeof(NextionSettingsPage));
Routing.RegisterRoute(nameof(XpdzToneSettingsPage), typeof(XpdzToneSettingsPage));
}
}
}
7 changes: 7 additions & 0 deletions PowerControlHubApp/Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ internal static class Constants
public const string JsonRtcClockPin = "clk";
public const string JsonRtcResetPin = "rst";
public const int RtcPinDisabled = 255;
// XpdzTone / Buzzer config
public const string RouteConfigXpdzTone = "api/config/C6";
public const string RouteXpdzToneSettingsPage = "XpdzToneSettingsPage";
public const string XpdzToneMsgSaveFailed = "Save failed — device unreachable";
public const string XpdzToneMsgSaved = "Buzzer settings saved";
public const string XpdzToneMsgRefreshed = "Refreshed";
public const string JsonXpdzPin = "xpdzPin";
// Nextion display config
public const string RouteConfigNextionGet = "api/config/N0";
public const string RouteConfigNextionSetFormat = "api/config/N{0}?v={1}";
Expand Down
2 changes: 2 additions & 0 deletions PowerControlHubApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddTransient<RtcSettingsViewModel>();
builder.Services.AddTransient<NetworkSecurityViewModel>();
builder.Services.AddTransient<NextionSettingsViewModel>();
builder.Services.AddTransient<XpdzToneSettingsViewModel>();

// Pages
builder.Services.AddSingleton<DashboardPage>();
Expand All @@ -128,6 +129,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddTransient<RtcSettingsPage>();
builder.Services.AddTransient<NetworkSecurityPage>();
builder.Services.AddTransient<NextionSettingsPage>();
builder.Services.AddTransient<XpdzToneSettingsPage>();

#if DEBUG
builder.Logging.AddDebug();
Expand Down
3 changes: 3 additions & 0 deletions PowerControlHubApp/Models/Json/ConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@ public sealed class ConfigModel

[JsonPropertyName("rtcPins")]
public RtcConfigModel Rtc { get; set; }

[JsonPropertyName("xpdzPin")]
public int XpdzTonePin { get; set; }
}
}
3 changes: 3 additions & 0 deletions PowerControlHubApp/PowerControlHubApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@
<MauiXaml Update="Views\TopBarView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\XpdzToneSettingsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions PowerControlHubApp/Services/ConfigConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ public async Task<bool> SetRtcPinsAsync(int dataPin, int clockPin, int resetPin,
}
}

public async Task<bool> SetXpdzTonePinAsync(int pin, CancellationToken ct = default)
{
try
{
string url = $"{RouteConfigXpdzTone}?v={pin}";
HttpResponseMessage response = await _client.PostAsync(url, null, ct);
return response.IsSuccessStatusCode;
}
catch
{
return false;
}
}

public async Task<AuthConfigModel> GetAuthConfigAsync(CancellationToken ct = default)
{
try
Expand Down
8 changes: 8 additions & 0 deletions PowerControlHubApp/Services/ConfigPoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ private async Task RunLoopAsync(CancellationToken stoppingToken)

public Task<bool> SetRtcPinsAsync(int dataPin, int clockPin, int resetPin, CancellationToken ct = default) => _connection.SetRtcPinsAsync(dataPin, clockPin, resetPin, ct);

public Task<bool> SetXpdzTonePinAsync(int pin, CancellationToken ct = default) => _connection.SetXpdzTonePinAsync(pin, ct);

public Task<AuthConfigModel> GetAuthConfigAsync(CancellationToken ct = default) => _connection.GetAuthConfigAsync(ct);

public Task<bool> SetAuthEnabledAsync(bool enabled, CancellationToken ct = default) => _connection.SetAuthEnabledAsync(enabled, ct);
Expand All @@ -240,11 +242,17 @@ private async Task RunLoopAsync(CancellationToken stoppingToken)
public Task<bool> GenerateAuthKeysAsync(CancellationToken ct = default) => _connection.GenerateAuthKeysAsync(ct);

public Task<NextionConfigModel> GetNextionConfigAsync(CancellationToken ct = default) => _connection.GetNextionConfigAsync(ct);

public Task<bool> SetNextionEnabledAsync(bool enabled, CancellationToken ct = default) => _connection.SetNextionEnabledAsync(enabled, ct);

public Task<bool> SetNextionHardwareSerialAsync(bool hardwareSerial, CancellationToken ct = default) => _connection.SetNextionHardwareSerialAsync(hardwareSerial, ct);

public Task<bool> SetNextionRxPinAsync(int pin, CancellationToken ct = default) => _connection.SetNextionRxPinAsync(pin, ct);

public Task<bool> SetNextionTxPinAsync(int pin, CancellationToken ct = default) => _connection.SetNextionTxPinAsync(pin, ct);

public Task<bool> SetNextionBaudRateAsync(int baudRate, CancellationToken ct = default) => _connection.SetNextionBaudRateAsync(baudRate, ct);

public Task<bool> SetNextionUartNumberAsync(int uartNumber, CancellationToken ct = default) => _connection.SetNextionUartNumberAsync(uartNumber, ct);

public void Dispose()
Expand Down
1 change: 1 addition & 0 deletions PowerControlHubApp/Services/IConfigConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public interface IConfigConnection
Task<bool> SetSdCardCsPinAsync(int pin, CancellationToken ct = default);
Task<(int DataPin, int ClockPin, int ResetPin)?> GetRtcPinsAsync(CancellationToken ct = default);
Task<bool> SetRtcPinsAsync(int dataPin, int clockPin, int resetPin, CancellationToken ct = default);
Task<bool> SetXpdzTonePinAsync(int pin, CancellationToken ct = default);
Task<AuthConfigModel> GetAuthConfigAsync(CancellationToken ct = default);
Task<bool> SetAuthEnabledAsync(bool enabled, CancellationToken ct = default);
Task<bool> SetAuthApiKeyAsync(string apiKey, CancellationToken ct = default);
Expand Down
5 changes: 5 additions & 0 deletions PowerControlHubApp/Services/PowerHubService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ public Task<bool> SetRtcPinsAsync(int dataPin, int clockPin, int resetPin, Cance
return _configConnection.SetRtcPinsAsync(dataPin, clockPin, resetPin, ct);
}

public Task<bool> SetXpdzTonePinAsync(int pin, CancellationToken ct = default)
{
return _configConnection.SetXpdzTonePinAsync(pin, ct);
}

public Task<bool> SetAuthEnabledAsync(bool enabled, CancellationToken ct = default)
{
return _configConnection.SetAuthEnabledAsync(enabled, ct);
Expand Down
3 changes: 3 additions & 0 deletions PowerControlHubApp/ViewModels/SystemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public bool HasPinRestrictions

public ICommand NavigateToNextionSettingsCommand { get; }

public ICommand NavigateToXpdzToneSettingsCommand { get; }

public SystemViewModel(PowerHubService service, LogService log)
: base(service, log)
{
Expand All @@ -127,6 +129,7 @@ public SystemViewModel(PowerHubService service, LogService log)
NavigateToRtcSettingsCommand = new Command(async () => await Shell.Current.GoToAsync(RouteRtcSettingsPage));
NavigateToNetworkSecurityCommand = new Command(async () => await Shell.Current.GoToAsync(RouteNetworkSecurityPage));
NavigateToNextionSettingsCommand = new Command(async () => await Shell.Current.GoToAsync(RouteNextionSettingsPage));
NavigateToXpdzToneSettingsCommand = new Command(async () => await Shell.Current.GoToAsync(RouteXpdzToneSettingsPage));
}

protected override void OnDataFetched(IndexModel index)
Expand Down
Loading
Loading