Mbed ublox ODIN W2 board: Multiple Connection to network (Cloud and webserver) at 1 time

Hi ,

I am having mbed ublox ODIN W2 board and working with mbedOS , i have connected it to wifi, and then connected to cloud, connection is established.

My requirement is periodically i need to Scan all wifi AP surrounding to me and send this data to my Web server, my observation is, once i have connected to Cloud, then i am not able to connect back to my WEB server.

Can we do this 2 connection at a time, as well as we can scan all wifi netwok.

Do you really need two connections?
If the “Cloud” means “Mbed Cloud”, the general data flow should be like: device => cloud => web server.
For your case, the device connect to cloud and register resources which is abstracted by WIFI AP data, device scan all wifi AP periodically and upload this data to cloud, web server fetch/subscribe this data from cloud via RestAPI/Cloud SDK.

Thank you terence,

for your Quick response.

Yes, I need 2 connection at one time, one to be connected to cloud, and one is with TCP socket open and close method whenever Needed. Is it possible at one time ???

My Current requirement:

  1. Device is always connected to Cloud, and In IDLE mode, and device is waiting for Trigger from the Cloud.

  2. When i Do click on cloud page for object 3336/0/5516, with POST method, i am getting this as a Wakeup trigger for my device, to come out from Idle mode to Normal working mode.

  3. In Normal mode, my Device connect to my webserver with network TCP socket and HTTP request message, once i get response from my Webserver, my device will just update 2 new values, and then i am closing my socket connection to webserver.

  4. I need to update this 2 new values to cloud.

Issue, in step-3 itself, I am not getting response back from my Webserver. I tested, My packet is proper., if i run my webserver connection code for 20 times in while loop, always i am getting response from my Webserver.

I doubt on: Once i connected to mbed Cloud, then i cannot connect back to another network, Is it Right ??

Approach 2: Suggested by you. device => cloud => web server.

If my above approach is not possible, then i can think on your approach.

Could you please provide me the way, how to Do it ?? is there is any Sample example available ??

Your quick response is Appreciated… Thank you in advance.

Best regards
Javed

I assume #3 request is to support multi socket: connect the same hot point, but create two sockets to different destination, and communication in parallel, I need some time to check.

Based on your detail description, I still recommend my approach which is more general and better performance:
I saw #2 you already implemented the remote control via 3336/0/5516:
So what you need to do to replace #3 is:
a. create another object/resource like what you did in #2 and upload data, only difference is the data transfer direction.
b. Add simple code in your web server to fetch the data from cloud

There is a quick start document for your reference: https://cloud.mbed.com/docs/v1.2/quick-start/index.html

Thank you terence,

our Implementation is 99 % ready, and we cant go back to new approach.

I just want to know,

  1. How IOT device is communicating to cloud, is it with Socket or as a HTTP client ???

  2. as you mentioned about creating 2 different socket, does it possible in my case with Cloud and Web server ??

  3. Yes we need 2 connection at one time with same Hot-spot (Access Point), i assume for cloud connection, existing API is using predefined socket, and i am using new socket whenever i want to communicate with my WEB server, and once work done i am closing it.

So it should work…

note: Just FYI

when i get trigger from cloud, my Device will gather data (time taken approx 7 sec) and , I am submitting around 300 bytes of data packet to my WEB server which will process (time taken is approx 8 sec) on that data and then i will get response from web server as only 50 bytes. by which i am updating 2 resource ID (5514 and 5516) on Cloud .

Got it, so let’s back to your problem firstly, we can talk others later.
Did you try to close the cloud connection before connect web server? could you share the code in github?

Sorry Terence,

we are using Existing code from mbed ARM, and expanding it.

Anyhow, could you please explain me about following questions:

  1. How IOT device is communicating to cloud, is it with Socket or as a HTTP client ???

  2. Is it required to really close Cloud Connection before connecting to Web server ??

as you said earlier , i can use 2 different Socket for this purpose, can u plz explain with any sample example, how i can do it. ??

FYI:

As soon as I get trigger from cloud, i am closing my cloud connection with API:

       //Close Existing CLOUD Connection
         client->close();
         free(client);

My Working Enviornment:

Wi-Fi Dev Board: follow link : Mbed Connect Cloud | Mbed

Mbed Cloud Connect starter KIT Board (Ublox EVK ODIN W262 MCU ) and Windows mbed_installer_v041

Code: Existing mbed-connect-cloud-application code from ARM mbed.

Do you have this code with you ??

any how i am attaching my main.cpp file.

As you know in my main (),

  1. Connecting to wife network

  2. Then i am connecting to my Web-server with Http POST: open TCP socket getting new data, Closing socket.
    Note: if i kept same code in while(1), to get data from Web-server, without connection to cloud. working properly.

  3. Connecting to cloud with
    client = new SimpleM2MClient(network, &sd, &fs);
    client->on_registered(&registered_cb);
    int init_rt = client->init();

  4. Connected to cloud, and Updating new data from step-2, to cloud page.

  5. All is done well.

                                     Issue Start Here: Reconnecting back to Web server.
    
  6. after some time again, let say after 10 min, if i want to get new data from Webserver and update it to cloud, I am Not able to connect back to My Webserver.

Please find the google drive link for main.cpp file:

can not attach a C / txt file, only allowed format is JPEG/JPG/PNG

if possible, please modify my code.

hi terence,

I got the reason behind it, please refer the image, module limitation.

please recheck it and confirm.

I think as you suggested, we need to use 2 different socket,

could you please answer my all open questions from previous reply.
https://os.mbed.com/platforms/ublox-EVK-ODIN-W2/#example-code

The limitation only impact that you could not connect two wifi network, but two socket connection is still possible.

  1. It is based on socket: TCP/UDP => COAP => LWM2M
  2. Depend on the connection type to you web server, if it is also based on socket, multi sockets support should be enough for you
  3. Yes, I have the code, I assume you are using the cloud board from mbed connect, isn’t it?
  4. About the attached main.cpp, could you add below chagne and try again:
    a. wait(osWaitForever); in the end of main_loop();
    b. “mbed-trace.enable”: true in mbed_app.json please provide the full log.
    Please catch the full log during your verification.