Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by MolluskJesse · Dec 19, 2014 at 04:41 PM · windowsmacbluetoothplatform-support

Bluetooth Support on Win and OSX

While there appears to be plenty of Bluetooth solutions for mobile platforms on the Unity Asset store, I'd like to know if anyone has any insight into supporting Bluetooth on Windows and Mac OSX platforms. Ideally, it would be best to have a solution that is itself cross platform.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dshewmaker · Apr 13, 2015 at 05:08 PM 0
Share

looking for same thing.

avatar image MolluskJesse · Apr 18, 2015 at 12:49 AM 0
Share

Haven't found an in Unity solution. Had to fallback to developing a WinForms companion application. Unity and the companion communicate through a TCP connection. It's not an ideal work around, but I got what I needed working.

Still looking for a true answer though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Freefly18 · May 09, 2015 at 12:08 AM

I was having similar issues while looking for a way to communicate between 2 Unity applications, one on PC and one on Android. As far as I can tell, there is a lot of solutions for Mobile (notably Android Bluetooth Multiplayer), but none for PC. Even well tested Bluetooth libraries for C# (like 32feet.NET) fails on Unity3D and it took me a while to learn why. Here's some valid C# code:

 using System.Net.Sockets;
 Socket s = new Socket((AddressFamily)32, SocketType.Stream, (ProtocolType)3);

32 is for a Bluetooth address and 3 is for RFCOMM protocol. Try this in .NET 3.5 and it will work as intended. Try it in Unity with Mono 2.0 and you will get this Exception:

 System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used.

This means that Mono 2.0 does not support Bluetooth Sockets and, as far as I know, you cannot do bluetooth communications using only C# in Unity3D.

I see 2 workarounds:

  • Do what MolluskJesse did and implement a man-in-the-middle application made in your favorite language, that handles Bluetooth communications and talks with your Unity3D software using TCP or some other interface. This solution is good if you want to use a specific library and if you're only fluent in C#.

  • The correct solution, IMO, would be to develop a C++ plugin for your Unity3D software. The plugin would implement all the Bluetooth communication and would offer some callbacks and methods to the C# code. This of course require you to know well enough C/C++ and have a Pro version of Unity3D.

Hope this helps others.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MolluskJesse · May 09, 2015 at 12:19 AM 0
Share

The issue with doing the plugin solution is I have too much on my plate with the game's development to really devote the time necessary. That and we need support for Windows and OSX. Still possible with a plugin, but someone doing a plugin would have to integrate the Windows and OSX solutions together to a degree while the man-in-the-middle allows for an entirely different app to jump and stand in the middle for OSX as long as it sends the information in the same manner.

avatar image Freefly18 · May 09, 2015 at 12:49 AM 0
Share

I hope you didn't interpret my answer as saying that your solution was bad. Both have their pros and cons and I'm probably going to go for the man-in-the-middle myself since I'm short on time. I consider the plugin solution to be a slightly better one because it makes for a more elegant solution as well as not depending on a third application.

Speaking of which, may I ask what was your way of handling the execution of the man-in-the-middle? Does the user need to run 2 software or is there some triggering mechanism?

avatar image MolluskJesse · May 09, 2015 at 12:59 AM 0
Share

To trigger the man-in-the-middle I use the following line of code.

 System.Diagnostics.Process.Start(storedAppPath);

In this the storedAppPath is the computed path to the man-in-the-middle exe which, in my case, lives next door to the Unity game's standalone executable.

The other half of this is quitting. In my implementation, it is the man-in-the-middles responsibility to detect that the game has disconnected from the other side of the TCP. If it detect this, it closes itself.

avatar image jvv MolluskJesse · Jan 05, 2017 at 06:54 PM 0
Share

Hey @$$anonymous$$olluskJesse ! I need to do something similar for the HoloLens except with a Bluetooth GPS receiver. Would you be able to share your source code for your man-in-the-middle exe? I have been trying to find a solution to implement this and would really like to see how you implemented yours so I can try to use the same approach for my app.

I would appreciate any help on this.

Thanks!

avatar image Freefly18 jvv · Jan 06, 2017 at 05:07 AM 0
Share

Not sure if he answered back, but I just pushed to GitHub what I had for my version of it, including the code for Android and the one for Windows: https://github.com/Freefly18/UnityDesktopToAndroidBluetooth/

Feel free to use the man-in-the-middle (see the readme). It translates anything from a connected Bluetooth device using a specific GUID (currently hardcoded, just search for "GUID"), to an application on the same computer, using TCP on port 13000 (once again you may want to change that).

Also feel free to use my code for the PC side (TCP server), although you'll propably have to change a lot of things in SmartphoneCommand.cs and other files with 'Smartphone' in it... all in all still a lot of work for you to do, but it should save you the hassle of having to deal with client-server stuff.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Kinect doesn't work on the virtual machine or Mac. 0 Answers

Can I develop an iphone app on UnityPro3d (for windows) and then transport it to Unity (iphone version for mac)? 2 Answers

Compile a game for iOS, Mac, PC - how much adjustment? 2 Answers

Failed to load window layout - from Win7 to Mac 2 Answers

Shader.SetGlobalTexture not working on Windows 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges