TCPIP communication between Matlab - Arduino. Stuck at fopen even when Arduino indicated a connection has been established.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 10 Sep. 2019
t = tcpip('localhost',1234,'NetworkRole', 'server')
might help, maybe
Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!