This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Multiple SPP Connections

A while ago I have posted a question in regards to multiple SPP connections.

I have received reply from StoneStreetOne with a new library and code to convert the current demo into one that can accept multiple connections. Shortly after, the post was removed due to the fact that they didn't want to post code files in this forum.

I have more questions in regards to this post, and I have tried to email their support directly, but received no response. Can anyone help?

This was my email to them:

"I have received a new library complied for CCS and a new SPPLEDemo.c file. I have replaced the files for the demo project, and it is successfully working with more than one connection. I have already developed a software that is based on the lite version of the demo. Basically I have a simple software that is automatically running the server and is ready for connection (as the lite version does). what I have added was a communication protocol for exchanging messages. In that sense, it was fairly easy to adapt the lite version to my needs.

Now I would like to have the same thing, but to add the option for multiple connections. I have tried to understand new file that supports the multi-connections, but it was too difficult to follow all the changes.
Can you provide me with a similar file for the lite version, or a guidance on how I should add that support to my current project."
Thank you,
Guy
  • Hello Guy,

    The code that you have needs a new lib as it invokes a function in L2CAP that was not present in the old lib. This helps to change roles at connection time. But it also may mean that you will not be able to connect to a remote device if it does not allow role change. 

    We have added new code that works around this by invoking an explicit role switch *after* you are connected. The code and some information explaining the changes has been added to 

    http://processors.wiki.ti.com/index.php/CC256x_Bluetopia_Software_Add-on:_Multiple_SPP_Connections

    Please go through it and we hope it helps to understand the changes better. We can use this page to discuss multiple SPP connections further and it will also give us a chance to improve the information on that page using feedback from customers. 

    Best Regards,

    Stonestreet One. 

  • We also would like to add that you should use the library that  is included with the release with this sample code.  

    Best Regards,

    Stonestreet One. 

  • Thank you for your response and help.

    I have tried the new code, and was trying to connect two Android phones using BlueTerm.

    I started by choosing the "Server" role, and next "Open 1". I can connect one phone all right, and I get the message "Initiating Role Switch."

    Now, I am not sure what to do next. Whatever I tried didn't work. Previously I was told to "Open 1" again. What should I do next in order to open another server/port for the second phone?

    By the way, would you prefer to have this discussion in the wiki site?

    Thank you

  • Hi Guy,

    We can discuss here and there we will summarize the discussions on the wiki page.

    Yes, you will have to Open another server. Every open server can service only one client. As you can see, the API does not have any number of client connections supported parameter and it is one for each server. For every connection you will have to open a new server. You can keep the server port the same or change it. Keeping it same  will help for the same application in case the client devices cache the server port to connect to. 

    So you should "Open 1". You will get a PortID that is distinct from the other port and this is your local alias for this server port context. A second client connecting to this new server will give you a port open indication on this port id. You will have to write to the port ID corresponding to the specific remote device when you want to choose which remote device to send data to. 

    Hope this helps.

    Stonestreet One. 

  • Here is the terminal output I get. I open one server, connect with a device, then open second server successfully, but when I try to connect with second device it fails.

    I get "Alloc Failed: 70 Alloc Failed: 28" upon second connection attempt.

    I might be doing something wrong...

    SPP+LE>open 1
    Server Opened: 1.
    Server Port Context Stored.

    SPP+LE>
    atLinkKeyRequest: 0xD8952FE283B9
    GAP_Authentication_Response success.

    SPP+LE>
    atPINCodeRequest: 0xD8952FE283B9
    Respond with: PINCodeResponse

    SPP+LE>pincoderesponse 0
    GAP_Authentication_Response(), Pin Code Response Success.

    SPP+LE>
    atLinkKeyCreation: 0xD8952FE283B9
    Link Key Stored.

    SPP+LE>
    SPP Open Indication, ID: 0x0001, Board: 0xD8952FE283B9.

    Initiating Role Switch.

    SPP+LE>open 1
    Server Opened: 1.
    Server Port Context Stored.

    SPP+LE>Alloc Failed: 70
    Alloc Failed: 28

  • Hi Guy,

    This issue is due to the fact that the memory on the device is optimised for single server operation. To use multiple servers, you will need to bump up the memory. To change the memory in IAR go to Project->Options->C/C++ Compiler->Preprocessor. In the list of defined symbols you will find

    BTPS_MEMORY_BUFFER_SIZE=3600.

     

    You need to set this to a higher value depending on your requirements. Try something like 9600 and see if that works for you.

    Note: If you are using CCS, click on the Project->Properites->Advanced options->Predefined Symbols to access the same option.

    We will add a note in the wiki for this.

    Best Regards,

    Stonestreet One.

     

  • I am using CCS, and I have changed the 3600 to 9600. It seems to be working well.

    One thing, at one point I get "Link Key array full.", is that ok?

    This is my output:

    SPP+LE>open 1
    Server Opened: 1.
    Server Port Context Stored.

    SPP+LE>
    atLinkKeyRequest: 0xD8952FE283B9
    GAP_Authentication_Response success.

    SPP+LE>
    atPINCodeRequest: 0xD8952FE283B9
    Respond with: PINCodeResponse

    SPP+LE>pincoderesponse 0
    GAP_Authentication_Response(), Pin Code Response Success.

    SPP+LE>
    atLinkKeyCreation: 0xD8952FE283B9
    Link Key Stored.

    SPP+LE>
    SPP Open Indication, ID: 0x0001, Board: 0xD8952FE283B9.

    Initiating Role Switch.

    SPP+LE>open 1
    Server Opened: 1.
    Server Port Context Stored.

    SPP+LE>
    atLinkKeyRequest: 0xB0EC7100D31D
    GAP_Authentication_Response success.

    SPP+LE>
    atPINCodeRequest: 0xB0EC7100D31D
    Respond with: PINCodeResponse

    SPP+LE>pincoderesponse 0
    GAP_Authentication_Response(), Pin Code Response Success.

    SPP+LE>
    atLinkKeyCreation: 0xB0EC7100D31D
    Link Key array full.

    SPP+LE>
    SPP Open Indication, ID: 0x0002, Board: 0xB0EC7100D31D.

    Initiating Role Switch.

  • Guy,

    Please change MAX_SUPPORTED_LINK_KEYS to the number of simultaneous connections that you want to support. Right now, it is set for only one. Thanks for pointing that out, we will make a note for that on the wiki as well. 

    You want the application to remember Link keys for all the devices that you want to communicate with in a session. If you want the pairing information to survive a power cycle, you would write this Link key info structure to the flash and the app will read from flash and populate the local structure on next power up.

    Hope this helps.

    Stonestreet One.  

  • Thank you for all your help. This seems to work great.

    I have already developed a small application that was using the lite demo example. Now I want to have a multi-connection support.

    What would be easier to do, adding multi-connection capabilities to the lite demo, or make this full demo, to operate as the lite demo.

    What I am basically looking for, is a software that would run automatically a server which will support multiple connections. To this software I'd add my own code.

    Thank you!