Skip to content

Commit d558782

Browse files
authored
Merge pull request #21 from ARMmbed/development
Update to mbed-os-6.3.0
2 parents 6712ac2 + 538fd8e commit d558782

File tree

8 files changed

+160
-9
lines changed

8 files changed

+160
-9
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ jobs:
1010
working_directory: ~
1111
steps:
1212
- checkout:
13-
path: mbed-os-example-aws
13+
path: mbed-os-example-for-aws
1414
- run: |
15-
cd mbed-os-example-aws
15+
cd mbed-os-example-for-aws
1616
mbed deploy
1717
mbed compile -t GCC_ARM -m K64F
1818

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![](./resources/official_armmbed_example_badge.png)
22

3-
# AWS Mbed OS example
3+
# Mbed OS example for AWS cloud
44

55
The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/). It contains an application that connects to an AWS MQTT broker and publishes a message every 1 second for 10 seconds or until a message is received.
66

@@ -13,14 +13,14 @@ You can build the project with all supported [Mbed OS build tools](https://os.mb
1313
1. Clone this repository on your system, and change the current directory to where the project was cloned:
1414

1515
```
16-
$ git clone git@github.com:armmbed/mbed-os-example-aws && cd mbed-os-example-aws
16+
$ git clone https://github.com/ARMmbed/mbed-os-example-for-aws.git && cd mbed-os-example-for-aws
1717
$ mbed deploy
1818
```
1919
2020
Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand:
2121
2222
```
23-
$ mbed import mbed-os-example-aws && cd mbed-os-example-aws
23+
$ mbed import mbed-os-example-for-aws && cd mbed-os-example-for-aws
2424
```
2525
2626
@@ -39,6 +39,18 @@ You can build the project with all supported [Mbed OS build tools](https://os.mb
3939
Also download "Amazon Root CA 1" from [here](https://docs.aws.amazon.com/iot/latest/developerguide/server-authentication.html#server-authentication-certs).
4040
4141
Once you have downloaded the credentials, you will need to place them in the [`aws_credentials.h`](./aws_credentials.h) file of this example.
42+
43+
The example includes a python script to automate converting the credentials you downloaded from AWS into C-compatible arrays/strings. First, create a new folder in the project to store your credential files, eg: `mkdir aws-credentials`. Copy the previously-downloaded credential files into this subdirectory.
44+
45+
Then, you can run the script to automatically generate the necessary code from the credentials:
46+
47+
```
48+
python aws-cert-converter.py aws-credentials
49+
```
50+
51+
For more details on how to use the convert script, simply pass in the `-h` flag to print the help documentation.
52+
53+
The above command will read your credential files and place them into a C header file for you: `aws_credentials.h`
4254
4355
1. Once you have created the "thing", you will need to obtain the custom endpoint name from the console. At the time of writing this document, you can find it under "Settings" in the IoT console.
4456
@@ -64,7 +76,7 @@ You can build the project with all supported [Mbed OS build tools](https://os.mb
6476
```
6577
6678
Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
67-
The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-aws.bin`.
79+
The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-for-aws.bin`.
6880
6981
Depending on the target, you can build the example project with the `GCC_ARM` or `ARM` toolchain. Run the command below to determine which toolchain supports your target:
7082

aws-cert-converter.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
from os import walk
5+
6+
# If modifying the template below,
7+
# make sure to double escape newlines you want in the C-string (ie: '\\n')
8+
# and to double-up brackets ('{' and '}' become '{{' and '}}') or else
9+
# formatting of the template string will fail
10+
header_template = (
11+
"""
12+
// AWS Certificates
13+
14+
#ifndef AWS_CREDENTIALS_H
15+
#define AWS_CREDENTIALS_H
16+
17+
namespace aws {{
18+
namespace credentials {{
19+
/*
20+
* PEM-encoded root CA certificate
21+
*/
22+
const char rootCA[] =
23+
{0};
24+
25+
/*
26+
* PEM-encoded client certificate
27+
*/
28+
const char clientCrt[] =
29+
{1};
30+
31+
/*
32+
* PEM-encoded client private key.
33+
*/
34+
const char clientKey[] =
35+
{2};
36+
37+
}}
38+
}}
39+
40+
#endif
41+
"""
42+
)
43+
44+
default_out_file_name = "aws_credentials.h"
45+
46+
# Formats the given file into a C-string with newlines
47+
def format_file(file_path):
48+
out = ''
49+
with open(file_path, 'r') as f:
50+
lines = f.readlines()
51+
for l in lines:
52+
# Do not add a newline to the last line
53+
line_format = '"{}\\n"\n'
54+
if l is lines[-1]:
55+
line_format = '"{}"\n'
56+
out = out + line_format.format(l.strip())
57+
return out
58+
59+
def main():
60+
parser = argparse.ArgumentParser(description='Convert AWS credential files to a compatible C-style header format')
61+
parser.add_argument('certs_directory', metavar='d', help='Path to directory containing credential files downloaded from AWS IoT Console')
62+
global default_out_file_name
63+
parser.add_argument('--output-file', help='Output file name (optional, defaults to: {}'.format(default_out_file_name))
64+
args = parser.parse_args()
65+
66+
# Walk the given directory to find the cert files we need
67+
f = []
68+
for (dirpath, dirnames, filenames) in walk(args.certs_directory):
69+
f.extend(filenames)
70+
break
71+
72+
# These are the files we need, make sure they exist
73+
root_ca_file = None
74+
client_crt_file = None
75+
client_key_file = None
76+
for cert_file in f:
77+
if "root" in cert_file.lower():
78+
root_ca_file = args.certs_directory + "/" + cert_file
79+
elif ".pem.crt" in cert_file:
80+
client_crt_file = args.certs_directory + "/" + cert_file
81+
elif "private.pem.key" in cert_file:
82+
client_key_file = args.certs_directory + "/" + cert_file
83+
84+
if root_ca_file:
85+
print("Root CA file found: {}".format(root_ca_file))
86+
else:
87+
print("Could not find Root CA file (eg: AmazonRootCA1.pem)!")
88+
exit()
89+
90+
if client_crt_file:
91+
print("Client certificate file found: {}".format(client_crt_file))
92+
else:
93+
print("Could not find client certificate file (eg: xxxxxxxxxx-certificate.pem.crt)!")
94+
exit()
95+
96+
if client_key_file:
97+
print("Client key file found: {}".format(client_key_file))
98+
else:
99+
print("Could not find client private key file (eg: xxxxxxxxxx-private.pem.key)!")
100+
exit()
101+
102+
print("Generating C-style header from given credentials...")
103+
104+
global header_template
105+
out_file_name = default_out_file_name
106+
if args.output_file:
107+
out_file_name = args.output_file
108+
109+
with open(out_file_name, 'w+') as out:
110+
out.write(header_template.format(format_file(root_ca_file),\
111+
format_file(client_crt_file),\
112+
format_file(client_key_file)))
113+
114+
print("Saved generated credentials header to {}!".format(out_file_name))
115+
116+
if __name__ == "__main__":
117+
main()

aws_credentials.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// AWS Certificates
1+
/*
2+
* AWS Certificates
3+
* Copyright (c) 2020 Arm Limited
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
27

38
#ifndef AWS_CREDENTIALS_H
49
#define AWS_CREDENTIALS_H

mbed-aws-client.lib

Lines changed: 0 additions & 1 deletion
This file was deleted.

mbed-client-for-aws.lib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/ARMmbed/mbed-client-for-aws.git#8ed6606e142e338a3cd27932138c984120d86e65

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#890f0562dc2efb7cf76a5f010b535c2b94bce849
1+
https://github.com/ARMmbed/mbed-os/#0db72d0cf26539016efbe38f80d6f2cb7a3d4414

mbed_app.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@
3030
"nsapi.default-wifi-security": "WPA_WPA2",
3131
"nsapi.default-wifi-ssid": "\"SSID\"",
3232
"nsapi.default-wifi-password": "\"PASSWORD\""
33+
},
34+
"EP_AGORA": {
35+
"platform.stdio-buffered-serial" : true,
36+
"platform.stdio-flush-at-exit" : true,
37+
"drivers.uart-serial-rxbuf-size" : 1024,
38+
"drivers.uart-serial-txbuf-size" : 1024,
39+
"lwip.ipv4-enabled" : true,
40+
"lwip.ipv6-enabled" : true,
41+
"lwip.ppp-enabled" : true,
42+
"lwip.tcp-enabled" : true,
43+
"lwip.ethernet-enabled" : false,
44+
"lwip.mem-size" : 22000,
45+
"lwip.tcpip-thread-stacksize" : 2000,
46+
"nsapi.dns-response-wait-time" : 30000,
47+
"nsapi.default-cellular-apn" : "\"phone\"",
48+
"lwip.use-mbed-trace" : true,
49+
"lwip.debug-enabled" : false
3350
}
3451
}
3552
}

0 commit comments

Comments
 (0)