TCPIP communication between Matlab - Arduino. Stuck at fopen even when Arduino indicated a connection has been established.
조회 수: 3 (최근 30일)
이전 댓글 표시
Here's my Arduino Code:
#include <WiFi101.h>
// To connect to the server on laptop
char ssid[] = "EEELAB";
char pass[] = "@adelaide";
int status = WL_IDLE_STATUS;
IPAddress server(129,127,225,25);
WiFiClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Setup wifi connection
Serial.println("Connecting to wifi.");
while (status != WL_CONNECTED) {
Serial.println("Can't connect to wifi, try again.");
status = WiFi.begin(ssid, pass);
}
delay(10000); // If don't include this, it won't work
// don't know why, can anyone figure out??
// Setup server connection
Serial.println("Connecting to server.");
int j = client.connect(server, 1234);
while (j != 1) {
Serial.println();
Serial.println(j);
Serial.println("Can't connect to server, try again.");
j = client.connect(server, 1234);
}
Serial.println("Done connecting to server");
}
void loop() {
// put your main code here, to run repeatedly:
if (client.available()) {
int a = client.read();
Serial.print("I got this from client: ");
Serial.println(a);
Serial.println();
}
}
And here's my Matlab:
t = tcpip('129.127.225.25',1234,'NetworkRole', 'server')
fopen(t)
On the Arduino, I can see on Serial Monitor that it has "Done connecting to server", but fopen still stuck at a loop and not returning. Any idea?
댓글 수: 2
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!