Skip to content

Commit 1fd45f1

Browse files
committed
Add Device Controller Feature
1 parent 951fe8e commit 1fd45f1

File tree

9 files changed

+431
-181
lines changed

9 files changed

+431
-181
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,89 @@ for more information on the troubleshooting
203203
|9|CELLULAR NETWORK REGISTRATION STATUS MAX|
204204
<p>Table 2. Network Registration Status </p>
205205

206+
## Device Controller
207+
The Device Controller is an API that allows you to interact with devices integrated into the 1NCE API. You can use this API to send requests to devices, and the devices will respond accordingly. For more details you can visit our [DevHub](https://help.1nce.com/dev-hub/docs/1nce-os-device-controller)
208+
### Sending a Request
209+
To send a request to a specific device, you can use the following `curl` command:
210+
#### UDP
211+
212+
```
213+
curl -X 'POST' 'https://api.1nce.com/management-api/v1/integrate/devices/<ICCID>/actions/UDP' \
214+
-H 'accept: application/json' \
215+
-H 'Authorization: Bearer <your Access Token >' \
216+
-H 'Content-Type: application/json' \
217+
-d '{
218+
"payload": "enable_sensor",
219+
"payloadType": "STRING",
220+
"port": 3000,
221+
"requestMode": "SEND_WHEN_ACTIVE"
222+
}'
223+
```
224+
Replace `<ICCID>` with the ICCID (International Mobile Subscriber Identity) of the target device and `<your Access Token>` with the authentication token from [Obtain Access Token](https://help.1nce.com/dev-hub/reference/postaccesstokenpost).
225+
#### COAP
226+
227+
```
228+
curl -X 'POST' 'https://api.1nce.com/management-api/v1/integrate/devices/<ICCID>/actions/COAP' \
229+
-H 'accept: application/json' \
230+
-H 'Authorization: Bearer <your Access Token >' \
231+
-H 'Content-Type: application/json' \
232+
-d '{
233+
"payload": "Data to send to the device",
234+
"payloadType": "STRING",
235+
"port": <NCE_RECV_PORT>,
236+
"path": "/example?param1=query_example1",
237+
"requestType": "POST",
238+
"requestMode": "SEND_NOW"
239+
}'
240+
```
241+
Replace `<ICCID>` with the ICCID (International Mobile Subscriber Identity) of the target device and `<your Access Token>` with the authentication token from [Obtain Access Token](https://help.1nce.com/dev-hub/reference/postaccesstokenpost).
242+
243+
##### Requested Parameters
244+
* `payload`: The data you want to send to the device. This should be provided as a string.
245+
* `payloadType`: The type of the payload. In this example, it is set to "STRING".
246+
* `port`: The port number on which the device will receive the request. In the code, this is defined as NCE_RECV_PORT.
247+
* `path`: The path of the request. It can include query parameters as well. In this example, it is set to "/example?param1=query_example1".
248+
* `requestType`: The type of request, such as "POST", "GET", etc.
249+
* `requestMode`: The mode of the request. In this example, it is set to "SEND_NOW". There are other possible value like SEND_WHEN_ACTIVE.
250+
251+
#### FreeRTOS Configuration
252+
To handle the incoming request from the 1NCE API, the configuration of certain parameters needed
253+
254+
##### nce_demo_config.h
255+
```
256+
/* C2D Parameters */
257+
#define NCE_RECV_PORT 3000
258+
#define NCE_RECEIVE_BUFFER_SIZE 200
259+
260+
```
261+
* `NCE_RECV_PORT`: This is the port number where your device will listen for incoming requests. It should match the port parameter used in the request.
262+
* `NCE_RECEIVE_BUFFER_SIZE` : This is the size of the buffer that will be used to receive the incoming data from the 1NCE API.
263+
264+
#### FreeRTOS Output
265+
266+
##### COAP
267+
268+
When the FreeRTOS application receives a request from the 1NCE API, it will produce output similar to the following:
269+
270+
```
271+
[ListeningTask] [INFO ][LwM2M][9777] Token (len 8) [0xDCB86446841F78AC]
272+
[ListeningTask] [INFO ][LwM2M][9785] OPTION 11 (delta 11, len 7):
273+
[ListeningTask] [INFO ][LwM2M][9792] Uri-Path [example]
274+
[ListeningTask] [INFO ][LwM2M][9798] OPTION 12 (delta 1, len 0):
275+
[ListeningTask] [INFO ][LwM2M][9805] Content-Format [0]
276+
[ListeningTask] [INFO ][LwM2M][9811] OPTION 15 (delta 3, len 21):
277+
[ListeningTask] [INFO ][LwM2M][9818] Uri-Query [param1=query_example1]
278+
[ListeningTask] [INFO ][LwM2M][9825] Payload [Data to send to the device]
279+
[ListeningTask] [INFO ][LwM2M][9833] -Done parsing-------
280+
```
281+
282+
##### UDP
283+
284+
```
285+
[ListeningTask] [INFO ][DEMO][8652] Listening on UDP port 3000...
286+
[ListeningTask] [INFO ][DEMO][9520] Received 13 bytes:
287+
enable_sensor
288+
```
206289
## Asking for Help
207290

208291
The most effective communication with our team is through GitHub. Simply create a [new issue](https://github.com/1NCE-GmbH/blueprint-freertos/issues/new/choose) and select from a range of templates covering bug reports, feature requests, documentation issue, or Gerneral Question.

0 commit comments

Comments
 (0)