1
1
// ----------------------------------------------------------------------------
2
- // Copyright 2016-2019 ARM Ltd.
2
+ // Copyright 2016-2020 ARM Ltd.
3
3
//
4
4
// SPDX-License-Identifier: Apache-2.0
5
5
//
21
21
#include " mbed-cloud-client/MbedCloudClient.h" // Required for new MbedCloudClient()
22
22
#include " factory_configurator_client.h" // Required for fcc_* functions and FCC_* defines
23
23
#include " m2mresource.h" // Required for M2MResource
24
+ #include " key_config_manager.h" // Required for kcm_factory_reset
24
25
25
26
#include " mbed-trace/mbed_trace.h" // Required for mbed_trace_*
26
27
@@ -36,6 +37,8 @@ static M2MResource* m2m_get_res;
36
37
static M2MResource* m2m_put_res;
37
38
static M2MResource* m2m_post_res;
38
39
static M2MResource* m2m_deregister_res;
40
+ static M2MResource* m2m_factory_reset_res;
41
+ static SocketAddress sa;
39
42
40
43
EventQueue queue (32 * EVENTS_EVENT_SIZE);
41
44
Thread t;
@@ -98,6 +101,14 @@ void client_unregistered(void)
98
101
cloud_client_running = false ;
99
102
}
100
103
104
+ void factory_reset (void *)
105
+ {
106
+ printf (" POST factory reset executed\n " );
107
+ m2m_factory_reset_res->send_delayed_post_response ();
108
+
109
+ kcm_factory_reset ();
110
+ }
111
+
101
112
void client_error (int err)
102
113
{
103
114
printf (" client_error(%d) -> %s\n " , err, cloud_client->error_description ());
@@ -139,8 +150,12 @@ int main(void)
139
150
printf (" NetworkInterface failed to connect with %d\n " , status);
140
151
return -1 ;
141
152
}
142
-
143
- printf (" Network initialized, connected with IP %s\n\n " , network->get_ip_address ());
153
+ status = network->get_ip_address (&sa);
154
+ if (status!=0 ) {
155
+ printf (" get_ip_address failed with %d\n " , status);
156
+ return -2 ;
157
+ }
158
+ printf (" Network initialized, connected with IP %s\n\n " , sa.get_ip_address ());
144
159
145
160
// Run developer flow
146
161
printf (" Start developer flow\n " );
@@ -202,6 +217,12 @@ int main(void)
202
217
return -1 ;
203
218
}
204
219
220
+ // optional Device resource for running factory reset for the device. Path of this resource will be: 3/0/6.
221
+ m2m_factory_reset_res = M2MInterfaceFactory::create_device ()->create_resource (M2MDevice::FactoryReset);
222
+ if (m2m_factory_reset_res) {
223
+ m2m_factory_reset_res->set_execute_function (factory_reset);
224
+ }
225
+
205
226
printf (" Register Pelion Device Management Client\n\n " );
206
227
207
228
#ifdef MBED_CLOUD_CLIENT_SUPPORT_UPDATE
@@ -224,7 +245,7 @@ int main(void)
224
245
} else if (in_char == ' r' ) {
225
246
(void ) fcc_storage_delete (); // When 'r' is pressed, erase storage and reboot the board.
226
247
printf (" Storage erased, rebooting the device.\n\n " );
227
- wait ( 1 );
248
+ ThisThread::sleep_for ( 1 * 1000 );
228
249
NVIC_SystemReset ();
229
250
} else if (in_char > 0 && in_char != 0x03 ) { // Ctrl+C is 0x03 in Mbed OS and Linux returns negative number
230
251
value_increment (); // Simulate button press
0 commit comments