Clear Filters
Clear Filters

TCPIP communication between Matlab - Arduino. Stuck at fopen even when Arduino indicated a connection has been established.

2 views (last 30 days)
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?

Answers (0)

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!