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

Commit 5d7f230

Browse files
committed
Reduce String use
Optimise - don't use String class unnecessarily.
1 parent f046c0f commit 5d7f230

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Diff for: main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ ThreadInterface mesh;
5959
#define HEAP_SIZE 1023
6060
static uint8_t app_stack_heap[HEAP_SIZE + 1];
6161
// This is address to mbed Device Connector
62-
const String &MBED_SERVER_ADDRESS = "coap://api.connector.mbed.com:5684";
62+
#define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
6363
#else
6464
// This is address to mbed Device Connector
65-
const String &MBED_SERVER_ADDRESS = YOTTA_CFG_DEVICE_CONNECTOR_URI;
65+
#define MBED_SERVER_ADDRESS YOTTA_CFG_DEVICE_CONNECTOR_URI
6666
#endif
6767

6868
Serial output(USBTX, USBRX);

Diff for: simpleclient.h

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

34-
// These come from the security.h file copied from connector.mbed.com
35-
const String &MBED_USER_NAME_DOMAIN = MBED_DOMAIN;
36-
const String &ENDPOINT_NAME = MBED_ENDPOINT_NAME;
34+
// MBED_DOMAIN and MBED_ENDPOINT_NAME come
35+
// from the security.h file copied from connector.mbed.com
3736

3837
struct MbedClientDevice {
3938
const char* Manufacturer;
@@ -44,7 +43,7 @@ struct MbedClientDevice {
4443

4544
/*
4645
* Wrapper for mbed client stack that handles all callbacks, error handling, and
47-
* other schenanigans to make the mbed client stack easier to use.
46+
* other shenanigans to make the mbed client stack easier to use.
4847
*
4948
* The end user should only have to care about configuring the parameters at the
5049
* top of this file and making sure they add the security.h file correctly.
@@ -88,7 +87,7 @@ class MbedClient: public M2MInterfaceObserver {
8887
* setup its name, resource type, life time, connection mode,
8988
* Currently only LwIPv4 is supported.
9089
*/
91-
void create_interface(const String &server_address,
90+
void create_interface(const char *server_address,
9291
void *handler=NULL) {
9392
// Randomizing listening port for Certificate mode connectivity
9493
_server_address = server_address;
@@ -97,18 +96,17 @@ class MbedClient: public M2MInterfaceObserver {
9796

9897
// create mDS interface object, this is the base object everything else attaches to
9998
_interface = M2MInterfaceFactory::create_interface(*this,
100-
ENDPOINT_NAME, // endpoint name string
99+
MBED_ENDPOINT_NAME, // endpoint name string
101100
"test", // endpoint type string
102101
100, // lifetime
103102
port, // listen port
104-
MBED_USER_NAME_DOMAIN, // domain string
103+
MBED_DOMAIN, // domain string
105104
SOCKET_MODE, // binding mode
106105
M2MInterface::LwIP_IPv4, // network stack
107106
""); // context address string
108-
String binding_mode;
109-
(SOCKET_MODE == M2MInterface::UDP) ? binding_mode = "UDP" : binding_mode = "TCP";
110-
printf("\r\nSOCKET_MODE : %s\r\n", binding_mode.c_str());
111-
printf("Connecting to %s\r\n", _server_address.c_str());
107+
const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP";
108+
printf("\r\nSOCKET_MODE : %s\r\n", binding_mode);
109+
printf("Connecting to %s\r\n", server_address);
112110

113111
if(_interface) {
114112
_interface->set_platform_network_handler(handler);

0 commit comments

Comments
 (0)