Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Read actual status code after a POST device API call #471

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/c/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "rest-server.h"
#include "map.h"

#include <stdatomic.h>

#define EX_METRIC_EVSENT 0x1
#define EX_METRIC_RDGSENT 0x2
#define EX_METRIC_RDCMDS 0x4
Expand Down
10 changes: 5 additions & 5 deletions src/c/examples/discovery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ provisioning of devices.
The environment variable CSDK_DIR should be set to a directory containing the
C SDK include files and libraries.

Set LD_LIBRARY_PATH to $CSDK_DIR/lib
Set LD_LIBRARY_PATH to $CSDK_DIR/lib:/opt/iotech/iot/1.5/lib

### Building

```
gcc -I$CSDK_DIR/include -L$CSDK_DIR/lib -o device-template template.c -lcsdk
gcc -I$CSDK_DIR/include -I/opt/iotech/iot/1.5/include -L$CSDK_DIR/lib -L/opt/iotech/iot/1.5/lib -o device-template template.c -lcsdk -liot
```

### Device Profile
Expand All @@ -39,16 +39,16 @@ Discovery/Interval to 0), discovery may be forced by calling the discovery
endpoint manually:

```
curl -X POST 0:59999/api/v2/discovery
curl -X POST 0:59999/api/v3/discovery
```

Initially, none of the discovered devices will be added to EdgeX, but by
using appropriate Provision Watchers they can be accepted. To upload the
supplied Provision Watchers to core-metadata:

```
curl -X POST [email protected] 0:59881/api/v2/provisionwatcher
curl -X POST [email protected] 0:59881/api/v2/provisionwatcher
curl -X POST [email protected] 0:59881/api/v3/provisionwatcher
curl -X POST [email protected] 0:59881/api/v3/provisionwatcher
```

The Provision Watchers each match one of the discovered devices. They work by
Expand Down
2 changes: 1 addition & 1 deletion src/c/examples/discovery/watcher1.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"apiVersion":"v2","provisionWatcher":{"apiVersion":"v2", "name":"watcher1", "identifiers":{"MAC":"00-05-1B-A1-99-[0-9A-Fa-f][0-9A-Fa-f]"}, "blockingIdentifiers":{"MAC":["00-05-1B-A1-99-99"]},"profileName":"TemplateSensor","serviceName":"device-template","adminState":"UNLOCKED"}}]
[{"apiVersion":"v2","provisionWatcher":{"apiVersion":"v2","name":"watcher1","identifiers":{"MAC":"00-05-1B-A1-99-[0-9A-Fa-f][0-9A-Fa-f]"},"blockingIdentifiers":{"MAC":["00-05-1B-A1-99-99"]},"serviceName":"device-template","adminState":"UNLOCKED","discoveredDevice":{"profileName":"TemplateSensor","serviceName":"device-template","adminState":"UNLOCKED","properties":{"DeviceNameTemplate":{"valueReplace":true,"template":"device-name-{{MAC}}"}}}}}]
2 changes: 1 addition & 1 deletion src/c/examples/discovery/watcher2.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"apiVersion":"v2","provisionWatcher":{"apiVersion":"v2", "name":"watcher2", "identifiers":{"HTTP":"10\\.0\\.0\\.[0-9]*"}, "blockingIdentifiers":{"HTTP":["10.0.0.1","10.0.0.255"]},"profileName":"TemplateSensor","serviceName":"device-template","adminstate":"UNLOCKED"}}]
[{"apiVersion":"v2","provisionWatcher":{"apiVersion":"v2","name":"watcher2","identifiers":{"HTTP":"10\\.0\\.0\\.[0-9]*"},"blockingIdentifiers":{"HTTP":["10.0.0.1","10.0.0.255"]},"profileName":"TemplateSensor","serviceName":"device-template","adminstate":"UNLOCKED","discoveredDevice":{"profileName":"TemplateSensor","serviceName":"device-template","adminState":"UNLOCKED","properties":{"DeviceNameTemplate":{"valueReplace":true,"template":"device-name-{{HTTP}}"}}}}}]
16 changes: 15 additions & 1 deletion src/c/metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,21 @@ void edgex_metadata_client_add_or_modify_device
iot_data_t *jwt_data = edgex_secrets_request_jwt (secretprovider);
ctx.jwt_token = iot_data_string(jwt_data);

if (edgex_http_post (lc, &ctx, url, json, edgex_http_write_cb, &err) == 409)
edgex_http_post (lc, &ctx, url, json, edgex_http_write_cb, &err);

uint statusCode = 0;
JSON_Value *val = json_parse_string(ctx.buff);
JSON_Array *resps = json_value_get_array (val);
size_t nresps = json_array_get_count (resps);
if (nresps)
{
JSON_Object *obj = json_array_get_object (resps, 0);
statusCode = json_object_get_uint (obj, "statusCode");

}
json_value_free(val);

if (statusCode == 409)
{
if (edgex_metadata_client_check_device (lc, endpoints, secretprovider, name))
{
Expand Down