Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit a7f6def

Browse files
Yogesh PandeYogesh Pande
Yogesh Pande
authored and
Yogesh Pande
committed
Fix for Connector URI and update mbed-os.lib
1 parent 9684992 commit a7f6def

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

main.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ ThreadInterface mesh;
5858

5959
#define HEAP_SIZE 1023
6060
static uint8_t app_stack_heap[HEAP_SIZE + 1];
61+
// This is address to mbed Device Connector
62+
const String &MBED_SERVER_ADDRESS = "coap://api.connector.mbed.com:5684";
63+
#else
64+
// This is address to mbed Device Connector
65+
const String &MBED_SERVER_ADDRESS = YOTTA_CFG_DEVICE_CONNECTOR_URI;
6166
#endif
6267

63-
6468
Serial output(USBTX, USBRX);
6569

6670
// These are example resource values for the Device Object
@@ -170,7 +174,7 @@ class LedResource {
170174
*/
171175
class ButtonResource {
172176
public:
173-
ButtonResource(){
177+
ButtonResource(): counter(0) {
174178
// create ObjectID with metadata tag of '3200', which is 'digital input'
175179
btn_object = M2MInterfaceFactory::create_object("3200");
176180
M2MObjectInstance* btn_inst = btn_object->create_object_instance();
@@ -213,7 +217,7 @@ class ButtonResource {
213217

214218
private:
215219
M2MObject* btn_object;
216-
uint16_t counter = 0;
220+
uint16_t counter;
217221
};
218222

219223
// Network interaction must be performed outside of interrupt context
@@ -307,7 +311,7 @@ int main() {
307311
obs_button.fall(&button_clicked);
308312

309313
// Create endpoint interface to manage register and unregister
310-
mbed_client.create_interface(network_stack);
314+
mbed_client.create_interface(MBED_SERVER_ADDRESS, network_stack);
311315

312316
// Create Objects of varying types, see simpleclient.h for more details on implementation.
313317
M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info

mbed-os.lib

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os.git/#c4986eed9f42cbb3352c793d7a16d512d978d102
1+
https://github.com/ARMmbed/mbed-os/#77c8e885e91f3b2504335f7221dcc551547b76d3

simpleclient.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
//Select binding mode: UDP or TCP
3232
M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP;
3333

34-
// This is address to mbed Device Connector
35-
const String &MBED_SERVER_ADDRESS = YOTTA_CFG_DEVICE_CONNECTOR_URI;
36-
3734
// These come from the security.h file copied from connector.mbed.com
3835
const String &MBED_USER_NAME_DOMAIN = MBED_DOMAIN;
3936
const String &ENDPOINT_NAME = MBED_ENDPOINT_NAME;
@@ -91,8 +88,10 @@ class MbedClient: public M2MInterfaceObserver {
9188
* setup its name, resource type, life time, connection mode,
9289
* Currently only LwIPv4 is supported.
9390
*/
94-
void create_interface(void *handler=NULL) {
91+
void create_interface(const String &server_address,
92+
void *handler=NULL) {
9593
// Randomizing listening port for Certificate mode connectivity
94+
_server_address = server_address;
9695
srand(time(NULL));
9796
uint16_t port = rand() % 65535 + 12345;
9897

@@ -109,7 +108,7 @@ class MbedClient: public M2MInterfaceObserver {
109108
String binding_mode;
110109
(SOCKET_MODE == M2MInterface::UDP) ? binding_mode = "UDP" : binding_mode = "TCP";
111110
printf("\r\nSOCKET_MODE : %s\r\n", binding_mode.c_str());
112-
printf("Connecting to %s\r\n", MBED_SERVER_ADDRESS.c_str());
111+
printf("Connecting to %s\r\n", _server_address.c_str());
113112

114113
if(_interface) {
115114
_interface->set_platform_network_handler(handler);
@@ -143,7 +142,7 @@ class MbedClient: public M2MInterfaceObserver {
143142
// make sure security ObjectID/ObjectInstance was created successfully
144143
if(security) {
145144
// Add ResourceID's and values to the security ObjectID/ObjectInstance
146-
security->set_resource_value(M2MSecurity::M2MServerUri, MBED_SERVER_ADDRESS);
145+
security->set_resource_value(M2MSecurity::M2MServerUri, _server_address);
147146
security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate);
148147
security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT));
149148
security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT));
@@ -326,6 +325,7 @@ class MbedClient: public M2MInterfaceObserver {
326325
volatile bool _unregistered;
327326
int _value;
328327
struct MbedClientDevice _device;
328+
String _server_address;
329329
};
330330

331331
#endif // __SIMPLECLIENT_H__

0 commit comments

Comments
 (0)