#16 Bluetooth msg to more then one slave

closed
John Hansen
None
5
2009-01-26
2007-06-28
LorenzoSabattini
No

Hi everybody,

I need one master to send the same message to 2 or 3 slaves. Is it possible to do it in only one NXC instruction?
or is it necessary to do:
SendRemoteNumber(conn1,outbox,outmsg);
SendRemoteNumber(conn2,outbox,outmsg);

Because this doesn't work very well.... is seems that the master can only perform correctly the first instruction.

Please, help me! :-)

thank you
Lorenzo

Discussion

  • Logged In: NO

    hi,

    this might not work because you first have to check if the bluetooth channel is free.
    2 possibilities:
    1. Look at the Nxc Docs, there are some nice bluetooth examples in the tutorial !
    2. Have a look at Danny's BT library: http://daniele.benedettelli.com/BT_NXC.htm

    You should write methods like this one:

    // (Danny's bluetooth library.)

    sub BTWait (int connection)
    { //wait until BT is idle
    until(BluetoothStatus(connection)==NO_ERR);
    }

    // usage:
    BTWait(connection); // wait until channel is free
    BluetoothWrite(connection,out); // send message

    so the method you need might look like this: (not tested !)
    sub SendAll(string message)
    {
    for (int i=1; i<=4; i++)
    {
    BTWait(i); // wait until channel i is free
    BluetoothWrite(i ,message); // send message
    }
    }

    But be careful, there are bugs in these few lines of code:
    - the message byte array for the bluetooth write method succeeds the maximum length
    of a bluetooth message according to the Lego Mindstorms Bluetooth specification.
    - the length of a string message you send is one too great. (You normally don't count
    the 0 termination character.) (Code: length +1...)
    - the library isn't up to date, you have to replace some deprecated commands.

    If you only communicate from Nxt to Nxt using Danny's library, you can ignore the bugs.
    (Except the last one.)
    But you could get problems if one of the other Nxts is not using Danny's library.

    Greetings

    Sallac

     
  • John Hansen
    John Hansen
    2007-07-04

    Logged In: YES
    user_id=661666
    Originator: NO

    The response already posted is great. I would just add that your problem definitely is that the first message has not been sent completely by the asynchronous bluetooth sending operation in the NXT firmware. Your call to SendRemoteNumber starts the transfer process but it works in the background while your program continues on to the next instruction. What you need to do is loop until the bluetooth status is idle as mentioned in the other response to your support request.

    You can just place

    until(BluetoothStatus(conn1)==NO_ERR);

    between your calls to SendRemoteNumber (of course, passing in the correct connection based on the connection used in the function call you just made).

    The NXT does not have a broadcast mode for bluetooth, unfortunately, but the wait for idle does not take very much time. You may also want to check the return value of the SendRemoteNumber call just to make sure that no errors occurred in that call, like if you pass in an invalid connection number.

     
  • Logged In: YES
    user_id=1774284
    Originator: YES

    thank you all for your answers.

    In reality, I've already tried this way... but it DOES take very much time to perform the operation.... for a "Send" operation to be completed, il takes about 200-300ms, and it's a very long time for a position control task.

    thank you, bye
    Lorenzo

     
  • Logged In: NO

    hi,

    this is not normal !
    Have a look at this page:
    http://www.tau.ac.il/~stoledo/lego/btperformance.html

    You should have a latency between 3-50 ms.

    Possible problems:

    - Do you use the correct connection numbers ?
    - Only the one brick, the master, can start communication.
    The slaves just answer.
    - If everything is set up correctly, do you use wireless LAN ?
    Bluetooth and WLAN (except 802.11 a) use the same frequency.
    So bluetooth and WLAN might jam each other.

    Can you post your code ? (Master and slave)

    Greetings

    Sallac

     
  • Logged In: NO

    wrong bug report:

    - the size+1 is correct in Danny's bluetooth library:
    -> NXT-G counts the 0 terminator to the message size.
    -> According to the Bluetooth Developer Kit document on page 9
    the message size includes the 0 termination character.

    Greetings

    Sallac

     
  • John Hansen
    John Hansen
    2009-01-26

    • assigned_to: nobody --> afanofosc_99
    • status: open --> closed