This is a simple mbed client example demonstrating, registration of a device with mbed Device Connector and reading and writing values as well as deregistering on different Network Interfaces including Ethernet, WiFi, 6LoWPAN ND and Thread respectively.
Fork of mbed-os-example-client by
Diff: simpleclient.h
- Revision:
- 42:d9a3043214a6
- Parent:
- 37:9a9428fc4b26
- Child:
- 43:90fccf21be20
diff -r 496e5ec1f1bd -r d9a3043214a6 simpleclient.h --- a/simpleclient.h Sat Dec 10 22:30:09 2016 +0000 +++ b/simpleclient.h Sun Dec 11 08:15:09 2016 +0000 @@ -38,11 +38,23 @@ #define STRINGIFY(s) #s -//Select network stack mode: IPv4 or IPv6 -M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4; +#if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) + // Mesh is always IPV6 - also WiFi and ETH can be IPV6 if IPV6 is enabled + M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv6; +#else + // Everything else - we assume it's IPv4 + M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4; +#endif -//Select binding mode: UDP or TCP -M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP; +//Select binding mode: UDP or TCP -- note - Mesh networking is IPv6 UDP ONLY +#ifdef MESH + M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP; +#else + // WiFi or Ethernet supports both - TCP by default to avoid + // NAT problems, but UDP will also work - IF you configure + // your network right. + M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP; +#endif // MBED_DOMAIN and MBED_ENDPOINT_NAME come @@ -107,13 +119,6 @@ _server_address = server_address; uint16_t port = rand() % 65535 + 12345; - // In case of Mesh or Thread use M2MInterface::Nanostack_IPv6 -#if MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND - NETWORK_STACK = M2MInterface::Nanostack_IPv6; -#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD - NETWORK_STACK = M2MInterface::Nanostack_IPv6; -#endif - // create mDS interface object, this is the base object everything else attaches to _interface = M2MInterfaceFactory::create_interface(*this, MBED_ENDPOINT_NAME, // endpoint name string