31
31
// Select binding mode: UDP or TCP
32
32
M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP;
33
33
34
- // This is address to mbed Device Connector
35
- const String &MBED_SERVER_ADDRESS = YOTTA_CFG_DEVICE_CONNECTOR_URI;
36
-
37
34
// These come from the security.h file copied from connector.mbed.com
38
35
const String &MBED_USER_NAME_DOMAIN = MBED_DOMAIN;
39
36
const String &ENDPOINT_NAME = MBED_ENDPOINT_NAME;
@@ -91,8 +88,10 @@ class MbedClient: public M2MInterfaceObserver {
91
88
* setup its name, resource type, life time, connection mode,
92
89
* Currently only LwIPv4 is supported.
93
90
*/
94
- void create_interface (void *handler=NULL ) {
91
+ void create_interface (const String &server_address,
92
+ void *handler=NULL ) {
95
93
// Randomizing listening port for Certificate mode connectivity
94
+ _server_address = server_address;
96
95
srand (time (NULL ));
97
96
uint16_t port = rand () % 65535 + 12345 ;
98
97
@@ -109,7 +108,7 @@ class MbedClient: public M2MInterfaceObserver {
109
108
String binding_mode;
110
109
(SOCKET_MODE == M2MInterface::UDP) ? binding_mode = " UDP" : binding_mode = " TCP" ;
111
110
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 ());
113
112
114
113
if (_interface) {
115
114
_interface->set_platform_network_handler (handler);
@@ -143,7 +142,7 @@ class MbedClient: public M2MInterfaceObserver {
143
142
// make sure security ObjectID/ObjectInstance was created successfully
144
143
if (security) {
145
144
// 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 );
147
146
security->set_resource_value (M2MSecurity::SecurityMode, M2MSecurity::Certificate);
148
147
security->set_resource_value (M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof (SERVER_CERT));
149
148
security->set_resource_value (M2MSecurity::PublicKey, CERT, sizeof (CERT));
@@ -326,6 +325,7 @@ class MbedClient: public M2MInterfaceObserver {
326
325
volatile bool _unregistered;
327
326
int _value;
328
327
struct MbedClientDevice _device;
328
+ String _server_address;
329
329
};
330
330
331
331
#endif // __SIMPLECLIENT_H__
0 commit comments