小编avm*_*tte的帖子

BLE Android - 未调用onConnectionStateChange

我在尝试连接外围设备时遇到问题.有时回调onConnectionStateChange(...)不会被调用BluetoothDevice#connectGatt(...).我想要实现的是用户操作触发的快速和短连接.

这种情况大约发生在10次,没有特定的事先行动.它持续约20至30秒,或直到应用程序被杀死并重新打开.我遵循的正常步骤顺序是:

  1. 扫描设备以查找外围设备.
  2. 打电话BluetoothDevice#connectGatt(...).如果连接时间超过1秒,则表示连接"卡住",因此无法连接,因此BluetoothDevice#connectGatt(...)再次调用.这是在5次尝试的限制下完成的.
  3. onConnectionStateChange(...)使用newStateCONNECTED 调用并开始服务发现.
  4. 其余的操作没有问题.
  5. 断开连接后BluetoothGatt#close()调用.

发生的问题是在第3点.有时onConnectionStateChange(...)不会被调用.我注意到大多数时候问题都是从特定的行为开始的.之后BluetoothDevice#connectGatt(...),onConnectionStateChange(...)使用newStateCONNECTED 调用,但几乎立即(~40毫秒)再次使用newStatusDISCONNECTED 调用.由于状态改变的时间很短,我可以推断设备甚至没有尝试建立连接并将状态更改为DISCONNECTED.问题在以下时间结束:

  1. 20-30秒过去了.在此期间onConnectionStateChange(...)永远不会被召唤.问题结束时,onConnectionStateChange(...)称为应用尝试连接的次数.例如,如果BluetoothDevice#connectGatt(...)被调用15次,onConnectionStateChange(...)则被调用15次,newState等于DISCONNECTED.这很奇怪,因为在任何连接尝试中都没有将状态更改为CONNECTED.
  2. 该应用程序被杀死并重新开始.

SDK18和SDK 21中发生此错误.

@Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
    String deviceName = device.getName();
    if (deviceName == null) return;
    Log.d("BLUETOOTH CONNECTION", "Device found: " + device.getName());
    if (mMode == SCAN_MODE) { …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth-lowenergy android-bluetooth

18
推荐指数
1
解决办法
1万
查看次数

未定义的局部变量或方法"articles_path"

我正在尝试完成本教程:http://guides.rubyonrails.org/getting_started.html#say-hello-rails但我收到的错误是:

<%= form_for :article, url: articles_path do |f| %>
Run Code Online (Sandbox Code Playgroud)

我有下一个错误:

undefined local variable or method `articles_path' for #<#<Class:0x4646c28>:0x4661d30>
Extracted source (around line #1):       
Run Code Online (Sandbox Code Playgroud)

rake routes:

Prefix Verb URI Pattern                      Controller#Action
welcome_index GET /welcome/index(.:format)   welcome#index
 articles_new GET /articles/new(.:format)    articles#new
         root GET /                          welcome#index`
Run Code Online (Sandbox Code Playgroud)

ArcticlesController:

class ArticlesController < ApplicationController
  def new
  end

  def create
  end
end
Run Code Online (Sandbox Code Playgroud)

请帮忙!

ruby routes ruby-on-rails

5
推荐指数
1
解决办法
5201
查看次数

安装mysql(2.9.1)时发生错误,Bundler无法继续

我正在尝试按照本指南将Rails应用程序上传到hostgator:http: //support.hostgator.com/articles/specialized-help/technical/how-do-i-start-using-ruby-on-rails 我'我在5.6点得到一个错误.当我做:

rake generate_session_store
Run Code Online (Sandbox Code Playgroud)

它说找不到gem'rack'并建议我运行bundle install.当我这样做时:

Gem::Installer:ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for mysql_ssl_set()... no
checking for rb_str_set_len()... no
checking for rb_thread_start_timer()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog …
Run Code Online (Sandbox Code Playgroud)

ruby rack ruby-on-rails gemfile

2
推荐指数
1
解决办法
3939
查看次数