Skip to content

Commit

Permalink
Merge pull request intel-retail#148 from ejlee3/fix-cv-inference
Browse files Browse the repository at this point in the history
fix: Address Lenny's PR comments
  • Loading branch information
ejlee3 authored Sep 26, 2023
2 parents f4ea352 + 402f1ea commit 80dd866
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ds-cv-inference/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,26 @@ func NewMqttConnection(connectionString string) Connection {
// define a function for the default message handler
var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {

var edgeXMessage map[string]string
if err := json.Unmarshal(msg.Payload(), &edgeXMessage); err != nil {
fmt.Println(http.StatusBadRequest, "Failed to unmarshal body")
return
}

fmt.Printf("received message: %v+", edgeXMessage)
fmt.Printf("received message on topic: %s", msg.Topic())

words := strings.Split(msg.Topic(), "/")
if len(words) != 5 {
numWords := len(words)
if numWords > 5 {
fmt.Println(http.StatusBadRequest, fmt.Sprintf("mqtt command topic not formatted for EdgeX 3.0: %s", msg.Topic()))
return
}
cmd := words[2]
uuid := words[4]

cmd := words[numWords-3]
method := words[numWords-2]
uuid := words[numWords-1]
publishTopic := fmt.Sprintf("%s/%s", responseTopic, uuid)

if !strings.EqualFold(method, "get") {
fmt.Println(http.StatusBadRequest, fmt.Sprintf("expected mqtt to have the method GET, got %s in the topic, %s", method, msg.Topic()))
return
}

edgeXMessage := make(map[string]string)
switch cmd {
case "inferenceHeartbeat":
{
Expand Down Expand Up @@ -153,7 +156,6 @@ func SendDeltaData(client MQTT.Client, delta []byte) {
cmdSKUDelta := "inferenceSkuDelta"
publishTopic := fmt.Sprintf("%s/%s/%s", dataTopic, "Inference-device", cmdSKUDelta)
edgeXMessage := make(map[string]string)
edgeXMessage["method"] = "get"
edgeXMessage[cmdSKUDelta] = string(delta)

deltaMessage, _ := json.Marshal(edgeXMessage)
Expand Down

0 comments on commit 80dd866

Please sign in to comment.