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

Update to Mbed Cloud 1.2.2 #16

Merged
merged 7 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .mbedignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ docs/
example-nodejs/
example-python/
webapp/
mbed-cloud-client/mbed-client-pal/Source/Port/Reference-Impl/mbedOS/Update/pal_plat_update.cpp
mbed-cloud-client/provisioning-sources-private/lib-device-identity/source/identity_dev_security.c
platform/linux/setup.cpp
__x86_x64_Linux_Native/*
pal-platform/*
59 changes: 24 additions & 35 deletions docs/4_connectivity.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
### Adding connectivity

Now that you've built the basic circuit and written the code to control that circuit, you can add connectivity to the project. Part of the ARM mbed IoT Device Platform is mbed Cloud, a unified solution to connect devices to the internet and communicate with them, regardless of *how* these devices connect to the internet. Libraries are available for a variety of connectivity methods, including Ethernet, Wi-Fi and cellular. You also can add new connectivity methods with the [unified networking APIs](https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/communication/network_sockets/) in mbed OS 5.
Now that you've built the basic circuit and written the code to control that circuit, you can add connectivity to the project. Part of the ARM Mbed IoT Device Platform is Mbed Cloud, a unified solution to connect devices to the internet and communicate with them, regardless of *how* these devices connect to the internet. Libraries are available for a variety of connectivity methods, including Ethernet, Wi-Fi and cellular. You also can add new connectivity methods with the [unified networking APIs](https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/communication/network_sockets/) in Mbed OS 5.

#### Obtaining a device certificate

[mbed TLS](https://tls.mbed.org) encrypts all data that goes from the device to mbed Cloud (and from mbed Cloud to the device). You need a security certificate to set up secure communication, which you can get from the mbed Cloud Portal:
[Mbed TLS](https://tls.mbed.org) encrypts all data that goes from the device to Mbed Cloud (and from Mbed Cloud to the device). You need a security certificate to set up secure communication, which you can get from the Mbed Cloud Portal:

1. Go to the [mbed Cloud Portal](https://portal.us-east-1.mbedcloud.com), and sign in.
1. If prompted for your login credentials, use your mbed Cloud credentials. These are different from your credentials for the mbed Online Compiler.
1. Select **Developer Tools** > **Certificate**.
1. Click **Get new device security credentials**.
1. To copy the contents of the white box, click **Copy to clipboard**. This is your certificate.
1. Go to the [Mbed Cloud Portal](https://portal.us-east-1.mbedcloud.com), and sign in.
1. If prompted for your login credentials, use your Mbed Cloud credentials. These are different from your credentials for the Mbed Online Compiler.
1. Select **Device Identity** > **Certificates**.
1. Click **Actions** > **Create a developer certificate**.
1. Enter a name for the certificate, and click **Create certificate**.
1. Click **Download Developer C file**. Your certificate file downloads.

<span class="images">![The certificate is located in the white box](https://s3-us-west-2.amazonaws.com/cloud-docs-images/lights16.png)</span>

1. Go back to the mbed Online Compiler.
1. Go back to the Mbed Online Compiler.
1. Create a new file `identity_dev_security.c` in your application's `source` directory.
1. Paste the certificate into this file.

<span class="notes">**Note:** You can only download the certificate once. It's not stored in the mbed Cloud Portal.</span>

#### Adding connectivity to the board

**Built-in Ethernet, Wi-Fi or Cellular**

This example assumes that the network has DHCP enabled and the firewall does not block connections to *https://mbedcloud.com*.

If you have a development board that connects over Ethernet, just plug in an Ethernet cable. If you have a board that connects over cellular or Wi-Fi, no actions are required.

#### Adding libraries with the mbed Online Compiler

For the device and mbed Cloud to talk, you need the [mbed Cloud Client library](https://cloud.mbed.com/docs/latest/mbed-cloud-client/index.html). This is a cross-platform library that runs on mbed OS and Linux, and which you can port to other RTOSes. In this example, you will use an additional library built on top of mbed Cloud Client: SimpleCloudClient. This library is designed specifically to be used with mbed OS 5 and makes it easy to expose variables and resources to the cloud.
**ESP8266 Wi-Fi module**

You will also use [EasyConnect](https://github.com/ARMmbed/easy-connect) to handle connectivity.
To wire the ESP8266 module to your development board, look at the [ESP8266 Cookbook page](https://os.mbed.com/users/4180_1/notebook/using-the-esp8266-with-the-mbed-lpc1768/). This means hooking up the ESP8266's TX pin to `D0` and RX pin to `D1`.

To add these libraries to your project:
<span class="notes">**Note about ESP8266 on NUCLEO boards:** On the NUCLEO boards, pins `D0` and `D1` are used for serial communication with the computer. Use pins `D8` (to ESP8266 TX) and `D2` (to ESP8266 RX) instead.</span>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: From a content perspective, is it correct to say "... The NUCLEO boards reserve pins D0 and D1 for serial communication ..." for active voice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine.


1. Go back to the mbed Online Compiler.
1. Right-click on your program in the tree, and select **Import Library** > **From URL**.
1. Under **Source URL**, enter: `https://github.com/armmbed/easy-connect`.
1. Do **not** tick **Update all sub-libraries to the latest version**.
1. Click **Import**.
1. Again, right-click on your program, and select **Import Library** > **From URL**.
1. Under **Source URL** enter: `https://github.com/armmbed/simple-cloud-client/`.
1. Click **Import**.
#### Adding libraries with the Mbed Online Compiler

#### Adding libraries with mbed CLI
For the device and Mbed Cloud to talk, you need the [Mbed Cloud Client library](https://cloud.mbed.com/docs/latest/mbed-cloud-client/index.html). This is a cross-platform library that runs on Mbed OS and Linux and that you can port to other RTOSes. This example uses an additional library built on top of Mbed Cloud Client: SimpleCloudClient. We created this library specifically to use Mbed OS 5, so you can expose variables and resources to the cloud.

If you are using mbed CLI, run the following commands to add the libraries:
You will also use [EasyConnect](https://github.com/ARMmbed/easy-connect) to handle connectivity.

```bash
$ mbed add easy-connect
$ mbed add simple-cloud-client
```
These libraries are already in the project (see the `.lib` files in the project directory).

#### Updating configuration

Expand All @@ -73,10 +62,10 @@ You need to tell **EasyConnect** which connectivity method to use. Open `mbed_ap
"help": "Pin used as RX (connects to ESP8266 TX)",
"value": "D0"
},
"esp8266-ssid": {
"wifi-ssid": {
"value": "\"SSID\""
},
"esp8266-password": {
"wifi-password": {
"value": "\"Password\""
},
"esp8266-debug": {
Expand All @@ -93,7 +82,7 @@ If you are using Wi-Fi, you also need to set your Wi-Fi SSID and your password.

##### Setting up a connection

You need to add some code to the application, so it connects to the internet and sets up a connection to mbed Cloud.
You need to add some code to the application, so it connects to the internet and sets up a connection to Mbed Cloud.

Replace `main.cpp` with:

Expand Down Expand Up @@ -125,7 +114,7 @@ void blink_builtin_led() {
}

void registered() {
// When we registered with mbed Cloud, blink faster
// When we registered with Mbed Cloud, blink faster
eventQueue.cancel(statusLedBlinkId);

statusLedBlinkId = eventQueue.call_every(300, &blink_builtin_led);
Expand Down Expand Up @@ -171,7 +160,7 @@ The code sample above only sets up the connection. You can now define some logic
1. The color of the LED should be configurable.
1. The period between the moment of motion detection to the moment lights go out should be configurable.
1. There should be a permanent-on mode for the lights.
1. You should notify mbed Cloud whenever you detect movement.
1. You should notify Mbed Cloud whenever you detect movement.

You can implement these actions by defining *resources*: pieces of information the device makes available. You can read or write to them from the cloud, and the device can use a resource's value to determine the correct action to perform. You can reach a resource with a URI and access modifier (for example, only write allowed), and you can also subscribe to them, so you receive a notification when a resource changes.

Expand Down Expand Up @@ -289,7 +278,7 @@ void pir_rise() {

When you compile and flash this program, you'll see that when you wave your hand in front of the PIR sensor, the color of the LED changes to green, and the LED always turns off after 5 seconds.

When the connection to mbed Cloud is created, the onboard LED blinks faster. You can now control this device from the cloud.
When the connection to Mbed Cloud is created, the onboard LED blinks faster. You can now control this device from the cloud.

<span class="notes">**Note:** No connection? [Inspect the logs on the device](https://docs.mbed.com/docs/mbed-os-handbook/en/latest/debugging/printf/).</span>

18 changes: 9 additions & 9 deletions docs/5_controlling-from-cloud.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
### Controlling the device from mbed Cloud
### Controlling the device from Mbed Cloud

Now, the device is connected through mbed Cloud. In the code sample in the previous section, you defined resources using calls to `client.define_resource()`. These resources are automatically exposed to mbed Cloud, from where you can read and write resources, and changes automatically sync with the device. That means that you already have a remote management interface for this device.
Now, the device is connected through Mbed Cloud. In the code sample in the previous section, you defined resources using calls to `client.define_resource()`. These resources are automatically exposed to Mbed Cloud, from where you can read and write resources, and changes automatically sync with the device. That means that you already have a remote management interface for this device.

#### Seeing the status of a device

Each device that you connect to mbed Cloud has an endpoint name. This is a long string, which is the unique identifier of your device. If you don't know the endpoint name of your device, check the [serial output](https://docs.mbed.com/docs/mbed-os-handbook/en/latest/debugging/printf/) on your device for a line starting with 'Device Identity'.
Each device that you connect to Mbed Cloud has an endpoint name. This is a long string, which is the unique identifier of your device. If you don't know the endpoint name of your device, check the [serial output](https://docs.mbed.com/docs/mbed-os-handbook/en/latest/debugging/printf/) on your device for a line starting with 'Device Identity'.

You need to know the endpoint's name to check the device's status in the mbed Cloud Portal. The [Connectivity Inspector](https://portal.us-east-1.mbedcloud.com/developer/connected) page lists all devices associated with your account and their current status.
You need to know the endpoint's name to check the device's status in the Mbed Cloud Portal. The [Device directory](https://portal.us-east-1.mbedcloud.com/devices) page lists all devices associated with your account and their current status. Click the **Connected only** toggle to only see connected devices.

<span class="tips">**Tip:** The mbed Cloud interface lists your devices by type. You can categorize devices by setting the device type in the application running on the device. See the `endpoint-type` property in `mbed_app.json`.</span>
<span class="tips">**Tip:** The Mbed Cloud interface lists your devices by type. You can categorize devices by setting the device type in the application running on the device. See the `endpoint-type` property in `mbed_app.json`.</span>

<span class="images">![Two connected devices](https://s3-us-west-2.amazonaws.com/cloud-docs-images/lights11.png)<span>The mbed Cloud Portal connectivity inspector page, showing two connected devices: our light-system and another device.</span></span>
<span class="images">![Two connected devices](https://s3-us-west-2.amazonaws.com/cloud-docs-images/lights11.png)<span>The Mbed Cloud Portal connectivity inspector page, showing two connected devices: our light-system and another device.</span></span>

#### Controlling the device

Expand All @@ -21,11 +21,11 @@ You created four resources before (see `main.cpp`):
* `led/0/permanent_status` - whether we should have the lights permanently on (status 1) or off (status 2), or just let the PIR sensor figure it out (status 0).
* `pir/0/count` - the number of times the PIR sensor was triggered. This is read only and shows notifications.

You can control these resources through the mbed Cloud Portal. For instance, when you write the value `1` to `led/0/permanent_status`, the lights stay on indefinitely.
You can control these resources through the Mbed Cloud Portal. For instance, when you write the value `1` to `led/0/permanent_status`, the lights stay on indefinitely.

##### Turning the lights on

To test this, select **Developer Tools** > **Connectivity inspector** in mbed Cloud Portal and click on your device. This gives you access to a management console where you can quickly test interactions with resources.
To test this, click on your Device ID in the device directory in Mbed Cloud Portal. This gives you access to a management console where you can quickly test interactions with resources.

<span class="images">![Viewing resources on the device](https://s3-us-west-2.amazonaws.com/cloud-docs-images/lights19.png)<span>These tables show the available resources on this device.</span></span>

Expand Down Expand Up @@ -61,4 +61,4 @@ Use the API Console to write this value to resource `/led/0/color` and change th

##### Other variables

You can also change the value of the timeout (in a real light system you probably want at least 30 seconds) and read the number of times the PIR sensor triggered (in the GET tab).
You can also change the value of the timeout (in a real light system, you probably want at least 30 seconds) and read the number of times the PIR sensor triggered.
Loading