저는 Arduino (컴퓨터의 X360 컨트롤러 사용)를 통해 로봇을 무선으로 제어하려고합니다. 대기 시간이 매우 짧습니다. 나는 Wifi를 선택했기 때문에 (사실 비디오 스트리밍을 할 것입니다.) 약간의 테스트를 거친 후에 TCP를 사용하여 거대한 지연을 보았습니다. 이것은 정상적인가요 (54Mbits/s로, 그것은 안됩니다!)? 제어 가능하도록 어떻게 줄일 수 있습니까?Wi-Fi를 통한 간단한 TCP 통신이 너무 느립니다 (초 지연)?
서버 코드 (아두 이노 스케치) :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x48, 0x0D };
byte ip[] = { 192, 168, 0, 11 };
byte gateway[] = { 192, 168, 0, 254 };
byte subnet[] = { 255, 255, 255, 0 };
byte localPort = 99;
EthernetServer server = EthernetServer(localPort);
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
// start listening for clients
server.begin();
Serial.println("Server ready");
}
void loop()
{
// if an incoming client connects, there will be bytes available to read:
EthernetClient client = server.available();
if (client == true) {
Serial.println("Received:");
byte received = 0;
while((received = client.read()) != -1) {
Serial.println(received);
server.write(received);
}
Serial.println("Over\n");
}
}
클라이언트 코드 (PC, QtCreator는) :
#include <QTextStream>
#include <QTCPSocket>
QString arduinoIP = "192.168.0.11";
char arduinoPort = 99;
int main(void)
{
QTcpSocket socket;
QTextStream in(stdin);
QTextStream out(stdout);
out << "Connection... "; out.flush();
socket.connectToHost(arduinoIP, arduinoPort);
if(!socket.waitForConnected(5000)) {
out << socket.errorString() << "\n";
}
else {
out << "OK\n"; out.flush(); //I don't know why \n doesn't flush
out << "Type a message to send to the Arduino or quit to exit\n"; out.flush();
QString command;
in >> command;
while(command != "quit") {
QByteArray bufOut = command.toUtf8();
socket.write(bufOut);
socket.waitForReadyRead(1000); //Wait for answer (temp)
out << "Answer: " << socket.readAll() << "\n";
}
}
return 0;
}
당신의 도움에 미리 감사드립니다.
감사합니다, 미스터 Mystère
나는 또한 게시하는 것은 좋은 생각 일 것이다라고 생각했다가 있기 때문에 그 절대적으로 (검색 시간 후 나의 지식에) HTTP를 사용하지 않고 이더넷/wifi를 통해 PC와 arduino 사이의 통신을위한 간단한 응용 프로그램 (서버 및 클라이언트)을 찾을 수있는 웹에서. 일반적으로이 댓글은 Google에서 색인을 생성하고이를 찾는 사람들을 도울 정도로 충분해야합니다. 이를 염두에두고이 코드를 개선하는 데 언제든지 도움을주십시오. –