ARMmbed / mbed-os-example-client

DEPRECATED: This is the mbed Client example application for mbed OS.
https://cloud.mbed.com/docs/current/welcome/index.html
Other
20 stars 58 forks source link

Problem for connecting to mDS #46

Closed SYuPing closed 8 years ago

SYuPing commented 8 years ago

Hi, I want to connect to local mDS instead of mDC because my contry do not support for IPv6 connectitvity... So, I did some change in main code as follow,

  1. coaps://[2607:f0d0:2601:52::20]:5684 TO "coap://FD00:FF1:CE0B:A5E0::1:5683" <--local mDS static address
  2. security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate); TO security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity); and rebuild project...

But... There's a bit confusing for me is where gatewayThreadStatic.bin comes from, and I've done two testing process...

First, I copied that from the lateset "mbed-os-example-client/ GW_Binary", after loaded to Gatway Router, and the meassage shows on Putty terminal is

Starting mbed Client example... Using Mesh

Connecting to Mesh..

Connected to Network successfully

No IP address

SOCKET_MODE : UDP Connecting to coap://FD00:FF1:CE0B:A5E0::1:5683

The other gatewayThreadStatic.bin comes from "mbed-client-example-6lowpan-device_server/ GW_Binary" which version is mbed-os 3.0, and the message shows on Putty is

Starting mbed Client example... Using Mesh

Connecting to Mesh..

Connected to Network successfully

IP address fd00:ff1:ce0b:a5e0:fcc2:3d00:4:b74d

SOCKET_MODE : UDP Connecting to coap://FD00:FF1:CE0B:A5E0::1:5683

The two results are different, and both fail to connect to mDS, I don't know what the problem is, could someone help me to solve this?

Many thanks.

yogpan01 commented 8 years ago

@hasnainvirk Can you check this please? @SYuPing : What are your endpoint credentials ? ENDPOINT_NAME and DOMAIN values , because you are not using Connector, what values are you providing there ?

SYuPing commented 8 years ago

Hi, The ENDPOINT_NAME is "822e461e-5580-4522-91df-e96b0230f879" and DOMAIN value is "40c8e96d-e5b8-4d5b-a49c-c3f7cbe399ee", which are copied from security.h is getten on mDC, is it uncorrect?

Thanks.

ciarmcom commented 8 years ago

ARM Internal Ref: IOTCLT-877

yogpan01 commented 8 years ago

If you are using local device server , you need to use DOMAIN value as "domain"

SYuPing commented 8 years ago

Hi, I've tried some steps as follow but still can't connect.....

  1. Change DOMAIN value to #define MBED_DOMAIN "domain" in security.h
  2. Change security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate); TO security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity); in simpleclient.h #L144
  3. Change “uint16_t port = rand() % 65535 + 12345;” to “uint16_t port = 5683;” in simpleclient.h #L95
  4. Change 1. coaps://[2607:f0d0:2601:52::20]:5684 TO "coap://FD00:FF1:CE0B:A5E0::1:5683" in main.cpp #L55

And the executed log is:

Starting mbed Client example... Using Mesh

Connecting to Mesh..

Connected to Network successfully IP address fd00:ff1:ce0b:a5e0:fcc2:3d00:4:b74d

SOCKET_MODE : UDP Connecting to coaps://[2607:f0d0:2601:52::20]:5684

[ERROR:] M2MInterface::SecureConnectionFailed

Many thanks....

SYuPing commented 8 years ago

Sorry, the message "Connecting to coaps://[2607:f0d0:2601:52::20]:5684" in log is wrong. It's my fault to check that when I paste it. Which correct log message is:

Starting mbed Client example... Using Mesh

Connecting to Mesh..

Connected to Network successfully IP address fd00:ff1:ce0b:a5e0:fcc2:3d00:4:b74d

SOCKET_MODE : UDP Connecting to coap://FD00:FF1:CE0B:A5E0::1:5683

[ERROR:] M2MInterface::NetworkError

Where the code I changed is as below,

In main.cpp

ifndef MESH

// This is address to mbed Device Connector

define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"

else

// This is address to mbed Device Connector #define MBED_SERVER_ADDRESS "coap://FD00:FF1:CE0B:A5E0::1:5683"

endif

In security.h

#define MBED_DOMAIN "domain"

define MBED_ENDPOINT_NAME "822e461e-5580-4522-91df-e96b0230f879"

In simpleclient.h

