假设我的电脑上有蓝牙加密狗
如何直接将数据发送到我的电脑
我不想把手机用作中间人
(通常用于调试蓝牙时磨损)
我可以直接将Android Wear与PC配对,然后传输任何数据吗?
答案 0 :(得分:1)
您需要在Android Wear手表和手机上的Wear App之间对蓝牙协议进行反向工程。鉴于Wear App用于更新手表上的OS Wear软件,Google可以随时更改协议。因此,虽然您可以嗅探流量并复制Wear应用程序的行为以便能够与手表通信,但您只需更新一次就可以重新进行逆向工程。
答案 1 :(得分:0)
我已经尝试过并确认它适用于Android Wear 5.1(版本1.1和最新版本1.3)
证明:https://www.youtube.com/watch?v=yyGD8uSjXsI
我不确定谷歌是否会尽快补丁,因为它似乎有些漏洞。
你需要一款带有WiFi的安卓手表,如三星Gear Live,Moto360,LG Urbane等。根据您的信息,LG G Watch没有WiFi支持。 首先,您需要将手表与手机配对,然后转到手表,启用WiFi并选择任何WiFi点。然后手表会要求您在手机上输入密码。之后,它将连接到WiFi。
然后现在你应该去你的Android手机,然后看看手表。这是因为我们想强制手表直接使用WiFi连接。否则它将始终通过手机使用蓝牙作为中间人 您可以通过运行Android Wear浏览器并浏览任何随机页面来仔细检查手表是否使用WiFi。
然后在您的代码(服务器/客户端模型)中,正常使用套接字 例如,我使用aysnctask进行网络连接,如下所示。你应该通过注册听众获取传感器数据,有很多例子,所以我不在这里发帖。
class ConnectServer extends AsyncTask<Void, Void, Void> {
public ConnectServer() {
super();
}
@Override
protected Void doInBackground(Void... params) {
sendToServer();
return null;
}
public void sendToServer(){
Socket socket = null;
BufferedWriter out = null;
try
{
socket = new Socket(IP_ADDRESS, 5000); // IP address of your computer
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
while(isSending)
{
//x,y,z,w is from android sensor
out.write(String.format("%.3f",x)+
","+String.format("%.3f",y)+
","+String.format("%.3f",z)+
","+String.format("%.3f",w)+"/");
out.flush();
Thread.sleep(INTERVAL); // 50ms is quite good
}
out.close();
socket.close();
}
catch (Exception e)
{
Log.e("socket",""+e.toString());
e.printStackTrace();
}
finally
{
if (socket != null)
{
try
{
socket.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}
对于Server,我在Unity中使用.net Async Socket,但对于任何.net应用程序都应该是相同的。代码未经过优化或错误检查,但您明白了。
using UnityEngine;
using System.Collections;
using System;
using System.IO;
using System.Net.Sockets;
using System.Net;
using System.Text;
public class AsyncServer : MonoBehaviour {
private byte[] data = new byte[1024];
private int size = 1024;
private Socket server;
private Socket client;
float x, y, z, w;
void Start () {
server = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
IPAddress ipAd = IPAddress.Parse("YOUR IP ADDRESS");
//IPEndPoint iep = new IPEndPoint(IPAddress.Any, 5000);
IPEndPoint iep = new IPEndPoint(ipAd, 5000);
server.Bind(iep);
server.Listen(5);
server.BeginAccept(new AsyncCallback(AcceptConn), server);
}
void AcceptConn(IAsyncResult iar)
{
Socket oldserver = (Socket)iar.AsyncState;
client = oldserver.EndAccept(iar);
Debug.Log("Accepted client: " + client.ToString());
client.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), client);
}
void SendData(IAsyncResult iar)
{
Socket client = (Socket)iar.AsyncState;
int sent = client.EndSend(iar);
client.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), client);
}
void ReceiveData(IAsyncResult iar)
{
Socket client = (Socket)iar.AsyncState;
int recv = client.EndReceive(iar);
if (recv == 0)
{
client.Close();
Debug.LogError("Waiting for client...");
server.BeginAccept(new AsyncCallback(AcceptConn), server);
return;
}
string receivedData = Encoding.ASCII.GetString(data, 0, recv);
//Debug.Log("len: " + recv + ", " + receivedData);
{
var s = receivedData.Split(',');
if (s.Length == 4)
{
float xx = float.Parse(s[0]);
float yy = float.Parse(s[1]);
float zz = float.Parse(s[2]);
s[3] = s[3].Replace("/","");
float ww = float.Parse(s[3]);
Debug.Log("len: " + recv + ", " + xx + ", " + yy + ", " + zz + ", " + ww);
}
}
client.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), client);
}
}