I am trying to set up a WiFi communication between my Arduino Yun and my PC, I have to use Matlab /simulink for that. I already connected the Yun to my WiFi network, it has the Ip Address 192.168.2.105, my Pc has the IP Adress 192.168.2.103. I found this example for a TCP/IP communication in this forum, which I am running on the Yun:
#include <Bridge.h>
#include <YunClient.h>
#define PORT 80
// Define our client object
YunClient client;
void setup()
{
// Bridge startup
Bridge.begin();
Serial.begin(9600);
while (!Serial); // wait for a serial connectionM
}
void loop()
{
// Make the client connect to the desired server and port
IPAddress addr(192, 168, 2, 103);
// Or define it using a single unsigned 32 bit value
// IPAddress addr(0xc0a8sab9); // same as 192.168.42.185
// Or define it using a byte array
// const uint8 addrBytes = {192, 168, 42, 185};
// IPAddress addr(addrBytes);
client.connect(addr, PORT);
// Or connect by a server name and port.
// Note that the Yun doesn't support mDNS by default, so "Yun.local" won't work
// client.connect("ServerName.com", PORT);
if (client.connected())
{
Serial.println("Connected to the server.");
// Send something to the client
//client.println("Something...");
client.println(3);
// Cheap way to give the server time to respond.
// A real application (as opposed to this simple example) will want to be more intelligent about this.
delay (250);
// Read all incoming bytes available from the server and print them
while (client.available())
{
char c = client.read();
Serial.print(c);
}
Serial.flush();
// Close the connection
client.stop();
}
else
Serial.println("Could not connect to the server.");
// Give some time before trying again
delay (10000);
}
In Simulink I use the TCP/IP receive und TCP/IP send blocks from the Instrument toolbox in the model attached, but I am always getting the error message
Error evaluating registered method 'Start' of MATLAB S-Function 'stcpiprb' in 'host_receive/TCP//IP Receive'.
Caused by:
Unsuccessful open: Connection timed out: connect
I would expect, that the sketch and simulink would create a echo, starting with 2 and getting doubled every time.
I don't know a lot about Wifi and TCP/IP communication, can someone help me please to set up a communication?