diff --git a/.env.example b/.env.example index 2abfbcd..497921d 100644 --- a/.env.example +++ b/.env.example @@ -18,9 +18,10 @@ MQTT_TOPIC="__MQTT_TOPIC__" MQTT_QOS="__MQTT_QOS__" MQTT_RETAINED="__MQTT_RETAINED__" -# HTTP Protocol Configuration -PROTOCOLS_HTTP_ENABLED="__PROTOCOLS_HTTP_ENABLED__" -PROTOCOLS_HTTP_PATH="__PROTOCOLS_HTTP_PATH__" +# Protocol Configuration +PROTOCOLS_CHIRPSTACK_ENABLED="__PROTOCOLS_CHIRPSTACK_ENABLED__" +PROTOCOLS_TTN_ENABLED="__PROTOCOLS_TTN_ENABLED__" +PROTOCOLS_HELIUM_ENABLED="__PROTOCOLS_HELIUM_ENABLED__" # SMS Protocol Configuration PROTOCOLS_SMS_ENABLED="__PROTOCOLS_SMS_ENABLED__" diff --git a/README.md b/README.md index a1d6660..35507c8 100644 --- a/README.md +++ b/README.md @@ -119,9 +119,10 @@ MQTT_TOPIC=mpa/devices/data MQTT_QOS=0 MQTT_RETAINED=false -# HTTP Protocol Configuration -PROTOCOLS_HTTP_ENABLED=true -PROTOCOLS_HTTP_PATH=/http +# Protocol Configuration +PROTOCOLS_CHIRPSTACK_ENABLED=true +PROTOCOLS_TTN_ENABLED=true +PROTOCOLS_HELIUM_ENABLED=true # SMS Protocol Configuration PROTOCOLS_SMS_ENABLED=false diff --git a/cmd/mpa/cmd/serve.go b/cmd/mpa/cmd/serve.go index 9b72956..7b2b3ba 100644 --- a/cmd/mpa/cmd/serve.go +++ b/cmd/mpa/cmd/serve.go @@ -30,7 +30,6 @@ import ( "github.com/Space-DF/mpa-service/internal/mqtt" "github.com/Space-DF/mpa-service/internal/protocols/handlers" "github.com/Space-DF/mpa-service/internal/protocols/lorawan" - "github.com/Space-DF/mpa-service/internal/protocols/transport/http" mqttprotocol "github.com/Space-DF/mpa-service/internal/protocols/transport/mqtt" "github.com/Space-DF/mpa-service/internal/protocols/transport/socketio" "github.com/Space-DF/mpa-service/internal/protocols/transport/websocket" @@ -131,44 +130,34 @@ func runServe(cmd *cobra.Command, args []string) { // Register transport handlers based on configuration transportCount := 0 - // 1. HTTP Transport (generic HTTP handler) - if cfg.Protocols.HTTP.Enabled { - httpHandler := http.NewHandler(deviceService, http.Config{ - Path: cfg.Protocols.HTTP.Path, - }, logger) - handlerManager.Register(httpHandler) - logger.Infof("Registered HTTP transport handler at path: %s", cfg.Protocols.HTTP.Path) - transportCount++ - } - - // 2. ChirpStack HTTP Transport + // 1. ChirpStack HTTP Transport if cfg.Protocols.ChirpStack.Enabled { chirpstackFactory := lorawan.NewChirpStackFactory(deviceService, logger) chirpstackHandler := chirpstackFactory.CreateHandler() handlerManager.Register(chirpstackHandler) - logger.Infof("Registered ChirpStack transport handler at path: /lorawan/chirpstack/http") + logger.Infof("Registered ChirpStack transport handler at path: /chirpstack/http") transportCount++ } - // 3. TTN HTTP Transport + // 2. TTN HTTP Transport if cfg.Protocols.TTN.Enabled { ttnFactory := lorawan.NewTTNFactory(deviceService, logger) ttnHandler := ttnFactory.CreateHandler() handlerManager.Register(ttnHandler) - logger.Infof("Registered TTN transport handler at path: /lorawan/ttn/http") + logger.Infof("Registered TTN transport handler at path: /ttn/http") transportCount++ } - // 4. Helium HTTP Transport + // 3. Helium HTTP Transport if cfg.Protocols.Helium.Enabled { heliumFactory := lorawan.NewHeliumFactory(deviceService, logger) heliumHandler := heliumFactory.CreateHandler() handlerManager.Register(heliumHandler) - logger.Infof("Registered Helium transport handler at path: /lorawan/helium/http") + logger.Infof("Registered Helium transport handler at path: /helium/http") transportCount++ } - // 5. WebSocket Transport + // 2. WebSocket Transport if cfg.Protocols.WebSocket.Enabled { wsHandler := websocket.NewHandler(deviceService, websocket.Config{ Path: cfg.Protocols.WebSocket.Path, @@ -187,7 +176,7 @@ func runServe(cmd *cobra.Command, args []string) { transportCount++ } - // 6. MQTT Subscriber Transport (non-HTTP) + // 3. MQTT Subscriber Transport (non-HTTP) if cfg.Protocols.MQTT.Enabled { mqttConfig := mqttprotocol.Config{ Broker: cfg.MQTT.Broker, @@ -216,7 +205,7 @@ func runServe(cmd *cobra.Command, args []string) { handlerManager.Register(mqttTransportHandler) } - // 7. SocketIO Transport (non-HTTP initially, but needs HTTP for upgrade) + // 4. SocketIO Transport (non-HTTP initially, but needs HTTP for upgrade) if cfg.Protocols.WebSocket.Enabled { // Reuse WebSocket config for SocketIO sioHandler := socketio.NewHandler(deviceService, socketio.Config{ Path: "/socket.io/", diff --git a/configs/config.yaml b/configs/config.yaml index 70ec526..df3059b 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -18,10 +18,6 @@ mqtt: retained: false # Protocol Configuration protocols: - http: - enabled: true - path: "/http" - sms: enabled: false provider: "twilio" @@ -43,13 +39,13 @@ protocols: enabled: false path: "/socketio" port: 8083 - + chirpstack: enabled: false - + ttn: enabled: false - + helium: enabled: false diff --git a/internal/config/config.go b/internal/config/config.go index 56e219c..35a295a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,23 +25,16 @@ type ServerConfig struct { } type ProtocolsConfig struct { - HTTP HTTPConfig `mapstructure:"http"` - SMS SMSConfig `mapstructure:"sms"` - WebSocket WebSocketConfig `mapstructure:"websocket"` - MQTT MQTTProtocolConfig `mapstructure:"mqtt_protocol"` - LoRaWAN LoRaWANConfig `mapstructure:"lorawan"` - // Backward compatibility - these will be deprecated - ChirpStack ChirpStackConfig `mapstructure:"chirpstack"` - TTN TTNConfig `mapstructure:"ttn"` - Helium HeliumConfig `mapstructure:"helium"` + SMS SMSConfig `mapstructure:"sms"` + WebSocket WebSocketConfig `mapstructure:"websocket"` + MQTT MQTTProtocolConfig `mapstructure:"mqtt_protocol"` + LoRaWAN LoRaWANConfig `mapstructure:"lorawan"` + ChirpStack ChirpStackConfig `mapstructure:"chirpstack"` + TTN TTNConfig `mapstructure:"ttn"` + Helium HeliumConfig `mapstructure:"helium"` } // Protocol-specific configurations -type HTTPConfig struct { - Enabled bool `mapstructure:"enabled" env:"PROTOCOLS_HTTP_ENABLED"` - Path string `mapstructure:"path" env:"PROTOCOLS_HTTP_PATH"` -} - type SMSConfig struct { Enabled bool `mapstructure:"enabled" env:"PROTOCOLS_SMS_ENABLED"` Provider string `mapstructure:"provider" env:"PROTOCOLS_SMS_PROVIDER"` @@ -149,8 +142,6 @@ func setDefaults(vp *viper.Viper) { }) vp.SetDefault("mqtt.qos", 0) vp.SetDefault("mqtt.retained", false) - vp.SetDefault("protocols.http.enabled", true) - vp.SetDefault("protocols.http.path", "/http") vp.SetDefault("protocols.sms.enabled", false) vp.SetDefault("protocols.sms.provider", "twilio") vp.SetDefault("protocols.sms.port", 8081) diff --git a/internal/protocols/lorawan/base/handler.go b/internal/protocols/lorawan/base/handler.go index c5f07be..d650493 100644 --- a/internal/protocols/lorawan/base/handler.go +++ b/internal/protocols/lorawan/base/handler.go @@ -45,7 +45,7 @@ func (h LoRaWANHandler) Name() string { // Path returns the HTTP endpoint path func (h LoRaWANHandler) Path() string { - return fmt.Sprintf("/lorawan/%s/http", h.provider) + return fmt.Sprintf("/%s/http", h.provider) } // Method returns the HTTP method