我尝试使用蓝牙在Windows和iOS之间进行通信。
在iOS方面,我发布广告,在窗口方面,我观看"观看"用于广告。
目前,在收到我的iOS设备正在发布的广告时,这些广告是空的。没有服务,没有ManufacturerData,DataSections列表包含1个DataSection,长度为1的数据(?)本地名称为空,这个广告包中没有任何用处。
当我调用# app/config/security.yml
security:
encoders:
Delivery\AdminBundle\Entity\User:
algorithm: bcrypt
providers:
our_db_provider:
entity:
class: DeliveryAdminBundle:User
property: username
access_control:
- { path: ^/admin, roles: ROLE_USER }
firewalls:
main:
pattern: ^/admin
http_basic: ~
provider: our_db_provider
(蓝牙地址)时,我得到一个对象,但是当我调用GetGattService时,所有内容都为空,没有服务,找不到异常的元素,DeviceInformation为空......就我而言没什么用处可以看到。
我不知道我在iOS上发布的广告是否有问题,或者我是如何在Windows上对待它的?侧。
以下是iOS代码:
<?php
namespace Delivery\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Table(name="app_users")
* @ORM\Entity(repositoryClass="Delivery\AdminBundle\Repository\UserRepository")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=25, unique=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @ORM\Column(type="string", length=60, unique=true)
*/
private $email;
/**
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
public function __construct()
{
$this->isActive = true;
// may not be needed, see section on salt below
// $this->salt = md5(uniqid(null, true));
}
public function getUsername()
{
return $this->username;
}
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
return null;
}
public function getPassword()
{
return $this->password;
}
public function getRoles()
{
return array('ROLE_USER');
}
public function eraseCredentials()
{
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
*
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Set password
*
* @param string $password
*
* @return User
*/
public function setPassword($password)
{
if ($password) {
$this->password = password_hash($password, PASSWORD_DEFAULT);
}
return $this;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set isActive
*
* @param boolean $isActive
*
* @return User
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
}
这是Windows C#代码(暂时是一个简单的控制台应用程序):
BluetoothLEDevice.FromBluetoothAddressAsync
对不起它有点乱......
提前感谢您的帮助,我也尝试了另一个方向(Windows广告和iOS观看)它也不顺利,这里是另一个问题我和#39如果感兴趣,可以发表这个主题:Listening to and accepting a BLE Connect request in windows
答案 0 :(得分:0)
广告是被动的,因此您应该将代码从主动更改为被动,例如: watcher.ScanningMode = BluetoothLEScanningMode.Passive;
public sealed partial class MainPage : Page
{
Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher advertisementWatcher;
public MainPage()
{
this.InitializeComponent();
advertisementWatcher = new Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher();
advertisementWatcher.ScanningMode = Windows.Devices.Bluetooth.Advertisement.BluetoothLEScanningMode.Passive;
advertisementWatcher.Received += AdvertisementWatcher_Received;
advertisementWatcher.Start();
}
private void AdvertisementWatcher_Received(Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher sender, Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementReceivedEventArgs args)
{
System.Diagnostics.Debug.WriteLine("Address: {0:X}", args.BluetoothAddress);
}
}
仅使用.Received回调,您应该开始看到即将到来的数据,例如:
地址:A45E60F3E896地址:4BF5661A4EF2地址:549F476B5F37地址:4CB6DF3019A9地址:4BF5661A4EF2地址:106070EB42B1