Skip to content

Commit

Permalink
Merge pull request #25 from PelionIoT/edge-0.21-0
Browse files Browse the repository at this point in the history
Edge 0.21.0, typo fixes
  • Loading branch information
JanneKiiskila authored Feb 21, 2023
2 parents 1a55c7f + a957bd5 commit 0bc7b83
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 48 deletions.
24 changes: 24 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Mbed Edge Examples pull request

`
Please fill this pull request template to describe your pull request.
If it introduces API breaks please describe it in detail.
`

## Description

submitter: Please add a description of your PR here.

## Test instructions

Submitter: Please add instructions to test your PR here.

If your pull request is a fix for a defect please write instructions
to reproduce the defect.

## Check list

### Changelog

- [ ] `CHANGELOG.md` updated.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for Edge examples

## Release 0.21.0

* Update mbed-edge submodule to 0.21.0.
* Ubuntu references updated to 22.04 and 20.04 (18.04 dropped).
* Typo fixes.

## Release 0.20.0

* Update mbed-edge submodule to 0.20.0.
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ This example tests the robustness and thread safeness of Protocol API C-API inte

# Build and run the examples

1. Directly on Ubuntu 20.04 or 18.04, or
1. Directly on Ubuntu 22.04 or 20.04 or
1. Using Docker.

## Using Ubuntu 20.04 or 18.04:
## Using Ubuntu 22.04 or 20.04:

1. Dependencies

Expand All @@ -46,16 +46,16 @@ This example tests the robustness and thread safeness of Protocol API C-API inte
Install these (using `sudo` typically):

```
$ apt install build-essential git libc6-dev
$ apt install libmosquitto-dev mosquitto-clients
$ apt install libglib2.0-dev
apt install build-essential git libc6-dev
apt install libmosquitto-dev mosquitto-clients
apt install libglib2.0-dev
```
1. Preparing all the sources
Please run the following to clone and update all the git modules.
```
$ git submodule update --init --recursive
git submodule update --init --recursive
```
1. Building
Expand All @@ -64,34 +64,34 @@ This example tests the robustness and thread safeness of Protocol API C-API inte
To make all examples without debug information and with default trace level, run
```
$ make build-all-examples
make build-all-examples
```
It will build the examples to `build/bin` directory.
To make all examples with debug information and debug trace level, run
```
$ make build-all-examples-debug
make build-all-examples-debug
```
It will build the examples to `build-debug/bin` directory.
To make all examples with ThreadSanitizer and debug trace level, run
```
$ make build-all-examples-sanitize
make build-all-examples-sanitize
```
It will build the examples to `build-sanitize/bin` directory.
Running `make all` will generate `build`, `build-debug` and `build-sanitize` directories.
Please note following:
mqttpt-example will not be built if the libmosquitto is not installed.
`mqttpt-example` will not be built if the `libmosquitto` is not installed.
For more examples, see the rules in the Makefile.
1. Running the examples
Each of the examples has a README.md file that documents how to run the example.
Each of the examples has a `README.md` file that documents how to run the example.
## Using Docker
Expand Down
3 changes: 2 additions & 1 deletion blept-example/devices.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* ----------------------------------------------------------------------------
* Copyright 2018 ARM Ltd.
* Copyright (c) 2023 Izuma Networks
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -34,7 +35,7 @@
#include <sys/time.h>

#define LIFETIME \
300 // this setting currently has no effect. The translated endpoints are tracked withing the parent Edge device
300 // this setting currently has no effect. The translated endpoints are tracked within the parent Edge device
// lifetime. Please see BLE_MAX_BACK_OFF_TIME_SECS for related configuration.
#define TRACE_GROUP "BLEC"

