TCPIP communication between Matlab - Arduino. Stuck at fopen even when Arduino indicated a connection has been established.
1 次查看(过去 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!