Use a Self-Signed SSL Certificate for Nginx Server

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt

Modify Your Nginx Server Block:

server {
    listen 443 ssl;
    server_name your_domain.com;

    ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

    location / {
        # Your proxy or root configurations
    }
}
sudo nginx -t
sudo systemctl reload nginx

 

Set Battery Charge Limit in Fedora

sudo nano /etc/systemd/system/battery-charge-threshold.service
[Unit]
Description=Set battery charge threshold to 60%
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now battery-charge-threshold.service

 

Disable systemd-networkd-wait-online.service in Ubuntu Server

In Ubuntu Server, the systemd-networkd-wait-online.service is responsible for waiting until the network is fully online before allowing the boot process to continue. This service can sometimes cause delays during the boot process if the network configuration takes a long time to initialize.

1. Disable the Service

To completely disable the systemd-networkd-wait-online.service, run the following command:

sudo systemctl disable systemd-networkd-wait-online.service

This will prevent the service from starting at boot time.

2. Mask the Service (Optional)

If you want to ensure that the service cannot be started manually or automatically by any other service, you can mask it:

sudo systemctl mask systemd-networkd-wait-online.service

Masking creates a symbolic link to /dev/null, making it impossible for the service to start unless explicitly unmasked.

Use an X.509 Certificate to encrypt the data protection keys in ASP.NET Blazor

In your Blazor application, modify the Program.cs file to configure data protection with certificate-based encryption.

using Microsoft.AspNetCore.DataProtection;
using System.Security.Cryptography.X509Certificates;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

// Configure Data Protection to use a certificate for key encryption
var certificate = X509CertificateLoader.LoadPkcs12FromFile("path_to_certificate.pfx", "password");
builder.Services.AddDataProtection()
    .ProtectKeysWithCertificate(certificate)
    .PersistKeysToFileSystem(new DirectoryInfo(keyFolderPath))
    .SetApplicationName("ERP");

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();

 

Install Syncthing on Ubuntu 24.04

# Add the release PGP keys:
sudo mkdir -p /etc/apt/keyrings
sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
# Add the "stable" channel to your APT sources:
echo "deb [signed-by=/etc/apt/keyrings/syncthing-archive-keyring.gpg] https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
# Update and install syncthing:
sudo apt-get update
sudo apt-get install syncthing

Syncthing can be run as a service so that it starts automatically on boot.

  1. Enable the Syncthing service : By default, Syncthing installs a systemd service for the user syncthing. You can enable it to start on boot.
    sudo systemctl enable syncthing@<username>.service

    Replace <username> with the username of the user who will run Syncthing. For example, if your username is ubuntu, the command would be:

    sudo systemctl enable syncthing@ubuntu.service
  2. Start the Syncthing service : Once enabled, start the Syncthing service.
    sudo systemctl start syncthing@<username>.service

By default, Syncthing runs on localhost and listens on port 8384.

References
https://apt.syncthing.net/

Tuning the Kp, Ki, and Kd parameters for a PID controller

Tuning the Kp (proportional gain), Ki (integral gain), and Kd (derivative gain) parameters is critical for a PID controller to achieve stable and responsive control. Here’s a structured approach to tuning:


1. Understand the Role of Each Term

Term Effect on System Impact of Increasing Gain
Kp Responds to current error (e.g., how far you are from the setpoint). Reduces steady-state error but can overshoot.
Ki Eliminates steady-state error by integrating past errors over time. Eliminates residual error but risks integral windup.
Kd Predicts future error based on the rate of change (slows rapid corrections). Reduces overshoot and oscillations but amplifies noise.

2. Manual Tuning Procedure (Trial and Error)

  1. Start with Kp, Ki=0, Kd=0:
    • Increase Kp until the system responds quickly but starts to oscillate.
    • If oscillations occur, reduce Kp by 50% and proceed.
  2. Introduce Ki (Integral):
    • Increase Ki slightly to eliminate steady-state error (e.g., a persistent offset).
    • Too much Ki causes overshoot or instability. If oscillations occur, reduce Ki.
  3. Add Kd (Derivative):
    • Increase Kd to dampen oscillations and reduce overshoot.
    • Excessive Kd can make the system sluggish or amplify sensor noise.

3. Ziegler-Nichols Tuning Method

A systematic way to find PID parameters using experiments:

Method 1: Closed-Loop (Ultimate Gain)

  1. Set Ki=0Kd=0.
  2. Increase Kp until the system oscillates consistently (ultimate gain Ku, oscillation period Pu).
  3. Use the table below to set gains:
Controller Kp Ki Kd
P-only 0.5 * Ku 0 0
PI 0.45 * Ku 1.2 * Kp / Pu 0
PID 0.6 * Ku 2 * Kp / Pu Kp * Pu / 8

Method 2: Open-Loop (Step Response)

  1. Apply a step input and measure the response.
  2. Identify delay time (L) and time constant (T) from the response curve.
  3. Use the table below (values vary by source):
Controller Kp Ki Kd
PI 0.9*T/L 0.3*Kp/L 0
PID 1.2*T/L 0.5*Kp/L 0.5KpL

4. Practical Tips

  1. Start Small:
    • Begin with conservative gains and increase gradually.
    • Use OutputMin/OutputMax to clamp the controller’s output during tuning.
  2. Anti-Windup:
    • Ensure your PID implementation includes anti-windup (already in your C# code) to prevent integral term saturation.
  3. Test with Simulations:
    • Use tools like MATLAB/Simulink or Python (scipy) to simulate the system before real-world testing.
  4. Log Data:
    • Plot the system response (error, output) to diagnose overshoot, oscillations, or slow convergence.
  5. Iterate:
    • Tuning is iterative. Adjust one parameter at a time and observe the effect.

5. Example Tuning Workflow

  1. Step 1: Set Kp=1Ki=0Kd=0.
  2. Step 2: Increase Kp until the system oscillates (e.g., Kp=5 causes oscillations).
  3. Step 3: Reduce Kp by 50% (Kp=2.5) to stabilize.
  4. Step 4: Add Ki=0.1 to eliminate steady-state error. If overshoot occurs, reduce Ki.
  5. Step 5: Add Kd=0.05 to dampen oscillations. Adjust further if needed.

6. Advanced Methods

  • Auto-Tuning: Use libraries or tools (e.g., PID AutoTuner) to automate the process.
  • Software Tools: MATLAB’s PID Tuner or Python’s control library can optimize gains mathematically.
  • Model Predictive Control (MPC): For complex systems, use MPC to handle constraints and nonlinearities.

Key Takeaway

Tuning is highly system-dependent. Always prioritize stability over speed, and validate gains in real-world conditions.