Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d5b893948 | ||
|
|
4a73099460 | ||
|
|
addc90d856 | ||
|
|
d23be3062a | ||
|
|
740b654be6 | ||
|
|
dcc3cfa44f | ||
|
|
ae7b2f170a | ||
|
|
fad4da3f6b | ||
|
|
76cca9c1c0 |
@@ -1,3 +1,4 @@
|
|||||||
result
|
result
|
||||||
vrnp
|
vrnp
|
||||||
|
main
|
||||||
*.swp
|
*.swp
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
@@ -81,3 +81,17 @@ static const uint8_t PROGMEM spinny[][8] = {
|
|||||||
0x00,
|
0x00,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
static const uint16_t PROGMEM tiny_train_dims[] = {24, 9, 1};
|
||||||
|
static const uint8_t PROGMEM tiny_train[][27] = {
|
||||||
|
{
|
||||||
|
0x00, 0x04, 0x00,
|
||||||
|
0x00, 0x02, 0x00,
|
||||||
|
0x01, 0xff, 0xfe,
|
||||||
|
0x00, 0xa4, 0x94,
|
||||||
|
0x01, 0x24, 0x92,
|
||||||
|
0x01, 0x24, 0x92,
|
||||||
|
0x03, 0xfc, 0xff,
|
||||||
|
0x03, 0xff, 0xff,
|
||||||
|
0x01, 0xb0, 0x36,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
+13
-11
@@ -102,20 +102,17 @@ void setup() {
|
|||||||
|
|
||||||
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
pinMode(BUTTON_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(BUTTON_PIN, onButtonFalling, FALLING);
|
attachInterrupt(BUTTON_PIN, onButtonFalling, FALLING);
|
||||||
/*
|
|
||||||
display.print(" 5 Mannheim sofort\n"
|
|
||||||
"26 Kirchheim 9 min\n"
|
|
||||||
" 5 Weinheim 20:13");
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define QUERY_STRING "stop_id=de:08221:1225&platform=A"
|
||||||
|
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
String fetchDepartures() {
|
String fetchDepartures() {
|
||||||
std::unique_ptr<BearSSL::WiFiClientSecure> https(new BearSSL::WiFiClientSecure);
|
std::unique_ptr<BearSSL::WiFiClientSecure> https(new BearSSL::WiFiClientSecure);
|
||||||
https->setInsecure();
|
https->setInsecure();
|
||||||
|
|
||||||
HTTPClient client;
|
HTTPClient client;
|
||||||
if (!client.begin(*https, "vrnp.beany.club", 443, "/departures?stop_id=de:08221:1225&platform=A")) {
|
if (!client.begin(*https, "vrnp.beany.club", 443, "/departures?" QUERY_STRING)) {
|
||||||
display.fillScreen(COLOR_BG);
|
display.fillScreen(COLOR_BG);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("begin failed");
|
display.print("begin failed");
|
||||||
@@ -179,14 +176,19 @@ void logic_loop() {
|
|||||||
|
|
||||||
int line = 0;
|
int line = 0;
|
||||||
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
||||||
const char *directionStr = departure["direction"].as<const char *>();
|
|
||||||
|
|
||||||
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
||||||
display.printf("%2s %-15.15s %6s",
|
display.printf("%2s %-15.15s ",
|
||||||
departure["symbol"].as<const char*>(),
|
departure["symbol"].as<const char*>(),
|
||||||
directionStr,
|
departure["direction"].as<const char *>()
|
||||||
departure["leaving"].as<const char*>()
|
|
||||||
);
|
);
|
||||||
|
if (departure["leaving"].as<String>().equals("sofort")) {
|
||||||
|
int16_t x = display.getCursorX();
|
||||||
|
int16_t y = display.getCursorY();
|
||||||
|
display.drawBitmap(x + 6 * CX - tiny_train_dims[0], y, tiny_train[0], tiny_train_dims[0], tiny_train_dims[1], COLOR_TEXT);
|
||||||
|
} else {
|
||||||
|
display.printf("%6s", departure["leaving"].as<const char*>());
|
||||||
|
}
|
||||||
|
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,3 +43,4 @@ def generate_bitmap_from_gif(file: Path, fd):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
generate_bitmap_from_gif(Path("./animations/spinny.gif"), sys.stdout)
|
generate_bitmap_from_gif(Path("./animations/spinny.gif"), sys.stdout)
|
||||||
|
generate_bitmap_from_gif(Path("./animations/tiny_train.gif"), sys.stdout)
|
||||||
|
|||||||
Generated
+34
@@ -1,5 +1,23 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"gitignore": {
|
"gitignore": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
@@ -38,9 +56,25 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"gitignore": "gitignore",
|
"gitignore": "gitignore",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
@@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
gitignore = {
|
gitignore = {
|
||||||
url = "github:hercules-ci/gitignore.nix";
|
url = "github:hercules-ci/gitignore.nix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, gitignore }:
|
outputs = { self, nixpkgs, flake-utils, gitignore }: flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
pkgs = import nixpkgs { inherit system; };
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
|
||||||
|
|
||||||
vrnp-static = pkgs.buildGoModule {
|
vrnp-static = pkgs.buildGoModule {
|
||||||
pname = "vrnp";
|
pname = "vrnp";
|
||||||
version = "0.0.5";
|
version = "0.0.7";
|
||||||
vendorHash = null;
|
vendorHash = null;
|
||||||
|
|
||||||
# For building the package, we use only the files not ignored by Git as inputs.
|
# For building the package, we use only the files not ignored by Git as inputs.
|
||||||
@@ -31,15 +31,15 @@
|
|||||||
CGO_ENABLED = 0;
|
CGO_ENABLED = 0;
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
devShell.${system} = pkgs.mkShellNoCC {
|
devShell = pkgs.mkShell {
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.go
|
pkgs.go
|
||||||
(pkgs.python3.withPackages (ps: with ps; [ pillow ]))
|
(pkgs.python3.withPackages (ps: with ps; [ pillow ]))
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
packages.${system} = {
|
packages = {
|
||||||
default = vrnp-static;
|
default = vrnp-static;
|
||||||
image-meta = pkgs.runCommand "vrnp-version" {} ''
|
image-meta = pkgs.runCommand "image-meta" {} ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
echo -n ${vrnp-static.version} > $out/version
|
echo -n ${vrnp-static.version} > $out/version
|
||||||
echo -n git.pbrinkmeier.de/paul/vrnp:${vrnp-static.version} > $out/name
|
echo -n git.pbrinkmeier.de/paul/vrnp:${vrnp-static.version} > $out/name
|
||||||
@@ -55,5 +55,6 @@
|
|||||||
config.Cmd = [ "${vrnp-static}/bin/vrnp" ];
|
config.Cmd = [ "${vrnp-static}/bin/vrnp" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "cmp"
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
import "errors"
|
import "errors"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
@@ -8,7 +9,9 @@ import "net/http"
|
|||||||
import "net/url"
|
import "net/url"
|
||||||
import "os"
|
import "os"
|
||||||
import "slices"
|
import "slices"
|
||||||
|
import "strings"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
import "sync/atomic"
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// JSON unmarshaling types for departure monitor API
|
// JSON unmarshaling types for departure monitor API
|
||||||
@@ -43,11 +46,23 @@ type DMDateTime struct {
|
|||||||
Minute string `json:"minute"`
|
Minute string `json:"minute"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchDepartures(stopId string) (DMResponse, error) {
|
type EFAClient interface {
|
||||||
|
GetName() string
|
||||||
|
BuildRequest(string) (*http.Request, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type VRNEFAClient struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c VRNEFAClient) GetName() string {
|
||||||
|
return "VRN"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c VRNEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||||
// Create request object
|
// Create request object
|
||||||
req, err := http.NewRequest("GET", "https://www.vrn.de/mngvrn/XML_DM_REQUEST", nil)
|
req, err := http.NewRequest("GET", "https://www.vrn.de/mngvrn/XML_DM_REQUEST", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DMResponse{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure our request
|
// Configure our request
|
||||||
@@ -65,6 +80,77 @@ func FetchDepartures(stopId string) (DMResponse, error) {
|
|||||||
query.Set("useRealtime", "1")
|
query.Set("useRealtime", "1")
|
||||||
req.URL.RawQuery = query.Encode()
|
req.URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type KVVEFAClient struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c KVVEFAClient) GetName() string {
|
||||||
|
return "KVV"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c KVVEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("action", "XSLT_DM_REQUEST")
|
||||||
|
form.Set("name_dm", stopId)
|
||||||
|
form.Set("type_dm", "stop")
|
||||||
|
form.Set("useRealtime", "1")
|
||||||
|
form.Set("limit", "10")
|
||||||
|
form.Set("mode", "direct")
|
||||||
|
form.Set("useRealtime", "1")
|
||||||
|
form.Set("outputFormat", "json")
|
||||||
|
body := strings.NewReader(form.Encode())
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", "https://www.kvv.de/tunnelEfaDirect.php", body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("User-Agent", "coolio/1.0")
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type BwegtEFAClient struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c BwegtEFAClient) GetName() string {
|
||||||
|
return "bwegt"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c BwegtEFAClient) BuildRequest(stopId string) (*http.Request, error) {
|
||||||
|
// Create request object
|
||||||
|
req, err := http.NewRequest("GET", "https://www.bwegt.de/bwegt-efa/XML_DM_REQUEST", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure our request
|
||||||
|
query := url.Values{}
|
||||||
|
query.Set("coordOutputFormat", "EPSG:4326")
|
||||||
|
query.Set("depType", "stopEvents")
|
||||||
|
query.Set("includeCompleteStopSeq", "0")
|
||||||
|
query.Set("limit", "10")
|
||||||
|
query.Set("locationServerActive", "0")
|
||||||
|
query.Set("mode", "direct")
|
||||||
|
query.Set("name_dm", stopId)
|
||||||
|
query.Set("outputFormat", "json")
|
||||||
|
query.Set("type_dm", "stop")
|
||||||
|
query.Set("useOnlyStops", "1")
|
||||||
|
query.Set("useRealtime", "1")
|
||||||
|
req.URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func FetchDepartures(c EFAClient, stopId string) (DMResponse, error) {
|
||||||
|
req, err := c.BuildRequest(stopId)
|
||||||
|
if err != nil {
|
||||||
|
return DMResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
// Send the request, wait max 10 seconds
|
// Send the request, wait max 10 seconds
|
||||||
client := http.Client{
|
client := http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
@@ -95,6 +181,7 @@ type Departure struct {
|
|||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
Direction string `json:"direction"`
|
Direction string `json:"direction"`
|
||||||
Leaving string `json:"leaving"`
|
Leaving string `json:"leaving"`
|
||||||
|
Countdown int
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures, error) {
|
||||||
@@ -139,9 +226,14 @@ func ParseDepartures(response DMResponse, allowedPlatform *string) (Departures,
|
|||||||
d.ServingLine.Symbol,
|
d.ServingLine.Symbol,
|
||||||
direction,
|
direction,
|
||||||
leaving,
|
leaving,
|
||||||
|
countdown,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.SortFunc(ds, func(a Departure, b Departure) int {
|
||||||
|
return cmp.Compare(a.Countdown, b.Countdown)
|
||||||
|
})
|
||||||
|
|
||||||
return Departures{ds}, nil
|
return Departures{ds}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +243,14 @@ func main() {
|
|||||||
panic("Required environment variable VRNP_PASSWORD is not set")
|
panic("Required environment variable VRNP_PASSWORD is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use round-robin to send incoming requests to different servers
|
||||||
|
var efaClient atomic.Uint64
|
||||||
|
efaClients := []EFAClient{
|
||||||
|
BwegtEFAClient{},
|
||||||
|
VRNEFAClient{},
|
||||||
|
KVVEFAClient{},
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/departures", func(w http.ResponseWriter, r *http.Request) {
|
||||||
user, pass, ok := r.BasicAuth()
|
user, pass, ok := r.BasicAuth()
|
||||||
if !(ok && user == "admin" && pass == password) {
|
if !(ok && user == "admin" && pass == password) {
|
||||||
@@ -172,7 +272,9 @@ func main() {
|
|||||||
platform = &query["platform"][0]
|
platform = &query["platform"][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
ds, err := FetchDepartures(stopId)
|
c := efaClients[(efaClient.Add(1) - 1) % uint64(len(efaClients))]
|
||||||
|
log.Print(c.GetName())
|
||||||
|
ds, err := FetchDepartures(c, stopId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user