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:
- 21:b88cdeb5b302
- Parent:
- 19:91eb6f58fd77
- Child:
- 31:218ca6b6fe19
--- a/simpleclient.h Wed Oct 05 05:15:22 2016 +0100 +++ b/simpleclient.h Fri Oct 21 09:30:10 2016 +0100 @@ -25,12 +25,26 @@ #include "mbed-client/m2mobjectinstance.h" #include "mbed-client/m2mresource.h" #include "mbed-client/m2mconfig.h" +#include "mbed-client/m2mblockmessage.h" #include "security.h" #include "mbed.h" +#define ETHERNET 1 +#define WIFI 2 +#define MESH_LOWPAN_ND 3 +#define MESH_THREAD 4 +#define ATMEL 5 +#define MCR20 6 + +#define STRINGIFY(s) #s + +//Select network stack mode: IPv4 or IPv6 +M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4; + //Select binding mode: UDP or TCP M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP; + // MBED_DOMAIN and MBED_ENDPOINT_NAME come // from the security.h file copied from connector.mbed.com @@ -89,9 +103,16 @@ */ void create_interface(const char *server_address, void *handler=NULL) { - // Randomizing listening port for Certificate mode connectivity + // Randomizing listening port for Certificate mode connectivity _server_address = server_address; - uint16_t port = rand() % 65535 + 12345; + 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, @@ -101,7 +122,7 @@ port, // listen port MBED_DOMAIN, // domain string SOCKET_MODE, // binding mode - M2MInterface::LwIP_IPv4, // network stack + NETWORK_STACK, // network stack ""); // context address string const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP"; printf("\r\nSOCKET_MODE : %s\r\n", binding_mode); @@ -213,7 +234,7 @@ void object_unregistered(M2MSecurity */*server_object*/){ trace_printer("Unregistered Object Successfully"); _unregistered = true; - _registered = false; + _registered = false; } /*