Using one tablet for Two Rfduinos - Question

Ask, and ye shall receive.
Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Using one tablet for Two Rfduinos - Question

Postby Amman » 21:11, 03 Jul 2015

Hi ,

I am using the Rfduino LED On/Off evothings client/workbench example.

I have two Rfduinos that are powered on. And using the example I was able to connect to one of them and turn the Blue LED on and off.
It seems the connection is made between the app and the nearest Rfduino (one of the two I have) to the smart device.

My question is, If I can create two connect buttons "connect1" and "connect2" using the HTML/Js how can I make "connect1" means to connect only to Rfduino#1 and "connect2" means connect only to Rfduino#2?

What should I modify on the RFduino side for each one of them to recognize their own calling button from the app side ("connect1" or "connect2")

And if that is successful, would it be possible to be connected to both of them at the same time? or one will be dropped if one is connected?

Thank you


Amman

Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Re: Using one tablet for Two Rfduinos - Question

Postby Amman » 03:19, 06 Jul 2015

I think I got an answer for my own question :D

On the Rfduino#2 side (rfduino-led-onoff.ino) I changed the following as
RfduinoBLE.deviceName = "RFduino2"

And on the HTML/JS code I duplicated "Connect" button and created "Connect2" and created app.connect2 exactly as app.connect.
But on app.connect2 I modified where it says rfduinoble.connect( "RFduino2" ... , and kept the rest as is.

And it worked, as in Connect1 button connects only to RFduino#1 and the Connect2 button for RFduino#2.

Just in case someone has similar question.

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: Using one tablet for Two Rfduinos - Question

Postby ardiri » 23:05, 08 Jul 2015

great you solved it yourself.. :)

another point to note - you can only have a single device connected at any time; if you want to connect to both, you'll need to build some fancy logic to connect/do something/disconnect and move along to another device. great if you want to cycle through a few devices and collect information from them
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/

Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Re: Using one tablet for Two Rfduinos - Question

Postby Amman » 23:25, 09 Jul 2015

Thank you Aaron,

One more question I have on this topic, How can I change the color of the Connect button from Yellow to Green when it is connected.
I have visited multiple sites to learn how to do that using the HTML/js. However, their button color changing example (when clicked) works by itself but I could not integrate it into your BLE HTML/js example code to make it work for my rfduinos.

Thank you

Amman.

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: Using one tablet for Two Rfduinos - Question

Postby ardiri » 23:38, 09 Jul 2015

like you said; there are a few sites explaining how to do this in HTML/JavaScript:

http://stackoverflow.com/questions/1819 ... amatically

the problem is that the examples are using jQuery, not basic HTML5 - with a new google search; i found:

http://stackoverflow.com/questions/1624 ... or-onclick

may have some insights; basically.. seems there are a few ways to do this; if you do figure it out - be sure to post how you do it here on the forums.
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/

Amman
Posts: 14
Joined: 21:42, 19 Feb 2015

Re: Using one tablet for Two Rfduinos - Question

Postby Amman » 02:45, 10 Jul 2015

After some more research I found some info and it works. Just added the following code inside app.connect functions
http://www.webdeveloper.com/forum/showt ... a-function

Code: Select all

app.connect1 = function()
{
.
.
       function(device)
       {
       .
       .
      document.getElementsByTagName('button')[0].className = 'green';   // for button #1
      document.getElementsByTagName('button')[1].className = 'yellow';  // for button #2  and so on
      }
      .
      .
}



The [0], [1]... counts up for the number of buttons you have. The neat thing, you can also change the color of the other (unclicked) buttons at the same time when you color change the clicked or connected button.

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: Using one tablet for Two Rfduinos - Question

Postby ardiri » 10:30, 10 Jul 2015

great - thanks for posting the solution for others to enjoy!
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 11 guests