Mbed Cloud Connect for Ethernet Platforms
Fork of example-Ethernet-mbed-Cloud-connect by
Revision 6:2d0e0866f2e7, committed 2018-05-11
- Comitter:
- davwal04@E108444.Emea.Arm.com
- Date:
- Fri May 11 16:15:18 2018 +0100
- Branch:
- update-1.3.0
- Parent:
- 4:53eff875f5d0
- Child:
- 7:b52a8d71c26e
- Commit message:
- Updating to Mbed Cloud Client 1.3, support for NUCLEO_F429ZI
Changed in this revision
--- a/LICENSE.txt Tue Feb 27 17:36:27 2018 +0000 +++ b/LICENSE.txt Fri May 11 16:15:18 2018 +0100 @@ -1,165 +1,165 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. - -2. Grant of Copyright License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. - -3. Grant of Patent License. - -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. - -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. - -5. Submission of Contributions. - -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. - -6. Trademarks. - -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. - -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. - -8. Limitation of Liability. - -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. - -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability.
--- a/main.cpp Tue Feb 27 17:36:27 2018 +0000
+++ b/main.cpp Fri May 11 16:15:18 2018 +0100
@@ -1,167 +1,156 @@
-// ----------------------------------------------------------------------------
-// Copyright 2016-2017 ARM Ltd.
-//
-// SPDX-License-Identifier: Apache-2.0
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ----------------------------------------------------------------------------
-
-#include "mbed.h"
-#include "mbed-trace/mbed_trace.h"
-#include "mbed-trace-helper.h"
-#include "simple-mbed-cloud-client.h"
-#include "key-config-manager/kcm_status.h"
-#include "key-config-manager/key_config_manager.h"
-#include "HeapBlockDevice.h"
-#include "BlockDevice.h"
-#include "LittleFileSystem.h"
-#include "EthernetInterface.h"
-
-// Placeholder to hardware that trigger events (timer, button, etc)
-Ticker timer;
-
-// Placeholder for storage
-HeapBlockDevice bd(1024*28, 128); // 28 KBytes - Block size: 128 bytes
-LittleFileSystem fs("sd");
-
-// Pointers to the resources that will be created in main_application().
-static MbedCloudClientResource* pattern_ptr;
-
-// Pointer to mbedClient, used for calling close function.
-static SimpleMbedCloudClient *client;
-
-static bool button_pressed = false;
-
-void button_press() {
- button_pressed = true;
-}
-
-void pattern_updated(const char *) {
- printf("PUT received, new value: %s\n", pattern_ptr->get_value().c_str());
- // Placeholder for PUT action
-}
-
-void blink_callback(void *) {
- String pattern_str = pattern_ptr->get_value();
- const char *pattern = pattern_str.c_str();
- printf("POST received. LED pattern = %s\n", pattern);
- // Placeholder for POST action
- // The pattern is something like 500:200:500, so parse that.
-}
-
-void button_callback(const M2MBase& object, const NoticationDeliveryStatus status)
-{
- printf("Button notification. Callback: (%s)\n", object.uri_path());
- // Placeholder for GET
-}
-
-
-int main(void)
-{
- // Requires DAPLink 245+ (https://github.com/ARMmbed/DAPLink/pull/364)
- // Older versions: workaround to prevent possible deletion of credentials:
- wait(2);
-
- // Misc OS setup
- srand(time(NULL));
-
- // Placeholder for network
- EthernetInterface net;
-
- printf("Start Simple Mbed Cloud Client\n");
-
- // Initialize Block Device
- int status = bd.init();
- if (status != BD_ERROR_OK) {
- printf("Failed to init Block Device\r\n");
- return -1;
- }
-
- // Mount the file system (reformatting on failure)
- status = fs.mount(&bd);
- if (status) {
- printf("Failed to mount filesystem, reformatting...\r\n");
- status = fs.reformat(&bd);
- if (status) {
- printf("Failed to reformat filesystem\r\n");
- return -1;
- } else {
- printf("Reformat and mount complete\r\n");
- }
- }
-
- printf("Connecting to the network using Ethernet...\n");
-
- status = net.connect();
- if (status) {
- printf("Connection to Network Failed %d!\n", status);
- return -1;
- } else {
- const char *ip_addr = net.get_ip_address();
- printf("Connected successfully\n");
- printf("IP address %s\n", ip_addr);
- }
-
- SimpleMbedCloudClient mbedClient(&net);
- // Save pointer to mbedClient so that other functions can access it.
- client = &mbedClient;
-
- status = mbedClient.init();
- if (status) {
- return -1;
- }
-
- printf("Client initialized\r\n");
-
- // Mbed Cloud Client resource setup
- MbedCloudClientResource *button = mbedClient.create_resource("3200/0/5501", "button_resource");
- button->set_value("0");
- button->methods(M2MMethod::GET);
- button->observable(true);
- button->attach_notification_callback(button_callback);
-
- MbedCloudClientResource *pattern = mbedClient.create_resource("3201/0/5853", "pattern_resource");
- pattern->set_value("500:500:500:500");
- pattern->methods(M2MMethod::GET | M2MMethod::PUT);
- pattern->attach_put_callback(pattern_updated);
- pattern_ptr = pattern;
-
- MbedCloudClientResource *blink = mbedClient.create_resource("3201/0/5850", "blink_resource");
- blink->methods(M2MMethod::POST);
- blink->attach_post_callback(blink_callback);
-
- mbedClient.register_and_connect();
-
- // Wait for client to finish registering
- while (!mbedClient.is_client_registered()) {
- wait_ms(100);
- }
-
- // Placeholder for callback to update local resource when GET comes.
- timer.attach(&button_press, 5.0);
-
- // Check if client is registering or registered, if true sleep and repeat.
- while (mbedClient.is_register_called()) {
- static int button_count = 0;
- wait_ms(100);
-
- if (button_pressed) {
- button_pressed = false;
- printf("Simulated button clicked %d times\r\n", ++button_count);
- button->set_value(button_count);
- }
- }
-
- // Client unregistered, exit program.
- return 0;
-}
+// ----------------------------------------------------------------------------
+// Copyright 2016-2018 ARM Ltd.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------
+
+#include "mbed.h"
+#include "simple-mbed-cloud-client.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "EthernetInterface.h"
+
+// An event queue is a very useful structure to debounce information between contexts (e.g. ISR and normal threads)
+// This is great because things such as network operations are illegal in ISR, so updating a resource in a button's fall() function is not allowed
+EventQueue eventQueue;
+
+// Storage implementation definition, currently using SDBlockDevice (SPI flash, DataFlash, and internal flash are also available)
+SDBlockDevice bd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS);
+FATFileSystem fs("sd", &sd);
+
+// Declaring pointers for access to Mbed Cloud Client resources outside of main()
+MbedCloudClientResource *button_res;
+MbedCloudClientResource *pattern_res;
+
+// This function gets triggered by the timer. It's easy to replace it by an InterruptIn and fall() mode on a real button
+void fake_button_press() {
+ int v = button_res->get_value_int() + 1;
+
+ button_res->set_value(v);
+
+ printf("Simulated button clicked %d times\n", v);
+}
+
+/**
+ * PUT handler
+ * @param resource The resource that triggered the callback
+ * @param newValue Updated value for the resource
+ */
+void pattern_updated(MbedCloudClientResource *resource, m2m::String newValue) {
+ printf("PUT received, new value: %s\n", newValue.c_str());
+}
+
+/**
+ * POST handler
+ * @param resource The resource that triggered the callback
+ * @param buffer If a body was passed to the POST function, this contains the data.
+ * Note that the buffer is deallocated after leaving this function, so copy it if you need it longer.
+ * @param size Size of the body
+ */
+void blink_callback(MbedCloudClientResource *resource, const uint8_t *buffer, uint16_t size) {
+ printf("POST received. Going to blink LED pattern: %s\n", pattern_res->get_value().c_str());
+
+ static DigitalOut augmentedLed(LED1); // LED that is used for blinking the pattern
+
+ // Parse the pattern string, and toggle the LED in that pattern
+ string s = std::string(pattern_res->get_value().c_str());
+ size_t i = 0;
+ size_t pos = s.find(':');
+ while (pos != string::npos) {
+ wait_ms(atoi(s.substr(i, pos - i).c_str()));
+ augmentedLed = !augmentedLed;
+
+ i = ++pos;
+ pos = s.find(':', pos);
+
+ if (pos == string::npos) {
+ wait_ms(atoi(s.substr(i, s.length()).c_str()));
+ augmentedLed = !augmentedLed;
+ }
+ }
+}
+
+/**
+ * Notification callback handler
+ * @param resource The resource that triggered the callback
+ * @param status The delivery status of the notification
+ */
+void button_callback(MbedCloudClientResource *resource, const NoticationDeliveryStatus status) {
+ printf("Button notification, status %s (%d)\n", MbedCloudClientResource::delivery_status_to_string(status), status);
+}
+
+/**
+ * Registration callback handler
+ * @param endpoint Information about the registered endpoint such as the name (so you can find it back in portal)
+ */
+void registered(const ConnectorClientEndpointInfo *endpoint) {
+ printf("Connected to Mbed Cloud. Endpoint Name: %s\n", endpoint->internal_endpoint_name.c_str());
+}
+
+int main(void) {
+ printf("Starting Simple Mbed Cloud Client example\n");
+ printf("Connecting to the network using Ethernet...\n");
+
+ // Connect to the internet (DHCP is expected to be on)
+ EthernetInterface net;
+ nsapi_error_t status = net.connect();
+
+ if (status != 0) {
+ printf("Connecting to the network failed %d!\n", status);
+ return -1;
+ }
+
+ printf("Connected to the network successfully. IP address: %s\n", net.get_ip_address());
+
+ // SimpleMbedCloudClient handles registering over LwM2M to Mbed Cloud
+ SimpleMbedCloudClient client(&net, &sd, &fs);
+ int client_status = client.init();
+ if (client_status != 0) {
+ printf("Initializing Mbed Cloud Client failed (%d)\n", client_status);
+ return -1;
+ }
+
+ // Creating resources, which can be written or read from the cloud
+ button_res = client.create_resource("3200/0/5501", "button_count");
+ button_res->set_value(0);
+ button_res->methods(M2MMethod::GET);
+ button_res->observable(true);
+ button_res->attach_notification_callback(button_callback);
+
+ pattern_res = client.create_resource("3201/0/5853", "blink_pattern");
+ pattern_res->set_value("500:500:500:500:500:500:500:500");
+ pattern_res->methods(M2MMethod::GET | M2MMethod::PUT);
+ pattern_res->attach_put_callback(pattern_updated);
+
+ MbedCloudClientResource *blink_res = client.create_resource("3201/0/5850", "blink_action");
+ blink_res->methods(M2MMethod::POST);
+ blink_res->attach_post_callback(blink_callback);
+
+ printf("Initialized Mbed Cloud Client. Registering...\n");
+
+ // Callback that fires when registering is complete
+ client.on_registered(®istered);
+
+ // Register with Mbed Cloud
+ client.register_and_connect();
+
+ // Placeholder for callback to update local resource when GET comes.
+ // The timer fires on an interrupt context, but debounces it to the eventqueue, so it's safe to do network operations
+ Ticker timer;
+ timer.attach(eventQueue.event(&fake_button_press), 5.0);
+
+ // You can easily run the eventQueue in a separate thread if required
+ eventQueue.dispatch_forever();
+}
--- a/mbed-os.lib Tue Feb 27 17:36:27 2018 +0000 +++ b/mbed-os.lib Fri May 11 16:15:18 2018 +0100 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#caeaa49d68c67ee00275cece10cd88e0ed0f6ed3 +https://github.com/ARMmbed/mbed-os/#caeaa49d68c67ee00275cece10cd88e0ed0f6ed3
--- a/mbed_app.json Tue Feb 27 17:36:27 2018 +0000
+++ b/mbed_app.json Fri May 11 16:15:18 2018 +0100
@@ -1,22 +1,82 @@
-{
- "macros": [
- "MBEDTLS_USER_CONFIG_FILE=\"mbedTLSConfig_mbedOS.h\"",
- "MBED_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
- "MBED_CLOUD_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
- "PAL_DTLS_PEER_MIN_TIMEOUT=5000",
- "MBED_CONF_APP_MAIN_STACK_SIZE=4608"
- ],
- "target_overrides": {
- "*": {
- "platform.stdio-baud-rate": 115200,
- "platform.stdio-convert-newlines": true,
- "mbed-trace.enable": null
- }
- },
- "config": {
- "developer-mode": {
- "help": "Enable Developer mode to skip Factory enrollment",
- "value": 1
- }
- }
-}
+{
+ "macros": [
+ "MBEDTLS_USER_CONFIG_FILE=\"mbedTLSConfig_mbedOS.h\"",
+ "PAL_USER_DEFINED_CONFIGURATION=\"sotp_fs_config_MbedOS.h\"",
+ "MBED_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
+ "MBED_CLOUD_CLIENT_USER_CONFIG_FILE=\"mbed_cloud_client_user_config.h\"",
+ "PAL_DTLS_PEER_MIN_TIMEOUT=5000",
+ "MBED_CONF_APP_MAIN_STACK_SIZE=4608",
+ "ARM_UC_USE_PAL_BLOCKDEVICE=1",
+ "MBED_CLOUD_CLIENT_UPDATE_STORAGE=ARM_UCP_FLASHIAP_BLOCKDEVICE"
+ ],
+ "target_overrides": {
+ "*": {
+ "platform.stdio-baud-rate": 115200,
+ "platform.stdio-convert-newlines": true,
+ "update-client.storage-address" : "(1024*1024*64)",
+ "update-client.storage-size" : "(1024*1024*2)",
+ "update-client.storage-locations": "1",
+ "mbed-trace.enable": null
+ },
+ "NUCLEO_F429ZI": {
+ "SPI_MOSI" : "PC_12",
+ "SPI_MISO" : "PC_11",
+ "SPI_CLK" : "PC_10",
+ "SPI_CS" : "PA_15",
+ "app.sotp-section-1-address": "(0x08000000+1792*1024)",
+ "app.sotp-section-1-size" : "(128*1024)",
+ "app.sotp-section-2-address": "(0x08000000+1920*1024)",
+ "app.sotp-section-2-size" : "(128*1024)"
+ }
+ },
+ "config": {
+ "format-storage-layer-on-error": {
+ "help": "Whether to format the storage layer when it cannot be read - always disable for production devices!",
+ "value": 1
+ },
+ "developer-mode": {
+ "help": "Enable Developer mode to skip Factory enrollment",
+ "value": 1
+ },
+ "sotp-section-1-address": {
+ "help": "Flash sector address for SOTP sector 1",
+ "macro_name": "PAL_INTERNAL_FLASH_SECTION_1_ADDRESS",
+ "value": null
+ },
+ "sotp-section-1-size": {
+ "help": "Flash sector size for SOTP sector 1",
+ "macro_name": "PAL_INTERNAL_FLASH_SECTION_1_SIZE",
+ "value": null
+ },
+ "sotp-section-2-address": {
+ "help": "Flash sector address for SOTP sector 2",
+ "macro_name": "PAL_INTERNAL_FLASH_SECTION_2_ADDRESS",
+ "value": null
+ },
+ "sotp-section-2-size": {
+ "help": "Flash sector size for SOTP sector 2",
+ "macro_name": "PAL_INTERNAL_FLASH_SECTION_2_SIZE",
+ "value": null
+ },
+ "SPI_MOSI": {
+ "help": "SPI MOSI Pin for storage device if applicable",
+ "macro_name": "MBED_CONF_APP_SPI_MOSI",
+ "value": null
+ },
+ "SPI_MISO": {
+ "help": "SPI MISO Pin for storage device if applicable",
+ "macro_name": "MBED_CONF_APP_SPI_MISO",
+ "value": null
+ },
+ "SPI_CLK": {
+ "help": "SPI CLK Pin for storage device if applicable",
+ "macro_name": "MBED_CONF_APP_SPI_CLK",
+ "value": null
+ },
+ "SPI_CS": {
+ "help": "SPI CS Pin for storage device if applicable",
+ "macro_name": "MBED_CONF_APP_SPI_CS",
+ "value": null
+ }
+ }
+}
--- a/mbed_cloud_client_user_config.h Tue Feb 27 17:36:27 2018 +0000 +++ b/mbed_cloud_client_user_config.h Fri May 11 16:15:18 2018 +0100 @@ -1,56 +1,59 @@ -// ---------------------------------------------------------------------------- -// Copyright 2016-2017 ARM Ltd. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------- - -// This file is a template and it's intented to be copied to the application -// Enable this configuration - -#ifndef MBED_CLOUD_CLIENT_USER_CONFIG_H -#define MBED_CLOUD_CLIENT_USER_CONFIG_H - - -#define MBED_CLOUD_CLIENT_ENDPOINT_TYPE "default" - -// Enable either TCP or UDP, but no both -#define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP -// MBED_CLOUD_CLIENT_TRANSPORT_MODE_UDP - -#define MBED_CLOUD_CLIENT_LIFETIME 3600 - -#define MBED_CLOUD_CLIENT_SUPPORT_UPDATE -#define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 1024 - -// set flag to enable update support in mbed Cloud client -#define MBED_CLOUD_CLIENT_SUPPORT_UPDATE - -// set download buffer size in bytes (min. 1024 bytes) - -// Use larger buffers in Linux // -#ifdef __linux__ -#define MBED_CLOUD_CLIENT_UPDATE_BUFFER (2 * 1024 * 1024) -#else -#define MBED_CLOUD_CLIENT_UPDATE_BUFFER 2048 -#endif - -// Developer flags for Update feature -#if MBED_CONF_APP_DEVELOPER_MODE == 1 - #define MBED_CLOUD_DEV_UPDATE_CERT - #define MBED_CLOUD_DEV_UPDATE_ID -#endif // MBED_CONF_APP_DEVELOPER_MODE - -#endif // MBED_CLOUD_CLIENT_USER_CONFIG_H - +// ---------------------------------------------------------------------------- +// Copyright 2016-2017 ARM Ltd. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------- + +// This file is a template and it's intented to be copied to the application +// Enable this configuration + +#ifndef MBED_CLOUD_CLIENT_USER_CONFIG_H +#define MBED_CLOUD_CLIENT_USER_CONFIG_H + +#ifdef MBED_CONF_APP_ENDPOINT_TYPE +#define MBED_CLOUD_CLIENT_ENDPOINT_TYPE MBED_CONF_APP_ENDPOINT_TYPE +#else +#define MBED_CLOUD_CLIENT_ENDPOINT_TYPE "default" +#endif + +// Enable either TCP or UDP, but no both +#define MBED_CLOUD_CLIENT_TRANSPORT_MODE_TCP +// MBED_CLOUD_CLIENT_TRANSPORT_MODE_UDP + +#define MBED_CLOUD_CLIENT_LIFETIME 3600 + +#define MBED_CLOUD_CLIENT_SUPPORT_UPDATE +#define SN_COAP_MAX_BLOCKWISE_PAYLOAD_SIZE 1024 + +// set flag to enable update support in mbed Cloud client +#define MBED_CLOUD_CLIENT_SUPPORT_UPDATE + +// set download buffer size in bytes (min. 1024 bytes) + +// Use larger buffers in Linux // +#ifdef __linux__ +#define MBED_CLOUD_CLIENT_UPDATE_BUFFER (2 * 1024 * 1024) +#else +#define MBED_CLOUD_CLIENT_UPDATE_BUFFER 2048 +#endif + +// Developer flags for Update feature +#if MBED_CONF_APP_DEVELOPER_MODE == 1 + #define MBED_CLOUD_DEV_UPDATE_CERT + #define MBED_CLOUD_DEV_UPDATE_ID +#endif // MBED_CONF_APP_DEVELOPER_MODE + +#endif // MBED_CLOUD_CLIENT_USER_CONFIG_H +
--- a/mbed_cloud_dev_credentials.c Tue Feb 27 17:36:27 2018 +0000
+++ b/mbed_cloud_dev_credentials.c Fri May 11 16:15:18 2018 +0100
@@ -1,53 +1,53 @@
-/*
- * Copyright (c) 2017 ARM Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __MBED_CLOUD_DEV_CREDENTIALS_H__
-#define __MBED_CLOUD_DEV_CREDENTIALS_H__
-
-#if MBED_CONF_APP_DEVELOPER_MODE == 1
-#error "Replace mbed_cloud_dev_credentials.c with your own developer cert."
-#endif
-
-#include <inttypes.h>
-
-const char MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME[] = "";
-const char MBED_CLOUD_DEV_ACCOUNT_ID[] = "";
-const char MBED_CLOUD_DEV_BOOTSTRAP_SERVER_URI[] = "";
-
-const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE[] =
-{ 0x0 };
-
-const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE[] =
-{ 0x0 };
-
-const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY[] =
-{ 0x0 };
-
-const char MBED_CLOUD_DEV_MANUFACTURER[] = "dev_manufacturer";
-
-const char MBED_CLOUD_DEV_MODEL_NUMBER[] = "dev_model_num";
-
-const char MBED_CLOUD_DEV_SERIAL_NUMBER[] = "0";
-
-const char MBED_CLOUD_DEV_DEVICE_TYPE[] = "dev_device_type";
-
-const char MBED_CLOUD_DEV_HARDWARE_VERSION[] = "dev_hardware_version";
-
-const uint32_t MBED_CLOUD_DEV_MEMORY_TOTAL_KB = 0;
-const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE);
-const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE);
-const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY);
-
-#endif //__MBED_CLOUD_DEV_CREDENTIALS_H__
+/*
+ * Copyright (c) 2017 ARM Limited. All rights reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __MBED_CLOUD_DEV_CREDENTIALS_H__
+#define __MBED_CLOUD_DEV_CREDENTIALS_H__
+
+#if MBED_CONF_APP_DEVELOPER_MODE == 1
+#error "Replace mbed_cloud_dev_credentials.c with your own developer cert."
+#endif
+
+#include <inttypes.h>
+
+const char MBED_CLOUD_DEV_BOOTSTRAP_ENDPOINT_NAME[] = "";
+const char MBED_CLOUD_DEV_ACCOUNT_ID[] = "";
+const char MBED_CLOUD_DEV_BOOTSTRAP_SERVER_URI[] = "";
+
+const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE[] =
+{ 0x0 };
+
+const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE[] =
+{ 0x0 };
+
+const uint8_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY[] =
+{ 0x0 };
+
+const char MBED_CLOUD_DEV_MANUFACTURER[] = "dev_manufacturer";
+
+const char MBED_CLOUD_DEV_MODEL_NUMBER[] = "dev_model_num";
+
+const char MBED_CLOUD_DEV_SERIAL_NUMBER[] = "0";
+
+const char MBED_CLOUD_DEV_DEVICE_TYPE[] = "dev_device_type";
+
+const char MBED_CLOUD_DEV_HARDWARE_VERSION[] = "dev_hardware_version";
+
+const uint32_t MBED_CLOUD_DEV_MEMORY_TOTAL_KB = 0;
+const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_CERTIFICATE);
+const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_SERVER_ROOT_CA_CERTIFICATE);
+const uint32_t MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY_SIZE = sizeof(MBED_CLOUD_DEV_BOOTSTRAP_DEVICE_PRIVATE_KEY);
+
+#endif //__MBED_CLOUD_DEV_CREDENTIALS_H__
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sd-driver.lib Fri May 11 16:15:18 2018 +0100 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/sd-driver/#f4ab55df7768cfcb049b522bebd30218ee729c81
--- a/simple-mbed-cloud-client.lib Tue Feb 27 17:36:27 2018 +0000 +++ b/simple-mbed-cloud-client.lib Fri May 11 16:15:18 2018 +0100 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/simple-mbed-cloud-client/#2cabb6ba035e130093f0de193db1fed5eff9df43 +https://github.com/armmbed/simple-mbed-cloud-client/#3b72d712ccdb1fbdfa1bdec5209b52f5b813d819
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/LICENSE Fri May 11 16:15:18 2018 +0100 @@ -0,0 +1,165 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/combine_bootloader_with_app.py Fri May 11 16:15:18 2018 +0100
@@ -0,0 +1,315 @@
+#!/usr/bin/env python
+
+## ----------------------------------------------------------------------------
+## Copyright 2016-2017 ARM Ltd.
+##
+## SPDX-License-Identifier: Apache-2.0
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ----------------------------------------------------------------------------
+
+from os import path
+import json
+import hashlib, zlib, struct
+import time
+import sys
+from intelhex import IntelHex
+
+'''
+define FIRMWARE_HEADER_MAGIC 0x5a51b3d4UL
+define FIRMWARE_HEADER_VERSION 2
+define ARM_UC_SHA512_SIZE (512/8)
+define ARM_UC_GUID_SIZE (128/8)
+typedef struct _arm_uc_internal_header_t
+{
+ /* Metadata-header specific magic code */
+ uint32_t headerMagic;
+
+ /* Revision number for metadata header. */
+ uint32_t headerVersion;
+
+ /* Version number accompanying the firmware. Larger numbers imply more
+ recent and preferred versions. This is used for determining the
+ selection order when multiple versions are available. For downloaded
+ firmware the manifest timestamp is used as the firmware version.
+ */
+ uint64_t firmwareVersion;
+
+ /* Total space (in bytes) occupied by the firmware BLOB. */
+ uint64_t firmwareSize;
+
+ /* Firmware hash calculated over the firmware size. Should match the hash
+ generated by standard command line tools, e.g., shasum on Linux/Mac.
+ */
+ uint8_t firmwareHash[ARM_UC_SHA512_SIZE];
+
+ /* The ID for the update campaign that resulted in the firmware update.
+ */
+ uint8_t campaign[ARM_UC_GUID_SIZE];
+
+ /* Size of the firmware signature. Must be 0 if no signature is supplied. */
+ uint32_t firmwareSignatureSize;
+
+ /* Header 32 bit CRC. Calculated over the entire header, including the CRC
+ field, but with the CRC set to zero.
+ */
+ uint32_t headerCRC;
+
+ /* Optional firmware signature. Hashing algorithm should be the same as the
+ one used for the firmware hash. The firmwareSignatureSize must be set.
+ */
+ uint8_t firmwareSignature[0];
+} arm_uc_internal_header_t;
+'''
+
+# define defaults to go into the metadata header
+SIZEOF_SHA512 = int(512/8)
+SIZEOF_GUID = int(128/8)
+FIRMWARE_HEADER_MAGIC = 0x5a51b3d4
+FIRMWARE_HEADER_VERSION = 2
+header_format = ">2I2Q{}s{}s2I".format(SIZEOF_SHA512, SIZEOF_GUID)
+
+if sys.version_info < (3,):
+ def b(x):
+ return bytearray(x)
+else:
+ def b(x):
+ return x
+
+def create_header(app_blob, firmwareVersion):
+ # calculate the hash of the application
+ firmwareHash = hashlib.sha256(app_blob).digest()
+
+ # calculate the total size which is defined as the application size + metadata header
+ firmwareSize = len(app_blob)
+
+ # set campaign GUID to 0
+ campaign = b'\00'
+
+ # signature not supported, set size to 0
+ signatureSize = 0
+
+ print ('imageSize: {}'.format(firmwareSize))
+ print ('imageHash: {}'.format(''.join(['{:0>2x}'.format(c) for c in b(firmwareHash)])))
+ print ('imageversion: {}'.format(firmwareVersion))
+
+ # construct struct for CRC calculation
+ headerCRC = 0
+ FirmwareHeader = struct.pack(header_format,
+ FIRMWARE_HEADER_MAGIC,
+ FIRMWARE_HEADER_VERSION,
+ firmwareVersion,
+ firmwareSize,
+ firmwareHash,
+ campaign,
+ signatureSize,
+ headerCRC)
+
+ # calculate checksum over header, including signatureSize but without headerCRC
+ headerCRC = zlib.crc32(FirmwareHeader[:-4]) & 0xffffffff
+
+ # Pack the data into a binary blob
+ FirmwareHeader = struct.pack(header_format,
+ FIRMWARE_HEADER_MAGIC,
+ FIRMWARE_HEADER_VERSION,
+ firmwareVersion,
+ firmwareSize,
+ firmwareHash,
+ campaign,
+ signatureSize,
+ headerCRC)
+
+ return FirmwareHeader
+
+
+def combine(bootloader_fn, app_fn, app_addr, hdr_addr, bootloader_addr, output_fn, version, no_bootloader):
+ ih = IntelHex()
+
+ bootloader_format = bootloader_fn.split('.')[-1]
+
+ # write the bootloader
+ if not no_bootloader:
+ print("Using bootloader %s" % bootloader_fn)
+ if bootloader_format == 'hex':
+ print("Loading bootloader from hex file.")
+ ih.fromfile(bootloader_fn, format=bootloader_format)
+ elif bootloader_format == 'bin':
+ print("Loading bootloader to address 0x%08x." % bootloader_addr)
+ ih.loadbin(bootloader_fn, offset=bootloader_addr)
+ else:
+ print('Bootloader format can only be .bin or .hex')
+ exit(-1)
+
+ # write firmware header
+ app_format=app_fn.split('.')[-1]
+ if app_format == 'bin':
+ with open(app_fn, 'rb') as fd:
+ app_blob = fd.read()
+ elif app_format == 'hex':
+ application = IntelHex(app_fn)
+ app_blob = application.tobinstr()
+ FirmwareHeader = create_header(app_blob, version)
+ print("Writing header to address 0x%08x." % hdr_addr)
+ ih.puts(hdr_addr, FirmwareHeader)
+
+ # write the application
+ if app_format == 'bin':
+ print("Loading application to address 0x%08x." % app_addr)
+ ih.loadbin(app_fn, offset=app_addr)
+ elif app_format == 'hex':
+ print("Loading application from hex file")
+ ih.fromfile(app_fn, format=app_format)
+
+ # output to file
+ ih.tofile(output_fn, format=output_fn.split('.')[-1])
+
+
+if __name__ == '__main__':
+ from glob import glob
+ import argparse
+
+ parser = argparse.ArgumentParser(
+ description='Combine bootloader with application adding metadata header.')
+
+ def addr_arg(s):
+ if not isinstance(s, int):
+ s = eval(s)
+
+ return s
+
+ bin_map = {
+ 'k64f': {
+ 'mem_start': '0x0'
+ },
+ 'ublox_evk_odin_w2': {
+ 'mem_start': '0x08000000'
+ },
+ 'nucleo_f429zi': {
+ 'mem_start': '0x08000000'
+ }
+ }
+
+ curdir = path.dirname(path.abspath(__file__))
+
+ def parse_mbed_app_addr(mcu, key):
+ mem_start = bin_map[mcu]["mem_start"]
+ with open(path.join(curdir, "..", "mbed_app.json")) as fd:
+ mbed_json = json.load(fd)
+ addr = mbed_json["target_overrides"][mcu.upper()][key]
+ return addr_arg(addr)
+
+ # specify arguments
+ parser.add_argument('-m', '--mcu', type=lambda s : s.lower().replace("-","_"), required=False,
+ help='mcu', choices=bin_map.keys())
+ parser.add_argument('-b', '--bootloader', type=argparse.FileType('rb'), required=False,
+ help='path to the bootloader binary')
+ parser.add_argument('-a', '--app', type=argparse.FileType('rb'), required=True,
+ help='path to application binary')
+ parser.add_argument('-c', '--app-addr', type=addr_arg, required=False,
+ help='address of the application')
+ parser.add_argument('-d', '--header-addr', type=addr_arg, required=False,
+ help='address of the firmware metadata header')
+ parser.add_argument('-o', '--output', type=argparse.FileType('wb'), required=True,
+ help='output combined file path')
+ parser.add_argument('-s', '--set-version', type=int, required=False,
+ help='set version number', default=int(time.time()))
+ parser.add_argument('-nb', '--no-bootloader',action='store_true', required=False,
+ help='Produce output without bootloader. The output only '+
+ 'contains header + app. requires hex output format')
+
+ # workaround for http://bugs.python.org/issue9694
+ parser._optionals.title = "arguments"
+
+ # get and validate arguments
+ args = parser.parse_args()
+
+ # validate the output format
+ f = args.output.name.split('.')[-1]
+ if f == 'hex':
+ output_format = 'hex'
+ elif f == 'bin':
+ output_format = 'bin'
+ else:
+ print('Output format can only be .bin or .hex')
+ exit(-1)
+
+ # validate no-bootloader option
+ if args.no_bootloader and output_format == 'bin':
+ print('--no-bootloader option requires the output format to be .hex')
+ exit(-1)
+
+ # validate that we can find a bootloader or no_bootloader is specified
+ bootloader = None
+ if not args.no_bootloader:
+ if args.mcu and not args.bootloader:
+ bl_list = glob("tools/mbed-bootloader-{}-*".format(args.mcu))
+ if len(bl_list) == 0:
+ print("Specified MCU does not have a binary in this location " + \
+ "Please specify bootloader location with -b")
+ exit(-1)
+ elif len(bl_list) > 1:
+ print("Specified MCU have more than one binary in this location " + \
+ "Please specify bootloader location with -b")
+ print(bl_list)
+ exit(-1)
+ else:
+ fname = bl_list[0]
+ bootloader = open(fname, 'rb')
+ elif args.bootloader:
+ bootloader = args.bootloader
+ elif not (args.mcu or args.bootloader):
+ print("Please specify bootloader location -b or MCU -m")
+ exit(-1)
+
+ # get the path of bootloader, application and output
+ if bootloader:
+ bootloader_fn = path.abspath(bootloader.name)
+ bootloader.close()
+ else:
+ bootloader_fn = ''
+
+ if bootloader_fn.split('.')[-1] != 'hex' and not args.mcu:
+ print("Please provide a bootloader in hex format or specify MCU -m")
+ exit(-1)
+
+ app_fn = path.abspath(args.app.name)
+ args.app.close()
+ output_fn = path.abspath(args.output.name)
+ args.output.close()
+
+ # Use specified addresses or default if none are provided
+ app_format = app_fn.split('.')[-1]
+ if(not (args.mcu or args.app_addr or app_format == 'hex')):
+ print("Please specify app address or MCU")
+ exit(-1)
+ if app_format != 'hex':
+ app_addr = args.app_addr or parse_mbed_app_addr(args.mcu, "target.mbed_app_start")
+ else:
+ app_addr = None
+
+ if args.mcu:
+ mem_start = addr_arg(bin_map[args.mcu]["mem_start"])
+ else:
+ mem_start = 0
+
+ if(not (args.mcu or args.header_addr)):
+ print("Please specify header address or MCU")
+ exit(-1)
+ header_addr = args.header_addr or parse_mbed_app_addr(args.mcu, "update-client.application-details")
+
+ # combine application and bootloader adding metadata info
+ combine(bootloader_fn, app_fn, app_addr, header_addr, mem_start,
+ output_fn, args.set_version, args.no_bootloader)
+
+ # print the output file path
+ print('Combined binary:' + output_fn)
Binary file tools/mbed-bootloader-k64f-block_device-sotp-v3_3_0.bin has changed
Binary file tools/mbed-bootloader-nucleo_f429zi-block_device-sotp-v3_3_0.bin has changed
Binary file tools/mbed-bootloader-ublox_evk_odin_w2-block_device-sotp-v3_3_0.bin has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/update_default_resources.c Fri May 11 16:15:18 2018 +0100
@@ -0,0 +1,41 @@
+// ----------------------------------------------------------------------------
+// Copyright 2016-2018 ARM Ltd.
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// ----------------------------------------------------------------------------
+
+#ifdef MBED_CLOUD_CLIENT_USER_CONFIG_FILE
+#include MBED_CLOUD_CLIENT_USER_CONFIG_FILE
+#endif
+
+#include <stdint.h>
+
+#ifdef MBED_CLOUD_DEV_UPDATE_ID
+const uint8_t arm_uc_vendor_id[16] = { "dev_manufacturer" };
+const uint16_t arm_uc_vendor_id_size = sizeof(arm_uc_vendor_id);
+
+const uint8_t arm_uc_class_id[16] = { "dev_model_number" };
+const uint16_t arm_uc_class_id_size = sizeof(arm_uc_class_id);
+#endif
+
+#ifdef MBED_CLOUD_DEV_UPDATE_CERT
+const uint8_t arm_uc_default_fingerprint[32] = { 0 };
+const uint16_t arm_uc_default_fingerprint_size =
+ sizeof(arm_uc_default_fingerprint);
+
+const uint8_t arm_uc_default_certificate[1] = { 0 };
+const uint16_t arm_uc_default_certificate_size =
+ sizeof(arm_uc_default_certificate);
+#endif