void create_interface(const char server_address, void handler=NULL) { // Randomizing listening port for Certificate mode connectivity _server_address = server_address; srand(time(NULL));

uint16_t port = 5683;

and

if(security) { // Add ResourceID's and values to the security ObjectID/ObjectInstance security->set_resource_value(M2MSecurity::M2MServerUri, _server_address); security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity); security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT)); security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT)); security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY)); }

SYuPing commented 8 years ago

Hi,

When the changed above confige to be 6lowpan-ND and connected with another k64f board which code is used k64f-border-router could connect to mDS.

What I mean is that I used k64f board+6lowpan shield which downloaded k64f-border-router example to be a BR to represent gayway router. It could connected to mDS sucessfully.

But in thread mode + gateway still failed...

yogpan01 commented 8 years ago

@hasnainvirk Can you please check this ?

SYuPing commented 8 years ago

Here is my mbed_app.json file

{ "config": { "network-interface":{ "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", "value": "MESH_THREAD" }, "wifi-ssid": { "help": "WiFi SSID", "value": "\"SSID\"" }, "wifi-password": { "help": "WiFi Password", "value": "\"Password\"" } }, "target_overrides": { "*": { "mbed-mesh-api.thread-config-channel-page": 0, "mbed-mesh-api.thread-config-channel": 12, "target.features_add": ["CLIENT", "IPV6", "COMMON_PAL"], "mbed-trace.enable": 1, "mbed-client.reconnection-count": 3, "mbed-client.reconnection-interval": 5 } } }

hasnainvirk commented 8 years ago

@SYuPing I tried a similar setup like you. And I was able to get connected. Can you please have a Skype session with me to look at what you are doing ? Please contact me at, skypeID = husnain.virk

hasnainvirk commented 8 years ago

@SYuPing My setup:

mbed-Gateway with Thread Static binary loaded(from this repo) K64F with Atmel-RF –Shield and mbed-os-example-client loaded on it mbed Device Server 3.1.0

Things I did differently :

In main.cpp:

#define MBED_SERVER_ADDRESS "coap://[fd00:ff1:ce0b:a5e0::1]:5683"

In simpleclient.h:

/*You need this port randomization. You can set here the port to be 5683*/
uint16_t port = rand() % 65535 + 12345;

On my laptop running mDS:

# You need to make your laptop accept router advertisements, 
# so that you can establish routing between your mDS and border router 
sudo sysctl -w net.ipv6.conf.eth0.accept_ra=1
SYuPing commented 8 years ago

Hi,

I still could not connect sucessfully after I followed your step...

BTW, My mDS is running on windows OS not linux...Is it effect? Should I still type some command on my dos command line?

Thanks a lot

hasnainvirk commented 8 years ago

@SYuPing Can you try this on windows

netsh interface ipv6 set interface "Local Area Connection" advertise=enabled

SYuPing commented 8 years ago

What I tried is netsh interface ipv6 set interface "區域連線 2" advertise=enabled The chinese I typed "區域連線 2" is the name of Local Area Connection in my computer but....it still failed... The version of mDS server what I used is 3.0.6

hasnainvirk commented 8 years ago

@SYuPing

I tried with Windows OS and I found out that the Windows Firewall was blocking all traffic on outgoing ports from Windows to BR.

Please follow the following instructions to get your issue resolved:

  1. Open Windows Firewall Settings (Control Panel->System & Security->Windows Firewall)
  2. Click on Advanced Settings in the left pane.
  3. Click on Inbound Rules in the left pane.
  4. Click on the New Rule in the right pane.
  5. In the Rule Type window, choose Port and click next.
  6. In the Protocol and Ports window, choose UDP and Specific local ports. Write ‘5683’ in the text section. Click next.
  7. In New Inbound Rule Wizard window, choose Allow the connection and click next.
  8. In Profile Window, check All and click next.
  9. In Name window, give your rule a name and give a little description

Now you should be able to see get your traffic from mDS through. Please close the issue if you are satisfied.

SYuPing commented 8 years ago

It can work after I changed the gateway code "gatewayThreadStatic.bin" which updated date is 8/19. The problem seems like the version of gatewayThreadStatic.bin file. No metter what the code I used is copied from you this week or three weeks ago which I chagned refer to your steps, both are workable now. But when I change the gateway code "gatewayThreadStatic.bin" back to 8/19 before (exctly date: 8/1), the problem shows up and both of two can't work...

The problem seems like that the version of gateway binary code is different...

Now, it is workable when I used this version of gateway binary (updated date: 8/19), and thanks for your help.

Close this issue.