Expand Down
5 changes: 3 additions & 2 deletions blept-example/pt_ble.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* ----------------------------------------------------------------------------
* Copyright 2018 ARM Ltd.
*
* Copyright (c) 2023 Izuma Networks
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -59,7 +60,7 @@
#define BLE_DEVICE_ADDRESS_SIZE 18
#define BLE_DEVICE_NAME_MAX_LENGTH 33
#define MAX_PATH_LENGTH 256
#define MAX_VALUE_STRING_LENGHT 10
#define MAX_VALUE_STRING_LENGTH 10
#define TRACE_GROUP "BLE"
#define BLE_VALUE_READ_INTERVAL 5000
#define BLE_RETRY_SLEEP_TIME_INITIAL_SECS 4
Expand Down
3 changes: 2 additions & 1 deletion c-api-stress-tester/stress_tester.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* ----------------------------------------------------------------------------
* Copyright 2018 ARM Ltd.
* Copyright 2023 (c) Izuma Networks
* ----------------------------------------------------------------------------
*/
#define _POSIX_C_SOURCE 200809L
Expand Down Expand Up @@ -713,7 +714,7 @@ void *protocol_translator_api_start_func(void *ctx)
pt_cbs.received_write_cb = (pt_received_write_handler) received_write_handler;
pt_cbs.connection_shutdown_cb = (pt_connection_shutdown_cb) shutdown_cb_handler;
pt_api_thread_t *api_data = pt_start_ctx->api_thread;
// Don't lock connection mutex here, because this funtion starts the eventloop.
// Don't lock connection mutex here, because this function starts the eventloop.
if (0 != pt_client_start(pt_start_ctx->socket_path,
pt_start_ctx->name,
&pt_cbs,
Expand Down
2 changes: 1 addition & 1 deletion lib/mbed-edge
32 changes: 16 additions & 16 deletions mqttpt-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ hold the sensor value.
Start edge-core:

```
$ ./edge-core
./edge-core
```

Start the mqttpt-example:

```
$ mqttpt-example
mqttpt-example
```

On Device Management, you should see the MQTT endpoints appear as new devices and they
Expand All @@ -66,7 +66,7 @@ The mqttpt-example supports optional command-line parameters, for example to set
For help, use:

```
$ mqttpt-example --help
mqttpt-example --help
```

### Crypto API
Expand All @@ -76,13 +76,13 @@ To subscribe to certificate renewal notifications, do the following when the gat
connected state:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh set-certificates-list certificate_names
mqttgw_sim/mqtt_gw_crypto_api.sh set-certificates-list certificate_names
```

To renew a certificate, it must first be added to the certificate list with the `set-certificates-list` operation as described above. To renew a certificate, do the following:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh renew-certificate certificate_name
mqttgw_sim/mqtt_gw_crypto_api.sh renew-certificate certificate_name
```

Only one certificate can be renewed at a time, and the certificate identified by `certificate_name` must exist on the device. It's supported to renew factory provisioned certificates,
Expand All @@ -92,8 +92,8 @@ for example ones created by the FCU tool. Renewing developer certificates is not
To test out fetching of the certificate or public key, do the following when the gateway is in the connected state:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh get-certificate certificate_name
$ mqttgw_sim/mqtt_gw_crypto_api.sh get-public-key certificate_name
mqttgw_sim/mqtt_gw_crypto_api.sh get-certificate certificate_name
mqttgw_sim/mqtt_gw_crypto_api.sh get-public-key certificate_name
```

Only one certificate or public key can be fetched at the same time. The certificates identified by `certificate_name`
Expand All @@ -102,8 +102,8 @@ must exist on the device.
To test out the asymmetric signing and verifying, do the following:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh asymmetric-sign private_key_name hash_digest
$ mqttgw_sim/mqtt_gw_crypto_api.sh asymmetric-verify private_key_name hash_digest signature
mqttgw_sim/mqtt_gw_crypto_api.sh asymmetric-sign private_key_name hash_digest
mqttgw_sim/mqtt_gw_crypto_api.sh asymmetric-verify private_key_name hash_digest signature
```

The certificates identified by `private_key_name` must exist on the device. `Hash-digest` is a string that has been
Expand All @@ -124,7 +124,7 @@ hash_digest=$(echo $hash_digest |base64)
To test out the ecdh key agreement, do the following:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh ecdh-key-agreement private_key_name peer_public_key
mqttgw_sim/mqtt_gw_crypto_api.sh ecdh-key-agreement private_key_name peer_public_key
```

The certificates identified by `private_key_name` must exist on the device. Parameter `peer_public_key` is a public key
Expand All @@ -133,7 +133,7 @@ that has been base64-encoded.
To test out the random byte array generation, do the following:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh ecdh-key-agreement generate-random size_of_array
mqttgw_sim/mqtt_gw_crypto_api.sh ecdh-key-agreement generate-random size_of_array
```

### Device certificate renewal
Expand All @@ -144,7 +144,7 @@ The MQTT protocol translator example demonstrates device certificate renewal or
The device initiated certificate renewal or enrollment is performed using the `mqttgw_sim/mqtt_gw_crypto_api.sh` script:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh device-cert-renew device_name certificate_name csr
mqttgw_sim/mqtt_gw_crypto_api.sh device-cert-renew device_name certificate_name csr
```

where `device_name` is the device that is performing the enrollment, `certificate_name` is the certificate to enroll and `csr` is the certificate signing request in DER format and base64 encoded.
Expand All @@ -158,13 +158,13 @@ The renewal or enrollment operation can also be requested from the cloud, for th
A test certificate signing request (CSR) can be generated with openssl:

```
$ openssl ecparam -name prime256v1 -genkey -noout -out private.key # Create private key
openssl req -new -nodes -out csr.req -key private.key -subj "/CN=CUSTOM_CERT_TEST/O=TEST/L=Test/ST=Test/C=EN/OU=ARM" -sha256 -outform DER # Create CSR
base64 -w 0 csr.req > csr_b64.txt # Base64 encode the CSR
openssl ecparam -name prime256v1 -genkey -noout -out private.key # Create private key
openssl req -new -nodes -out csr.req -key private.key -subj "/CN=CUSTOM_CERT_TEST/O=TEST/L=Test/ST=Test/C=EN/OU=ARM" -sha256 -outform DER # Create CSR
base64 -w 0 csr.req > csr_b64.txt # Base64 encode the CSR
```

The generated CSR can then be used when performing the enrollment for example like this:

```
$ mqttgw_sim/mqtt_gw_crypto_api.sh device-cert-renew device_name certificate_name $(cat csr_b64.txt)
mqttgw_sim/mqtt_gw_crypto_api.sh device-cert-renew device_name certificate_name $(cat csr_b64.txt)
```
33 changes: 26 additions & 7 deletions mqttpt-example/mqttgw_sim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,52 @@ This is an MQTT gateway simulator to test the `mqttpt-example` protocol translat

### Requirements
Requires `mosquitto_pub` client for publishing the MQTT messages to MQTT broker.
`$ apt install mosquitto-clients`
```
sudo apt install mosquitto-clients`
```

### Usage
1. Run `edge-core` and `mqttpt-example`
2. Register MQTT gateway by running `mqtt_gw.sh` script.

`$ ./mqtt_gw.sh`
```
./mqtt_gw.sh
```


3. Register device by running `mqtt_ep.sh` script.

`$ ./mqtt_ep.sh`
```
./mqtt_ep.sh
```

4. Update certificates `cert_id_1` and `cert_id_2` on the gateway

`$ ./mqtt_gw_crypto_api.sh --renew-certificates cert_id_1 cert_id_2`
```
./mqtt_gw_crypto_api.sh --renew-certificates cert_id_1 cert_id_2
```


5. Get certificate `cert_id_1`

`$ ./mqtt_gw_crypto_api.sh --get-certificate cert_id_1`
```
./mqtt_gw_crypto_api.sh --get-certificate cert_id_1
```


6. Get public key for `cert_id_1`

`$ ./mqtt_gw_crypto_api.sh --get-public-key cert_id_1`
```
$ ./mqtt_gw_crypto_api.sh --get-public-key cert_id_1
```


Notice that the device script accepts parameters for device name, temperature and humidity. For example to register device `MY_DEVICE` and set temperature value to 20.1C and humidity value to 67.5%:

`$ ./mqtt_ep.sh -d MY_DEVICE -t 20.1 -h 67.5`
```
./mqtt_ep.sh -d MY_DEVICE -t 20.1 -h 67.5
```


`mqtt_gw_crypto_api.sh` script can also be used to test rest of the crypto-features. Full list of the supported operations is

Expand Down
3 changes: 2 additions & 1 deletion mqttpt-example/mqttpt_example.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* ----------------------------------------------------------------------------
* Copyright 2018 ARM Ltd.
* Copyright (c) 2023 Izuma Networks
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -166,7 +167,7 @@ static void publish_to_mqtt(const char *topic, json_t *json_message)

/* Success message format:
* {
* "request_id": "id of the request that was succesful",
* "request_id": "id of the request that was successful",
* "value": "response value for the request"
* }
*/
Expand Down
2 changes: 1 addition & 1 deletion pt-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ client API.
This example creates three mediated devices and registers then to
Device Management. There are two temperature sensors and one thermometer. The
`cpu-temperature` device is created only if the underlying operating system
provides CPU temperature values from the `/sys/class/thermal/thermalzone[N]` file.
provides CPU temperature values from the `/sys/class/thermal/thermal_zone[N]` file.
Otherwise the CPU temperature values are random values.
The reset operation is supported for the `cpu-temperature` and it can be
triggered by sending a `POST` operation from Device Management to that resource. Also
Expand Down
Loading

0 comments on commit 0bc7b83

Please sign in to comment.