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

Commit b66fc5d

Browse files
author
Janne Kiiskilä
committed
Simplify UPD and IPv4/IPv6 selections
Idea is that MESH has to have hard-coded IPv6 server address, because it does not have DNS capability. Other networks should have. Also, UDP must be used with MESH - other networks we want to default to TCP because it is typically more reliable (UDP gets closed due to firewalls). Thirdly, IPv4/IPv6 selection should now happen automatically through the mbed_app.json selections with no need to modify the .h-file anymore by modifying the "lwip.ipv4-enabled": false, "lwip.ipv6-enabled": true selections accordingly.
1 parent 0995cd3 commit b66fc5d

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ NanostackRfPhyMcr20a rf_phy(MCR20A_SPI_MOSI, MCR20A_SPI_MISO, MCR20A_SPI_SCLK, M
5757
#endif //MBED_CONF_APP_RADIO_TYPE
5858
#endif //MESH
5959

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

6869
RawSerial output(USBTX, USBRX);

simpleclient.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,23 @@
3838

3939
#define STRINGIFY(s) #s
4040

41-
//Select network stack mode: IPv4 or IPv6
42-
M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4;
41+
#if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true)
42+
// Mesh is always IPV6 - also WiFi and ETH can be IPV6 if IPV6 is enabled
43+
M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv6;
44+
#else
45+
// Everything else - we assume it's IPv4
46+
M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4;
47+
#endif
4348

44-
//Select binding mode: UDP or TCP
45-
M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP;
49+
//Select binding mode: UDP or TCP -- note - Mesh networking is IPv6 UDP ONLY
50+
#ifdef MESH
51+
M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP;
52+
#else
53+
// WiFi or Ethernet supports both - TCP by default to avoid
54+
// NAT problems, but UDP will also work - IF you configure
55+
// your network right.
56+
M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP;
57+
#endif
4658

4759

4860
// MBED_DOMAIN and MBED_ENDPOINT_NAME come
@@ -107,13 +119,6 @@ class MbedClient: public M2MInterfaceObserver {
107119
_server_address = server_address;
108120
uint16_t port = rand() % 65535 + 12345;
109121

110-
// In case of Mesh or Thread use M2MInterface::Nanostack_IPv6
111-
#if MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND
112-
NETWORK_STACK = M2MInterface::Nanostack_IPv6;
113-
#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
114-
NETWORK_STACK = M2MInterface::Nanostack_IPv6;
115-
#endif
116-
117122
// create mDS interface object, this is the base object everything else attaches to
118123
_interface = M2MInterfaceFactory::create_interface(*this,
119124
MBED_ENDPOINT_NAME, // endpoint name string

0 commit comments

Comments
 (0)