{credentials}After the network profile has been successfully added to the Smart Motor Sensor, it will stop broadcasting its AP, and both the sensor and the mobile or desktop device should connect to the internet.

The Smart Motor Sensor will connect to the internet via the Wi-Fi network specified in the network profile. The mobile or desktop device may connect to the internet via the same Wi-Fi network, another Wi-Fi network, or, less commonly, another access mode (e.g. wired LAN).

Once the sensor and the mobile or desktop device have connected to the internet, the sensor will attempt to connect to the cloud via the IoT endpoint. Before the sensor can connect to the cloud, however, the mobile or desktop application must provision it using the sensor certificate. Provisioning the sensor with the cloud ensures that the data from the sensor will flow into the user’s tenant and can be processed by the ADI OtoSense™ Smart Motor Sensor analytics.

The sensor will then enter normal operation mode and begin communicating with the cloud.

Warning: The sensor will make 3 attempts (at 30 second intervals) to connect to the cloud. If you are unable to provision the sensor within this time frame, the sensor will enter sleep mode, and you will need to wait 20 minutes before you will be able to confirm that the sensor is connecting to the cloud [see Confirming the sensor’s cloud connection (optional)].

Figure 5: An overview of the cloud connection phase

Getting the OAuth bearer token

The ADI OtoSense™ Smart Motor Sensor REST API implements the OAuth 2.0 Client Credentials flow. The Client Credentials flow is recommended for use in machine-to-machine authentication. Your application will need to securely store its Client ID and Secret and pass those to the token service in exchange for an access token. At a high-level, the flow only has two steps:

  1. Your application passes its client credentials in a token request.
  2. If the credentials are accurate, OtoSense SMS responds with an access token.

Refer to https://adi.otosensesms.com/api-reference for more details on how to obtain a client id and secret.

Protocol: HTTPS
Host: your.apiendpoint.otosensesms.com
Method: POST
Path: /oauth/token
Request Headers:

Parameter Description
Authorization HTTP Basic Auth.
Create a basic auth header from your client_id and client_secret using the rules of HTTP basic auth. The header field should be in the form of Authorization: Basic {credentials} where credentials is the Base64 encoding of client_id and client_secret joined by a single colon :.

Request Content Type: application/x-www-form-urlencoded
Request Body:
grant_type=client_credentials

Response Content Type: application/json
Sample Response:

{
  "token_type": "bearer",
  "access_token": "eyJ0eXBlIXN0In0=.OTMMtNUxZGI2.Py6iJNUM3CEy2S.GTKP/92lYch4B/c=.MjAyMDBa",
  "expires_in": 3600,
  "scope": "service.sms tenant.tid.abc123 role.standard"
}

Provisioning the sensor in the cloud

Once this step is finished, the commissioning process is complete. Using the sensor certificate, provision the SMS in the cloud to claim it for the user’s tenant.

Protocol: HTTPS
Host: your.apiendpoint.otosensesms.com
Method: POST
Path: /sensors
Request Headers:

Parameter Description
Authorization Bearer Token.
This bearer token obtained from the ‘Getting the OAuth bearer token’ request.

Request Content Type: application/json
Request Schema:

Parameter Description
cert X509 certificate PEM for this sensor obtained from ‘Getting the sensor certificate’.

Sample Request:

{
  "cert": "-----BEGIN CERTIFICATE-----\nbase64encodeddata .. base64encodeddata=\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\nbase64encodeddata .. base64encodeddata=\n-----END CERTIFICATE-----"
}

Response Content Type: application/json
Sample Response:

{
  "sensorId": "0000S111A",
  "provisioned": "2020-08-18T18:43:35.713Z",
  "provisionedBy": "APIKEYID"
}

Confirming the sensor’s cloud connection (optional)

If you want to confirm that data is flowing from the device to the cloud, you can use an HTTP GET request to check the sensor’s `lastConnected` property in the cloud.

Note: The sensor may take 1-20 minute(s) to begin communicating with the cloud, depending on whether the device is in hibernation mode.

Protocol: HTTPS
Host: your.apiendpoint.otosensesms.com
Method: GET
Path: /sensors/sensorId
Path Parameters:

Parameter Description
sensorId The senosr ID. (ex. 0000S111A)

Request Headers:

Parameter Description
Authorization Bearer Token.
This bearer token obtained from the ‘Getting the OAuth bearer token’ request.

Response Content Type: application/json
Sample Response:

{
  "sensorId": "0000S111A",
  "provisioned": "2020-08-18T18:43:35.713Z",
  "provisionedBy": "APIKEYID",
  "lastConnected": "2021-03-02T17:21:03.314Z"
}