Skip to content

Commit

Permalink
Merge pull request intel-retail#147 from ejlee3/update-cv-inference
Browse files Browse the repository at this point in the history
feat: Migrate ds-cv-inferencing to be EdgeX 3.0 compatible
  • Loading branch information
ejlee3 authored Sep 22, 2023
2 parents 5ec26f3 + c7fac9b commit f4ea352
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
6 changes: 2 additions & 4 deletions ds-cv-inference/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright © 2022 Intel Corporation. All rights reserved.
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause

ARG OPENVINO_BASE=ubuntu20_dev
Expand All @@ -24,10 +24,8 @@ RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
RUN apt-get update && apt-get install libgtk2.0-dev libgtk-3-dev libjpeg62 -y
WORKDIR /go/src/ds-cv-inference

COPY go.* /go/src/ds-cv-inference/
RUN go mod download

COPY . /go/src/ds-cv-inference
RUN go mod tidy

RUN /bin/bash -c "source /opt/intel/openvino/setupvars.sh && echo building ds-cv-inference... && go build -o ds-cv-inference" && \
chmod +x entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion ds-cv-inference/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright © 2020-2022, Intel Corporation
Copyright © 2020-2023, Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions ds-cv-inference/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright © 2020 Intel Corporation. All rights reserved.
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause

.PHONY: build run down

MICROSERVICE=automated-checkout/ds-cv-inference
MICROSERVICE=automated-vending/ds-cv-inference

tidy:
go mod tidy
Expand Down
4 changes: 2 additions & 2 deletions ds-cv-inference/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---

# Copyright © 2020 Intel Corporation. All rights reserved.
# Copyright © 2023 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause

version: '3.4'

services:

ds-cv-inference:
image: automated-checkout/ds-cv-inference:dev
image: automated-vending/ds-cv-inference:dev
command: ["/go/src/ds-cv-inference/images","127.0.0.1:1883","0.85","/go/src/ds-cv-inference/skumapping.json"]
ports:
- "127.0.0.1:9005:9005"
4 changes: 2 additions & 2 deletions ds-cv-inference/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

module ds-cv-inference

go 1.18
go 1.20

require (
github.com/eclipse/paho.mqtt.golang v1.2.0
Expand Down
8 changes: 4 additions & 4 deletions ds-cv-inference/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package main
Expand All @@ -10,7 +10,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -38,12 +38,12 @@ func main() {
}
defer skuMappingJSONFile.Close()

skuMappingJSONByte, _ := ioutil.ReadAll(skuMappingJSONFile)
skuMappingJSONByte, _ := io.ReadAll(skuMappingJSONFile)

inferenceInit(*directory, *model, *configFile, *confidence, skuMappingJSONByte)

mqttConnection := mqtt.NewMqttConnection(*mqttAddress)
mqttConnection.SubscribeToAutomatedCheckout()
mqttConnection.SubscribeToAutomatedVending()
defer mqttConnection.Disconnect()

inference.Stream = mjpeg.NewStream()
Expand Down
28 changes: 18 additions & 10 deletions ds-cv-inference/mqtt/mqtt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Intel Corporation. All rights reserved.
// Copyright © 2023 Intel Corporation. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause

package mqtt
Expand All @@ -9,6 +9,7 @@ import (
"fmt"
"net/http"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -56,7 +57,7 @@ func NewMqttConnection(connectionString string) Connection {
return mc
}

//define a function for the default message handler
// define a function for the default message handler
var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {

var edgeXMessage map[string]string
Expand All @@ -67,7 +68,16 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT

fmt.Printf("received message: %v+", edgeXMessage)

switch edgeXMessage["cmd"] {
words := strings.Split(msg.Topic(), "/")
if len(words) != 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]
publishTopic := fmt.Sprintf("%s/%s", responseTopic, uuid)

switch cmd {
case "inferenceHeartbeat":
{
pingMessage := edgeXMessage
Expand All @@ -77,7 +87,7 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT
if err != nil {
fmt.Println("Failed to marshal mqtt message")
}
token := client.Publish(responseTopic, 0, false, pongMessage)
token := client.Publish(publishTopic, 0, false, pongMessage)
token.Wait()
}
case "inferenceDoorStatus":
Expand All @@ -90,7 +100,7 @@ var commandTopicFunction MQTT.MessageHandler = func(client MQTT.Client, msg MQTT
if err != nil {
fmt.Println("Failed to marshal mqtt message")
}
token := client.Publish(responseTopic, 0, false, pongMessage)
token := client.Publish(publishTopic, 0, false, pongMessage)
token.Wait()
checkDoorStatus(isDoorClosed, client)
}
Expand Down Expand Up @@ -141,16 +151,14 @@ func checkDoorStatus(isDoorClosed string, client MQTT.Client) {
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["name"] = "Inference-device"
edgeXMessage["cmd"] = cmdSKUDelta
edgeXMessage["method"] = "get"
edgeXMessage[cmdSKUDelta] = string(delta)

deltaMessage, _ := json.Marshal(edgeXMessage)
fmt.Println("Final deltaMessage is ", string(deltaMessage))
token := client.Publish(dataTopic, 0, false, deltaMessage)
token := client.Publish(publishTopic, 0, false, deltaMessage)
token.Wait()
}

Expand All @@ -173,7 +181,7 @@ func (mqttCon *Connection) Connect(connectionString string) {
}
}

func (mqttCon *Connection) SubscribeToAutomatedCheckout() {
func (mqttCon *Connection) SubscribeToAutomatedVending() {
//subscribe to the topic inference/CommandTopic and handle messages in the commandTopicFunction
attempts := 0
for attempts < retryCount {
Expand Down

0 comments on commit f4ea352

Please sign in to comment.