gendarme

Context

During the winter months, oyster farms are at an increased risk of theft due to the chrismas feast. In addition, oyster thieves may be more motivated to steal during the winter when there is less activity and less of a chance of being caught.

We need a protocol to receive information from sensors and alert in case of threats.

Functionnal Explications

The github with the source.

Imagine a device with a camera that tracks the entry of your farm.

In our app :

  • subscribe to a topic (name = DETECTED) to get information detected by the camera
  • we use an IA model that recognize what's on the picture
  • we use an algo to estimate a threat score
  • if the threat is too high, we send our payload to another topic (name = THREAT)
  • we save the payload in db for history

fonctional schema

Technicals explications

requirements

you need

  • docker to start MQTT Broker, Mongo DB

MQTT

An MQTT broker is a server that receives and sends messages between clients, allowing them to communicate with each other and exchange data over a network.

When subscribing to a topic, you can define the QOS (Quality of Service) It refers to the level of guarantee that a message will be delivered from the sender to the receiver. There are three levels:

QoS 0 (At Most Once): Message may not be delivered but it's quick to consume.

Example: you want to consume from temperature sensor and need to make an average over the day

QoS 1 (At Least Once): Message will be delivered at least once but it might be consumed multiple times.

Example: your app checks if the temperature is too high, it's ok to read twice the message, but critical if you miss the information ...

QoS 2 (Exactly Once): It's the slowest consume, but you can assume you will not miss the message and consume only once

Example: someone has entered your farm, we can't miss this info & can't read it twice or we might think there are 2 intrusions ...

Because we don't want to miss any burglar, we choose the QOS 2 !

start the environnement

docker-compose up -d mongo
docker-compose up -d mosquitto
docker-compose up -d app

test app

To mock the device you can use this simple endpoint that will publish to the topic DETECTED a payload

curl --location --request POST 'localhost:3001/mock-detected'

this above endpoint publishes on the topic DETECTED the below payload

{
  "sensorName": "Road X",
  "x": 49.7549872844638,
  "y": 0.35485002847631275,
  "imageUrl": "url/of/image/take",
  "timestamp": "2022-12-29 15:32:44"
}

Your app is subscribed to the topic DETECTED, you should see in the logs that he received the payload

level=info msg="topic oyster-guardian/detected consume message {\"sensorName\":\"Road X\",\"x\":49.7549872844638,\"y\":0.35485002847631275,\"imageUrl\":\"url/of/image/take\",\"timestamp\":\"2022-12-29 15:32:44\"}"

then your app

level=info msg="analysing img with url url/of/image/take"
level=info msg="type detected is human pack"

because the threat point is too high, we publish to the topic THREAT

level=info msg="topic oyster-guardian/threat consume message {\"sensorName\":\"Road X\",\"x\":49.7549872844638,\"y\":0.35485002847631275,\"imageUrl\":\"url/of/image/take\",\"timestamp\":\"2022-12-29 15:32:44\"}"
level=info msg="ALERT ! There might be a threat on your farm on the location => {\"sensorName\":\"Road X\",\"x\":49.7549872844638,\"y\":0.35485002847631275,\"imageUrl\":\"url/of/image/take\",\"timestamp\":\"2022-12-29 15:32:44\"}"

this was a really simple application using MQTT and an idea on where it could be useful