Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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__"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 9 additions & 20 deletions cmd/mpa/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -187,7 +176,7 @@ func runServe(cmd *cobra.Command, args []string) {
transportCount++
}

// 6. MQTT Subscriber Transport (non-HTTP)
// 3. MQTT Subscriber Transport (non-HTTP)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The numbering in the comments is inconsistent. This should be 5 to follow the sequence.

Suggested change
// 3. MQTT Subscriber Transport (non-HTTP)
// 5. MQTT Subscriber Transport (non-HTTP)

if cfg.Protocols.MQTT.Enabled {
mqttConfig := mqttprotocol.Config{
Broker: cfg.MQTT.Broker,
Expand Down Expand Up @@ -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/",
Expand Down
10 changes: 3 additions & 7 deletions configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ mqtt:
retained: false
# Protocol Configuration
protocols:
http:
enabled: true
path: "/http"

sms:
enabled: false
provider: "twilio"
Expand All @@ -43,13 +39,13 @@ protocols:
enabled: false
path: "/socketio"
port: 8083

chirpstack:
enabled: false

ttn:
enabled: false

helium:
enabled: false

Expand Down
23 changes: 7 additions & 16 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The LoRaWAN field appears to be redundant now that specific LoRaWAN providers (ChirpStack, TTN, and Helium) are defined as top-level fields in ProtocolsConfig. If the map-based configuration is no longer supported, this field should be removed to avoid confusion.

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"`
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/protocols/lorawan/base/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading