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

Simplify UPD and IPv4/IPv6 selections #139

Merged
merged 1 commit into from
Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, M
#endif //MBED_CONF_APP_RADIO_TYPE
#endif //MESH

#ifndef MESH
// This is address to mbed Device Connector
#define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
#ifdef MESH
// Mesh does not have DNS, so must use direct IPV6 address
#define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684"
#else
// This is address to mbed Device Connector
#define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684"
// This is address to mbed Device Connector, name based
// assume all other stacks support DNS properly
#define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
#endif

RawSerial output(USBTX, USBRX);
Expand Down
27 changes: 16 additions & 11 deletions simpleclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,13 +119,6 @@ class MbedClient: public M2MInterfaceObserver {
_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
Expand Down