Hallo,
ich versuche gerade eine Kommunikation zwischen Maltab/Simulink und
einem Arduino Yun über Wlan aufzubauen. Ich habe nicht wirklich viel
Ahnung von drahtloser Kommunikation aber theoretisch müsste dies doch
über TCP/IP möglich sein oder?
Ich hab hier einen Beispiel Sketch für den Arduino gefunden, der ein
echo erzeugen soll. http://forum.arduino.cc/index.php?topic=311200.0
Mit angepasster IP Adresse und anderem Port sieht dieser bei mir so aus:
1 | #include <Bridge.h>
|
2 | #include <YunClient.h>
|
3 |
|
4 | #define PORT 80
|
5 |
|
6 | // Define our client object
|
7 | YunClient client;
|
8 |
|
9 | void setup()
|
10 | {
|
11 | // Bridge startup
|
12 | Bridge.begin();
|
13 |
|
14 | Serial.begin(9600);
|
15 |
|
16 | while (!Serial); // wait for a serial connectionM
|
17 | }
|
18 |
|
19 | void loop()
|
20 | {
|
21 | // Make the client connect to the desired server and port
|
22 | IPAddress addr(192, 168, 2, 103);
|
23 |
|
24 | // Or define it using a single unsigned 32 bit value
|
25 | // IPAddress addr(0xc0a8sab9); // same as 192.168.42.185
|
26 |
|
27 | // Or define it using a byte array
|
28 | // const uint8 addrBytes = {192, 168, 42, 185};
|
29 | // IPAddress addr(addrBytes);
|
30 |
|
31 | client.connect(addr, PORT);
|
32 |
|
33 | // Or connect by a server name and port.
|
34 | // Note that the Yun doesn't support mDNS by default, so "Yun.local" won't work
|
35 | // client.connect("ServerName.com", PORT);
|
36 |
|
37 | if (client.connected())
|
38 | {
|
39 | Serial.println("Connected to the server.");
|
40 |
|
41 | // Send something to the client
|
42 | //client.println("Something...");
|
43 | client.println(3);
|
44 | // Cheap way to give the server time to respond.
|
45 | // A real application (as opposed to this simple example) will want to be more intelligent about this.
|
46 | delay (250);
|
47 |
|
48 | // Read all incoming bytes available from the server and print them
|
49 | while (client.available())
|
50 | {
|
51 | char c = client.read();
|
52 | Serial.print(c);
|
53 | }
|
54 | Serial.flush();
|
55 |
|
56 | // Close the connection
|
57 | client.stop();
|
58 | }
|
59 | else
|
60 | Serial.println("Could not connect to the server.");
|
61 |
|
62 | // Give some time before trying again
|
63 | delay (10000);
|
64 | }
|
Der Yun hat überigens die IP 192.168.2.105 und mein Pc hat die IP
Adresse 192.168.2.103.
In Simulink nutze ich die TCP/IP send und receive Blöcke aus der
Instrument control toolbox, mein Modell habe ich als screenshot
angehangen.
In Simulink bekomme ich immer folgenden Fehler:
1 | Error evaluating registered method 'Start' of MATLAB S-Function 'stcpiprb' in 'host_receive/TCP//IP Receive'.
|
2 | Caused by:
|
3 | Unsuccessful open: Connection timed out: connect
|
und der Yun kann auch keine Verbindung aufbauen. Testweise möchte ich
erstmal einfach ein paar Zahlen zwischen Simulink und dem Yun hin und
her schicken, aber was mache ich falsch, dass schon keine Verbindung
aufgebaut werden kann?