RadiusNetworks / scanbeacon-gem

A Ruby gem for scanning beacons
MIT License
30 stars 9 forks source link

Eddystone-TLM support - will follow? (not an issue of course) #22

Closed peteanusergiu closed 8 years ago

peteanusergiu commented 8 years ago

Hi there and thanks for your work.

I'm currently experimenting with a Raspberry and some beacons with Eddystone format. My progress would have been diminished if not for this project.

Are there any plans for adding support for Eddystone-TLM too? It would be even more appreciated :).

Many thanks again, Sergiu

syoder commented 8 years ago

Yes, I imagine I'll add Eddystone-TLM at some point. It shouldn't be hard to add. Until I do that, you should be able to scan for TLM frames with something like this:

tlm_parser = ScanBeacon::BeaconParser.new(
  :eddystone_tlm,
  "s:0-1=feaa,m:2-2=20,d:3-3,d:4-5,d:6-7,d:8-11,d:12-15"
)
scanner = ScanBeacon::DefaultScanner.new
scanner.add_parser(tlm_parser)
scanner.scan do |beacons|
  tlm_beacons = beacons.select {|beacon| beacon.beacon_types.include? :eddystone_tlm}
  tlm_beacons.each do |beacon|
    puts "mac: #{beacon.mac} voltage:#{beacon.data[1]}mv temp:#{beacon.data[2]} pdus:#{beacon.data[3]} seconds:#{beacon.data[4]}"
  end
end
# on my Mac, this outputs something like:
# mac: CFFE138E-CE86-4CE9-80C2-4CA555091B4C voltage:2963mv temp:4284 pdus:2266629 seconds:5666992
# mac: 3E30BCA7-21C6-4730-AEEC-8FC4525F0EFF voltage:2955mv temp:4182 pdus:1681219 seconds:4203240

If you're interested in the temperature data, you'd need to decode that from the "8.8 fixed point representation" into something you can deal with in Ruby. The Eddystone TLM spec links to this page for more information: https://courses.cit.cornell.edu/ee476/Math/

Let's leave this issue open until I get TLM support properly in - then you'll be notified when this gets closed.

peteanusergiu commented 8 years ago

Scott, you're the man :) It is, of course, doing what you said...

I'll keep it open and have an eye on it.

Many thanks.

syoder commented 8 years ago

As of v0.7.1, TLM support has been merged in. This also adds the ability to convert a Beacon::Field object in 8:8 fixed point to a Float using to_f on the object.

Here's an example usage:

scanner = ScanBeacon::DefaultScanner.new
scanner.scan do |beacons|
  tlm_beacons = beacons.select {|beacon| beacon.beacon_types.include? :eddystone_tlm}
  tlm_beacons.each do |beacon|
    puts "mac: #{beacon.mac} voltage:#{beacon.data[1]}mv temp:#{beacon.data[2].to_f} pdus:#{beacon.data[3]} seconds:#{beacon.data[4]}"
  end
end
peteanusergiu commented 8 years ago

Many thanks Scott. Glad to have it as part of the library.

peteanusergiu commented 8 years ago

Scottt, hi again. Is there a chance you'll be adding the IBeacon format support any time soon?

syoder commented 8 years ago

It is possible to use this gem with the iBeacon format already. Unfortunately we are unable to include an iBeacon parser out of the box because this is an open source project and the iBeacon format is proprietary.

This gem uses beacon layout strings that match what the Android Beacon Library uses. If you search online for Android Beacon Library ibeacon layout, you may be able to find what you need. :wink:

