3131// Select binding mode: UDP or TCP
3232M2MInterface::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
3835const String &MBED_USER_NAME_DOMAIN = MBED_DOMAIN;
3936const 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\n SOCKET_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