Steph10
October 12, 2024, 11:11am
1
Hi,
I use the mqtt forwarder on kerlink gateway. it work perfectly. I have custom script to put metadata on chirpstack server etc.
But I want to try the command section.
I try the example reboot, but I don’t now how to send command. I have try through mqtt topic, but i not found any documentation about this.
Have you try this ?
thanks you for help
Hello,
I think there is no documentation available, and you will need to send the Gateway Command Exec Request
yourself.
To do this, you can use the SDK to create commands for the MQTT forwarder in various programming languages.
ChirpStack API GitHub Repository
When you have your Gateway Command Exec Request
payload ready, send it to the following topic:
eu868/gateway/{gw_id}/command/exec
You will receive the response on this topic:
eu868/gateway/{gw_id}/event/exec
Example in Go
package main
import (
"github.com/chirpstack/chirpstack/api/go/v4/gw"
mqtt "github.com/eclipse/paho.mqtt.golang"
"google.golang.org/protobuf/proto"
"log"
"os"
)
func main() {
// setup mqtt client option
opts := mqtt.NewClientOptions().
AddBroker("tcp://test.mosquitto.org:1883").
SetClientID("go_mqtt_client")
client := mqtt.NewClient(opts)
// connect and catch error
if token := client.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
// random number to check if response of your command
var execID uint32 = 1234
// Prepare the Command Request
gatewayCommandExecRequest := gw.GatewayCommandExecRequest{
GatewayId: "ac1f09fffe0caeb5",
Command: "reboot",
ExecId: execID,
Stdin: nil,
Environment: nil,
}
// Subscribe to the response topic
client.Subscribe("eu868/gateway/00aa00aa00aa00aa/event/exec", 0, func(client mqtt.Client, message mqtt.Message) {
response := &gw.GatewayCommandExecResponse{}
_ = proto.Unmarshal(message.Payload(), response)
// this check are optional
if response.ExecId == execID {
println(response.String())
os.Exit(0)
}
})
payload, _ := proto.Marshal(&gatewayCommandExecRequest)
// Publish the command and catch error
if token := client.Publish("eu868/gateway/00aa00aa00aa00aa/command/exec", 0, false, payload); token.Wait() && token.Error() != nil {
log.Println(token.Error())
}
// Wait forever
select {}
}
You can replace proto.Marshal
by json.Marshal
if you use json config instead of protobuf in chirpstack config
system
Closed
January 10, 2025, 11:11am
3
This topic was automatically closed after 90 days. New replies are no longer allowed.