arduinoおよびBluetoothモジュールHC-05からのデータ受信に問題があります。私はPySerialとPybluezでデータを受け取ろうとしましたが、誰も私のために働いていませんでした。私が間違っていることを誰かが見直すことができたら、私は感謝します。puseerialまたはpybluezを使用したarduinoおよびHC-05モジュールからのデータの受信
StackOverflowでこれが見つかりましたが、機能しませんでした。 Bluetooth communication between Arduino and PyBluez
これは私のArduinoのコードです:
import serial
device_handler = serial.Serial('COM6', 9600, timeout=1)
count = 0
while (count < 5):
print device_handler.readline()
count += 1
device_handler.close()
そしてこれは、このリンクで説明したように、私は、pybluezと試みた方法は次のとおりです:
#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11
SoftwareSerial BTSerial(RxD, TxD);
void setup()
{
BTSerial.flush();
delay(500);
BTSerial.begin(9600);
BTSerial.println("The controller has successfuly connected to the PC");
Serial.begin(9600);
delay(100);
}
void loop()
{
BTSerial.write("{Dato1: 545}");
}
これは私がpyserialでそれをテストしてみましょう https://people.csail.mit.edu/albert/bluez-intro/x232.html
import bluetooth
import sys
bd_addr = "20:15:03:19:27:02"
port = 1
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr, port))
print 'Connected'
sock.settimeout(1.0)
count = 0;
while (count < 10):
data = sock.recv(12)
print 'received: %s'%data
count += 1
sock.close()
N 2つの形式のうちの1つが私のために働いた。 Pyserialはエラーを投げず、5つの読みを実行します。明らかにそれは何も得ていない。一方、pybluezはこの例外をスローします:
IOError: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
私の英語のためにあなたの助けと申し訳ありません。