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
1
Question by Isson · Dec 09, 2014 at 06:03 AM · inputstreamingbluetooth

How to receive Bluetooth-Data as Controller Input?

We are currently working on a project in which we try to use android-smartphone sensor data as cotroller input of our unity-(windows)-desktop application. We managed to program a bluetooth SPP server for C# but couldn't integrate the server into Unity3d. Our Bluetooth-Server does wait for incoming bluetooth-connections and accepts them (thanks to the 32feet.Net libary). As soon as the client has connected to the Server it should tranfer String-data over a stream.

Now the problem is, that Unity won't accept any GUID we create for our server (see code below). Is there a way we can set up a bluetooth server in a other way in unity/c# (we are used to java programming) or could we start the bluetooth-Server with "normal" .Net 3.5 and stream the data into unity ?

this is some code we tried. as we mentioned, unity won't accept our guid:

 using UnityEngine;
 using System.Collections;
 using BluetoothServerDLL;
 using InTheHand;
 using InTheHand.Net;
 using InTheHand.Windows;
 using InTheHand.Net.Bluetooth;
 using InTheHand.Net.Ports;
 using InTheHand.Net.Sockets;
 using System.IO;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 
 
 public class BlueToothControler : MonoBehaviour
 {
 
     public static CharacterController BtController;
     public static BlueToothControler Instance;
     public BluetoothServer bts;
 
     public Stream mStream;
     Guid mUUID = new Guid("00011111-0000-1000-8000-00805F9B34FB");
 
     // Use this for initialization
     void Awake()
     {
                //set up server
         try
         {
             //unity won't accept the mUUID in the next line
             BluetoothListener blueListener = new BluetoothListener(mUUID);
             blueListener.Start();
             BluetoothClient conn = blueListener.AcceptBluetoothClient();
             mStream = conn.GetStream();
         }
         catch (Exception e)
         {
             print(e.Message + "\n");
         }
 
 
         // Set up Player Control
         BtController = GetComponent("CharacterController") as CharacterController;
         Instance = this;
     }
 
 
 
     // Update is called once per frame
     void Update()
     {
 
         if (Camera.main == null)
         {
             return;
         }
 
         
         //receive data and use it as controller input
         try
         {
             //handle server connection
             byte[] received = new byte[1024];
             mStream.Read(received, 0, received.Length);
             String moveString = Encoding.ASCII.GetString(received);
             print("Received: " + Encoding.ASCII.GetString(received));
             //OnRaiseMoveEvent(moveString);
         }
         catch (IOException exception)
         {
             print("Client has disconnected!!!!");
         }
 
         PlayerMotor.Instance.UpdateMotor();
     }
 
 
 }

thanks in advance.

Comment
Add comment · Show 1
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 nicolas-rios · Jul 09, 2016 at 02:40 PM 0
Share

@username Did you figure this out? I am currently working on a project that receives a constant stream of data through a Bluetooth socket in order to transform GameObjects. Also, where did you attach this script? If I am trying to establish the Bluetooth connection, would I put that piece of code in a start() function? Or awake() like you have.. does it matter? Anything helps. Thanks

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mafemontoya94 · Aug 22, 2017 at 11:43 AM

Hi, do you solved this problem? I am trying to connect a balance board in unity but i am a little new in this library, could you help me please?

Comment
Add comment · Show 4 · 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 alibatiste · Aug 22, 2017 at 11:58 AM 0
Share

i succed to adapt this plugin https://github.com/Flafla2/Unity-Wiimote . You will need to make some research on the protocol used by Nintendo for balance.

avatar image mafemontoya94 alibatiste · Aug 22, 2017 at 03:30 PM 0
Share

Thank you alibatiste, but I realy don't understand what i should find in this code that allow me the conection witn the bluetooth dedvice, will you give me some ligth on it...

avatar image alibatiste mafemontoya94 · Aug 23, 2017 at 12:10 PM 0
Share

This plugin allow you to connect with Wii device in Bluetooth. You juste need to extend it to work with the balance.

avatar image jeffrocz · Feb 04, 2018 at 07:20 PM 0
Share

@alibatiste, could you please make a tutorial on how to this.. really need it..

avatar image
0

Answer by sofienjaballah · Jul 17, 2018 at 09:35 AM

Hi everyone! I'm developing an app for Android with unity 3D. I need that i include script in my actuel script to send app via bluetooth to another device for making vibration ( my app it turn on active vibration using smartphone coding by c#)

please give me the suggestion.

Comment
Add comment · 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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

My game can't find any controllers when streaming to a Steam Link or NVIDIA Shield! 0 Answers

UI issue when Streaming with 3DStreamingToolkit 0 Answers

Does Unity support Xbox 1 S controller input via bluetooth on Hololens? 0 Answers

Unity android bluetooth controller disconnect doesn't make array empty 1 Answer


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