This commit is contained in:
Gregory Salaun 2025-05-28 22:50:29 +02:00
parent 026915fdec
commit ded5c332e2
5 changed files with 98 additions and 5 deletions

View File

@ -81,7 +81,7 @@ func (c *TCPClient) StartClient() {
go func() {
for message := range c.TCPServer.CmdChan {
Log.Infof("Received DX Command: %s", message)
Log.Infof("Received Command: %s", message)
message := message + "\n"
c.WriteString(message)
}
@ -144,7 +144,7 @@ func (c *TCPClient) ReadLine() {
c.Write([]byte(c.Login + "\r\n"))
c.SetFilters()
if Cfg.Cluster.Command != "" {
c.WriteString(Cfg.Cluster.Command)
c.WriteString(Cfg.Cluster.Command + "\n\r")
}
Log.Info("Start receiving spots")
} else if strings.Contains(message, "Error reading from server: read tcp") {

View File

@ -44,6 +44,16 @@ type Config struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
} `yaml:"telnetserver"`
Gotify struct {
Enable bool `yaml:"enable"`
URL string `yaml:"url"`
Token string `yaml:"token"`
NewDXCC bool `yaml:"NewDXCC"`
NewBand bool `yaml:"NewBand"`
NewMode bool `yaml:"NewMode"`
NewBandAndMode bool `yaml:"NewBandAndMode"`
} `yaml:"gotify"`
}
func NewConfig(configPath string) *Config {

View File

@ -8,13 +8,13 @@ sqlite:
sqlite_path: 'C:\Perso\Seafile\Radio\Logs\Log4OM\F4BPO.SQLite' # SQLite Db oath of Log4OM
callsign: F4BPO # Log4OM Callsign used to check if you get spotted by someone
cluster:
server: cluster.f4bpo.com # dxc.k0xm.net
server: dxc.k0xm.net # dxc.k0xm.net
port: 7300
login: f4bpo
skimmer: true
ft8: false
ft4: false
command: #SET/NOFILTER
command: SET/NOFILTER
login_prompt: "Please enter your call:"
flex:
discovery: true # Radio must be on same LAN than the program
@ -22,4 +22,12 @@ flex:
spot_life: 600 #seconds
telnetserver: # Log4OM must be connected to this server ie: localhost:7301 if on same machine as this program else ip:7301
host: 0.0.0.0
port: 7301
port: 7301
gotify:
enable: true
url: https://gotify.rouggy.com/message
token: ALaGS4MVMWTEMcP
newDxcc: true
NewBand: false
NewMode: false
NewBandAndMode: true

View File

@ -209,6 +209,9 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
flexSpot.BackgroundColor = "#ff000000"
}
// Send notification to Gotify
Gotify(flexSpot)
flexSpot.Comment = strings.ReplaceAll(flexSpot.Comment, " ", "\u00A0")
srcFlexSpot, err := fc.Repo.FindDXSameBand(flexSpot)

72
gotify.go Normal file
View File

@ -0,0 +1,72 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type GotifyMessage struct {
Title string `json:"title"`
Message string `json:"message"`
Priority int `json:"priority"`
}
func Gotify(spot FlexSpot) {
if Cfg.Gotify.Enable {
message := fmt.Sprintf("DX: %s\nFrom: %s\nFreq: %s\nMode: %s\n", spot.DX, spot.Source, spot.FrequencyMhz, spot.Mode)
gotifyMsg := GotifyMessage{
Title: "",
Message: message,
Priority: 10,
}
if spot.NewDXCC && Cfg.Gotify.NewDXCC {
title := "FlexDXCluster New DXCC"
gotifyMsg.Title = title
gotifyMsg.Message = message
sendToGotify(gotifyMsg)
}
if spot.NewBand && spot.NewMode && Cfg.Gotify.NewBandAndMode {
title := "FlexDXCluster New Mode & Band"
gotifyMsg.Title = title
gotifyMsg.Message = message
sendToGotify(gotifyMsg)
}
}
}
func sendToGotify(mess GotifyMessage) {
jsonData, err := json.Marshal(mess)
if err != nil {
Log.Errorln("Error marshaling JSON:", err)
return
}
req, err := http.NewRequest("POST", Cfg.Gotify.URL, bytes.NewBuffer(jsonData))
if err != nil {
Log.Errorln("Error creating request:", err)
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+Cfg.Gotify.Token)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
Log.Errorln("Error sending request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
Log.Errorln("Gotify server returned non-OK status:", resp.Status)
} else {
Log.Println("Push successfully sent to Gotify")
}
}