From 64c5003fad33b49fd30f92afae41f4fd97a4a6e0 Mon Sep 17 00:00:00 2001 From: idanoo Date: Tue, 14 Feb 2023 00:43:43 +1300 Subject: [PATCH] Progress --- .env.example | 8 ++--- go.mod | 5 +++ go.sum | 2 ++ main.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/.env.example b/.env.example index 2cc74b1..d0c6be8 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -DISCORD_WEBHOOK= -RTL_FREQ=157.950 -RTL_DEVICE_ID= -RTL_GAIN=40.2 \ No newline at end of file +DISCORD_WEBHOOK="" +RTL_FREQ="157.50" +RTL_DEVICE_ID="" +RTL_GAIN="40.2" diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5b37040 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module go-pager-discord + +go 1.20 + +require github.com/joho/godotenv v1.5.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/main.go b/main.go new file mode 100644 index 0000000..4491bd9 --- /dev/null +++ b/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/joho/godotenv" +) + +var ( + DISCORD_WEBHOOK string + RTL_FREQ string + RTL_DEVICE_ID string + RTL_GAIN string + + // Emojies to replace + emojis = map[string][]string{ + ":house:": []string{"house", "roof"}, + ":blue_car:": []string{"mva", "mvc", "car "}, + ":fire:": []string{"fire", "smoke", "smoking", "chimney"}, + ":ocean:": []string{"flood"}, + ":evergreen_tree:": []string{"tree"}, + ":wind_blowing_face:": []string{"wind", "blow"}, + ":zap:": []string{"power", "electric", "spark"}, + ":ambulance: :purple_circle:": []string{"purple"}, + ":ambulance:": []string{"chest pain", "not alert", "seizure", "breath", "pain", "fall ", "orange", "sweats", "acute", "red 1", "red 2", "respitory", "bleeding", "purple"}, + ":biohazard": []string{"hazchem"}, + ":helmet_with_cross:": []string{"resc "}, + } + + // Phrases to skip + skip = []string{ + "this is a test", + "enabled demodulators", + "test page", + "assigned to station", + } +) + +// Load .env file +func init() { + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } + + // Webhook to post to + DISCORD_WEBHOOK = os.Getenv("DISCORD_WEBHOOK") + if DISCORD_WEBHOOK == "" { + log.Fatal("DISCORD_WEBHOOK empty or invalid") + } + + // Frequency to listen to + RTL_FREQ = os.Getenv("RTL_FREQ") + if RTL_FREQ == "" { + log.Fatal("RTL_FREQ empty or invalid") + } + + // Not required - if not set, skip setting + RTL_DEVICE_ID = os.Getenv("RTL_DEVICE_ID") + + // Receiver gain + RTL_GAIN = os.Getenv("RTL_GAIN") + if RTL_FREQ == "" { + log.Fatal("RTL_GAIN empty or invalid") + } +} + +// Start func +func main() { + log.Println("Booting go-pager-discord") + + // Start running rtl_fm + multimon + deviceID := "" + if RTL_DEVICE_ID != "" { + deviceID = fmt.Sprintf("-d %s", RTL_DEVICE_ID) + } + + // Build command + _ = fmt.Sprintf( + "rtl_fm -M fm -d %s -f %sM -g %s -s 22050 -- | multimon-ng -t raw -a POCSAG512 -a POCSAG1200 -a FLEX -a POCSAG2400 /dev/stdin", + deviceID, + RTL_FREQ, + RTL_GAIN, + ) +}