Reading rssi value

Ask, and ye shall receive.
User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Reading rssi value

Postby Attacking3rd » 18:58, 10 Dec 2014

Hello.

I am modifying the Arduino BLE example and can't figure out how to reference the rssi value.

In the startScan method this outputs the current rssi value to the console:
console.log('rssi: ' + deviceInfo.rssi);

But when I try to use deviceInfo.rssi in a different method I am getting a 'deviceInfo is not defined' message.

I understand what the error message is telling me but I have not been able to figure out how to resolve this problem. I have a pretty thin grasp of how this example works so perhaps I just missing something minor.

Any suggestions?

Thanks!

robertg

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 04:57, 11 Dec 2014

Upon further troubleshooting, rather than trying to use deviceInfo.rssi in the method I created, I used this:

Code: Select all

evothings.ble.rssi(
   deviceHandle,
   function(rssi)
   {
      console.log('BLE rssi: ' + rssi);
   },
   function(errorCode)
   {
      console.log('BLE rssi error: ' + errorCode);
   }
);


Which I pulled from https://github.com/evothings/cordova-ble/blob/master/ble.js.

And now the rssi value is displaying. So I think I am getting closer.

However, when I use this method again, I get this error: "Previous call to rssi() not yet completed!"

I looked for something similar to evothings.ble.stopScan(); but for rssi and did not find anything.

Any suggestions?

Thanks for looking!

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Reading rssi value

Postby micke » 10:56, 11 Dec 2014

Hi Robert,

You are on the right track!

When scanning the RSSI value is always included with the info you get about the found device.

But when connected you have to poll for it. The problem is you cannot poll too frequently, only about once a second. This is a limitation of the underlying system (not sure if it is a BLE limitation or a limitation on iOS/Android).

Try polling less frequently and see how that works.

Here is an experimental example that does polling for the RSSI value, perhaps this can be of some help:

https://github.com/evothings/evothings- ... s/ble-rssi

Best regards, Mikael

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 23:28, 11 Dec 2014

Thank you Mikael for the confirmation that I am on the right track and for the code samples. I'll work on it later tonight and report back on my results.

I very much appreciate your time and help!

robertg

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 02:05, 08 Jan 2015

Hello Again,

Either I am not understanding how polling is suppose to work or it does not appear to be working correctly.

The code with some console.logs I added is below.

I see 'in pollRSSI' and 'rssi polled again' a bunch of times. But I only see 'hey' once and it is after the first 'in pollRSSI'. So I'm taking this to mean evothings.ble.rssi is only being called once. Also, the RSSI value does not change regardless of how close or far away I am from the ble device.

Question: Should I see 'hey' every time pollRSSI is called?

Note: setTimeout only seems to work once whereas setInterval works repeatedly.

Code: Select all

   pollRSSI:  function(deviceAddress, deviceHandle)
   {
      console.log('in pollRSSI');
      // You may have to increase interval to 2000 ms if polling breaks.
      var interval = 2000;
      evothings.ble.rssi(
         deviceHandle,
         function(rssi)
         {
            console.log('hey');
            var deviceInfo = app.knownDevices[deviceAddress];
            if (!deviceInfo)
            {
               evothings.ble.close(deviceHandle);
               return;
            }
            deviceInfo.rssi = rssi;
//            setTimeout(
            setInterval(
               function()
               {
                  console.log('rssi polled again');
                  app.pollRSSI(deviceAddress, deviceHandle);
               },
               interval);
         },
         function(errorCode)
         {
            // RSSI errors may occur now and then, we just ignore them.
         });
   },


Thank you!

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Reading rssi value

Postby micke » 18:42, 12 Jan 2015

Hi,

You should see "hey" multiple times. The idea is to call evothings.ble.rssi and when you get the rssi reading via the callback function, you call evothings.ble.rssi again (via the app.pollRSSI function). The setTimeout is there beacuse you cannot poll too frequently, a delay is needed.

When using setInternal app.pollRSSI will be called repeatedly and for each call there will be even more calls to it. The number of active setInterval loops will grow exponentially. That is why setTimeout needs to be used.

Have you tried running the example without any modifications? Does it work? Was a while since I tested it, perhaps it is not working anymore. Will see if I can test it tomorrow.

If you see "hey" once, you are on the right track. Start by commenting out the setTimeout call. If that works and you get one rssi reading, you can add the setTimeout call.

Let me know how it goes!

Best, Mikael

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 09:31, 07 Feb 2015

Hi Mikael,

Thank you for your time and continued help.

I ran the ble-rssi example as you suggested on an Android and iOS device.
It works (I can watch the rssi value change as I move away from device) on iOS but not Android.

I then ran my modified ble-rssi on an iOS and Android device.
It also only works on iOS and not Android.

I tried setting the interval variable to 2000, 3000, 10000 and 20000 but regardless of the value I keep getting
'Previous call to rssi() not yet completed!' error.

I tried two Android devices and get the same results and all my test devices are running the latest version of Evothings client.

Are there any know issues with Android?

robertg

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: Reading rssi value

Postby Fredrik » 11:48, 07 Feb 2015

There is a known issue on Android: RSSI Polling only works once.

It's been fixed recently, but we still need to upload a new version of the Evothings Client to the app store.

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 20:23, 07 Feb 2015

Thanks for the great news Fredrik! I'll keep checking for the new version.

robertg

User avatar
Attacking3rd
Posts: 10
Joined: 18:19, 29 Oct 2014
Location: Austin Texas
Contact:

Re: Reading rssi value

Postby Attacking3rd » 04:00, 10 Feb 2015

I installed version 1.1.2 of the Evothings Client and my android device can now poll the RSSI correctly (like it already did on iOS).

Thanks!


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 28 guests