(see also: https://github.com/AltBeacon/android-beacon-library/issues/311)

Here is some sample code that shows how you how to use the gem to scan proprietary beacon types for which you have the layout:

proprietary_layout = "layout_goes_here"
proprietary_parser = ScanBeacon::BeaconParser.new(:ibeacon, proprietary_layout)
scanner = ScanBeacon::DefaultScanner.new
scanner.add_parser(proprietary_parser)
scanner.scan do |beacons|
  ibeacons = beacons.select {|beacon| beacon.beacon_types.include?(:ibeacon)}
  puts ibeacons.inspect
end
peteanusergiu commented 8 years ago

Scott,

I'm late with the thanks, hope not too late.

It worked like a charm .So Thanks again.

Question : I've extended the functionalities and added a IOT structure on top of your code. By IOT structure I mean a set of entities simulating something like IOT beacons[] : {ibeacon, altbeacon, eddystone[uid, url, tlm]} mac type

I'm a java developer (not an ruby expert) so my code might not be the state of the art, certainly not the optimum., but nevertheless I would like to contribute to scanbeacon project in case you consider is useful.

Let me know if interested in my branch.

Kr, Sergiu

On 7 March 2016 at 16:43, Scott Yoder notifications@github.com wrote:

It is possible to use this gem with the iBeacon format already. Unfortunately we are unable to include an iBeacon parser out of the box because this is an open source project and the iBeacon format is proprietary.

This gem uses beacon layout strings that match what the Android Beacon Library uses. If you search online for Android Beacon Library ibeacon layout, you may be able to find what you need. [image: :wink:]

(see also: AltBeacon/android-beacon-library#311 https://github.com/AltBeacon/android-beacon-library/issues/311)

Here is some sample code that shows how you how to use the gem to scan proprietary beacon types for which you have the layout:

proprietary_layout = "layout_goes_here" proprietary_parser = ScanBeacon::BeaconParser.new(:ibeacon, proprietary_layout) scanner = ScanBeacon::DefaultScanner.new scanner.add_parser(proprietary_parser) scanner.scan do |beacons| ibeacons = beacons.select {|beacon| beacon.beacon_types.include?(:ibeacon)} puts ibeacons.inspectend

— Reply to this email directly or view it on GitHub https://github.com/RadiusNetworks/scanbeacon-gem/issues/22#issuecomment-193304925 .

syoder commented 8 years ago

I'm not sure I understand the functionality that this would add - can you send more details? I'm happy to include code contributions. I do want to keep this gem focused on beacons. If I understood a little more what you're code does I can figure out whether it makes sense for it to be a part of this gem.

peteanusergiu commented 8 years ago

Hi Scott,

sorry for my late reaction. Life is overwhelming sometimes.

Yes, I totally understand you - a scanBeacon project should deal and be focus on beacons. I'm not changing that either, even though I'm adding the beacons in the IoT family. The changes are simpler but for my project were much needed. Others might need it as well.

My branch is doing the following:

  1. wraps scanBeacons results in a IoT OOP structure
  2. adds support for exporting the structure (current version just XML)
  3. add multiple type support - as new versions of beacons are able to send more more beacons types (extending somehow the Eddystone concept of TLM, UID and URL)

Here is the result [it should give a clear feeling of wrapping classes and export structure as well]:

<?xml version="1.0" encoding="UTF-8"?>

E6:F7:33:75:1F:CC Eddystone edd1ebeac04e5defa017,e6f733751fcc EDD1EBEA-C04E-5DEF-A017- 0 253949394624460 -25 65194 -54.0 3036 15.75 4209516 77970120 3033 15.75 4209523 77970240

Kr, Sergiu

On 7 April 2016 at 16:30, Scott Yoder notifications@github.com wrote:

I'm not sure I understand the functionality that this would add - can you send more details? I'm happy to include code contributions. I do want to keep this gem focused on beacons. If I understood a little more what you're code does I can figure out whether it makes sense for it to be a part of this gem.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/RadiusNetworks/scanbeacon-gem/issues/22#issuecomment-206931947

syoder commented 8 years ago

I don't think I want this gem to deal with putting beacons into XML or any particular format. I can see how that is useful but I think that's an easy layer to add on top of this gem, and each project will have it's own requirements which will result in different formats, etc.

Also, I just noticed that the above code I gave you for TLM is incorrect. The spec states that the timer field (beacon.data[4]) is in tenths of a second, not seconds. In order to get seconds, you'd want to do: beacon.data[4] / 10.0

peteanusergiu commented 8 years ago

Got it. Thanks for the tlm update, i ll correct it.

On Thu, Apr 14, 2016, 7:56 PM Scott Yoder notifications@github.com wrote:

I don't think I want this gem to deal with putting beacons into XML or any particular format. I can see how that is useful but I think that's an easy layer to add on top of this gem, and each project will have it's own requirements which will result in different formats, etc.

Also, I just noticed that the above code I gave you for TLM is incorrect. The spec states that the timer field (beacon.data[4]) is in tenths of a second, not seconds. In order to get seconds, you'd want to do: beacon.data[4] / 10.0

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/RadiusNetworks/scanbeacon-gem/issues/22#issuecomment-210077114