Clone
11
HomeAPI Setup
SocksOnHead edited this page 2025-08-02 14:52:07 +02:00

What is This?

You can think what we are about to configure in this tutorial is the server for giving the ESP32 the image data it needs to display it on the screen.

\color{Red}{\textsf{THIS API IS CURRENTLY BUILT FOR FETCHING SWEDISH PUBLIC TRANSPORT DATA}} \color{Red}{\textsf{YOU WILL HAVE TO DISABLE IT OR REPLACE IT IF YOU DON'T LIVE IN SWEDEN.}}

ADVANCED: Change Public Transport Api


Step 1: Download & Extract

  1. Download the zip file called HomeScreen_Build_vX.X.X.zip to your computer. Pick the newest version, you might have to expand Assets tab.
  2. Extract the zip file to a folder, e.g., C:\HomeApi or your Desktop.

Step 2: Configuring the API

When you have extracted the zip file there should be a appsettings.json file inside the folder. Open it and edit the lines I have marked.

Public API's that require keys:

{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://*:5000"
      }
    }
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ApiConfiguration": {
    "EspConfiguration": {
      "InformationBoardImageUrl": "http://192.168.101.178:5000/home/default.jpg", <--- Server Address (always use ip! This should always be the ip of the computer running this application)!
      "UpdateIntervalMinutes": 2,
      "BlackTextThreshold": 190,
      "EnableDithering": true,
      "DitheringStrength": 8,
      "EnhanceContrast": true,
      "ContrastStrength": 10,
      "IsHighContrastMode": true
    },
    "Keys": {
      "Weather": "NOT COMMITED", <---- WeatherApi key 
      "ResRobot": "NOT COMMITED" <---- Swedish transit api key
    },
    "BaseUrls": {
      "Nominatim": "https://nominatim.openstreetmap.org",
      "Aurora": "http://api.auroras.live",
      "Weather": "https://api.weatherapi.com/v1",
      "ResRobot": "https://api.resrobot.se"
    },
    "DefaultCity": "Stockholm, stockholms lan",
    "DefaultStation": "Stockholm C"
  },
  "AllowedHosts": "*"
}

Step 3: Install .NET 9 Runtime

You must install the .NET 9 Runtime to run this app.

1. Go to the official .NET download page:

2. Download the correct runtime:

  • Choose ".NET Runtime" (not SDK).
    • For Windows, select "x64" or "Arm64" depending on your machine.
    • For Mac/Linux, pick the right option for your OS.

3. Install:

  • Run the installer and follow the instructions.

Step 4: Verify .NET Installation

Open your Command Prompt (Windows) or Terminal (Mac/Linux) and run:

dotnet --version
  • If it prints something like 9.0.x, you are ready!

Step 6: Run the API

  1. Navigate to the extracted folder.

    • Example (Windows):
      cd C:\HomeApi\dotnet
      
    • Example (Mac/Linux):
      cd ~/Downloads/HomeApi/dotnet
      
  2. Run the API:

    dotnet HomeApi.dll
    
  3. You should see output like:

    Now listening on: http://localhost:5000
    Application started. Press Ctrl+C to shut down.
    

Step 6: Test the API


Stopping the API

  • Press Ctrl+C in the terminal window where the app is running.

FAQ

Q: I get 'dotnet is not recognized'?
The .NET runtime is not installed or not added to your PATH. Re-install it and reboot your computer.

Q: How do I change the port?
Open appsettings.json and look for URLs or configuration relating to ports. Edit as needed, or run with:

dotnet HomeApi.dll --urls "http://localhost:8080"

Q: Do I need Visual Studio?
No! You only need the .NET 9 Runtime.

Q: How do I call the API?
You can use a browser for GET endpoints or tools like Postman or curl for others.



Next Page: Setup ESP32