Skip to content

Commit

Permalink
DOCS-3018: Update helmet tutorial for email option (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguequierre authored Oct 17, 2024
1 parent 6d7f9c9 commit 0f63a64
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
Binary file added assets/tutorials/helmet/trigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions docs/configure/triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ aliases:
- /build/configure/triggers/
---

Triggers allow you to trigger webhooks when certain types of data are sent from your machine to the cloud, or when the your machine parts connect to Viam.
For example, you can configure a trigger to send you a notification when your robot's sensor collects a new reading.
Viam provides the following trigger types depending on the event you want to trigger on:
Triggers allow you to send webhook requests or emails for the following events:

- **Data has been synced to the cloud**: trigger when data from the machine is synced
- **Part is online**: trigger continuously at a specified interval while the {{< glossary_tooltip term_id="part" text="machine part" >}} is online
- **Part is offline**: trigger continuously at a specified interval while the machine part is offline
- **Conditional data ingestion**: trigger any time data is captured from a specified component with a specified method and condition

For example, you can configure a trigger to send you a notification when your robot's sensor collects a new reading.

To configure a trigger:

{{< tabs >}}
Expand Down Expand Up @@ -65,18 +65,20 @@ You must [configure data capture](/services/data/capture-sync/) for your compone
{{< tabs name="Notifications types" >}}
{{% tab name="Webhooks" %}}

Replace the **URL** value with the URL of your cloud function or lambda.
Click **Add Webhook**.
Add the URL of your cloud function or lambda.
Configure the time between notifications.

![The trigger configured with an example URL in the Viam app.](/build/configure/trigger-configured.png)

{{% /tab %}}
{{% tab name="Emails" %}}

Click **Add Email**.
Add the email you wish to be notified whenever this trigger is triggered.
Configure the time between notifications.

![The trigger configured with an example URL in the Viam app.](/build/configure/trigger-configured-email.png)
![The trigger configured with an example email in the Viam app.](/build/configure/trigger-configured-email.png)

{{% /tab %}}
{{< /tabs >}}
Expand Down
57 changes: 27 additions & 30 deletions docs/tutorials/projects/helmet.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Monitor Job Site Helmet Usage with Computer Vision"
linkTitle: "Helmet Monitor"
type: "docs"
description: "Get an email alert if people are not wearing hard hats."
description: "Use computer vision to detect problems such as people not wearing safety gear and get email alerts."
videos: ["/tutorials/helmet/hardhat.webm", "/tutorials/helmet/hardhat.mp4"]
images: ["/tutorials/helmet/hardhat.gif"]
videoAlt: "A man without a hard hat is detected and labeled as No-Hardhat. Then he puts on a hard hat and a bounding box labeled Hardhat appears. He gives a thumbs-up to the camera."
Expand All @@ -18,10 +18,12 @@ cost: 120

{{<imgproc src="/tutorials/helmet/ppe-hooks.png" resize="x300" declaredimensions=true alt="Hard hats and neon reflective vests on hooks." class="alignright" style="width: 350px">}}

We all know personal protective equipment (PPE) helps keep us safe, but sometimes we need a reminder to use it consistently.
Luckily, you can address this problem using Viam's integrated [data capture](/services/data/capture-sync/), [computer vision](/services/vision/), and [triggers](/configure/triggers/), along with a hard hat detection model.
Personal protective equipment (PPE) helps keep us safe, but sometimes we need a reminder to use it consistently.
If you want to monitor the usage of PPE equipment, you can address this problem using computer vision and a machine learning model that can detect if someone is wearing a hard.

By following this tutorial you will build a system to look out for you and your team, sending an email notification when someone isn't wearing a hard hat.
By following this tutorial you will build a system that can monitor camera feeds and detect situations that require review.
In other words, this system performs anomaly detection.
Whenever the system detects an anomaly, like someone not wearing a hard hat, it will send an email notification.

{{<gif webm_src="/tutorials/helmet/hardhat.webm" mp4_src="/tutorials/helmet/hardhat.mp4" alt="A man without a hard hat is detected and labeled as No-Hardhat. Then he puts on a hard hat and a bounding box labeled Hardhat appears. He gives a thumbs-up to the camera." class="alignleft" max-width="250px">}}

Expand Down Expand Up @@ -248,13 +250,18 @@ Now that you have verified that the detector and data sync are working, modify y

## Set up email notifications

[Triggers](/configure/triggers/) allow you to trigger actions by sending an HTML request when a certain event happens.
In this case, you're going to set up a trigger to trigger a serverless function that sends you an email when an image of someone without a hard hat is uploaded to the cloud.
[Triggers](/configure/triggers/) allow you to send webhook requests or email notifications when certain events happen.

Before you configure a trigger on your machine, you need to create a serverless function for the trigger to call.
For example, you can set up a trigger to perform an action whenever an image of someone without a hard hat is uploaded to the cloud.

You can set up the trigger with a serverless function which sends you a customized email or with Viam's built-in email alerts which sends a generic email letting you know that data has been synced.

If you wish to use Viam's built-in email alerts, skip ahead to [configuring a trigger on your machine](#set-up-email-notifications).
To set up a serverless function, continue reading.

### Create a serverless function

Before you configure a trigger on your machine, you need to create a serverless function for the trigger to call.
A serverless function is a simple script that is hosted by a service such as [Google Cloud Functions](https://cloud.google.com/functions) or [AWS Lambda](https://aws.amazon.com/pm/lambda).
You don't need to host it on your machine; instead, it is always available and runs only when an event triggers it.

Expand Down Expand Up @@ -411,36 +418,26 @@ Now you can test the script:

### Configure a trigger on your machine

Now it's time to configure a [trigger](/configure/triggers/) on your machine to trigger the email cloud function when a person is not wearing a hard hat.
Now it's time to configure a trigger so that you get an email when a person is not wearing a hard hat.
Since you configured data to sync only when an image of a person without a hard hat is captured, configuring the trigger to trigger each time an image is synced to the cloud will produce the desired result.

Configure a trigger as follows:
Go to the **CONFIGURE** tab of your machine on the [Viam app](https://app.viam.com).
Click the **+** (Create) button in the left side menu and select **Trigger**.

1. Navigate to the **CONFIGURE** tab of your machine.
Select **JSON** mode in the left-hand menu.
Name the trigger and click **Create**.

2. Paste the following JSON template into your JSON config.
`"triggers"` is a top-level section like `"components"`, `"services"`, or any of the other config sections.
Select trigger **Type** as **Data has been synced to the cloud** and **Data Types** as **Binary (image)**.

```json {class="line-numbers linkable-line-numbers"}
"triggers": [
{
"url": "<Insert your own cloud function URL>",
"event": {
"attributes": {
"data_types": ["binary"]
},
"type": "part_data_ingested"
}
}
]
```
{{<imgproc src="/tutorials/helmet/trigger.png" resize="x400" declaredimensions=true alt="The trigger created with data has been synced to the cloud as the type and binary (image) as the data type." >}}

3. Replace the `url` value with your cloud function URL.
You can get this URL by copying it from the **TRIGGER** tab in the cloud function console.
Once you've done this, the `url` line should resemble, for example, `"url": "https://us-east1-example-string-123456.cloudfunctions.net/hat-email"`.
To configure notifications, either

4. Click **Save** in the top right corner of the screen to save your changes.
- add a webhook and enter the URL of your custom cloud function, if you created one
- add an email address to use Viam's built-in email notifications

For both options also configure the time between notifications.

Click **Save** in the top right corner of the screen to save your changes.

## Test the whole system

Expand Down

0 comments on commit 0f63a64

Please sign in to comment.