Hallo
Ich habe mehrere Arduinos im Einsatz, die ich teilweise an verschiedenen Stationen positioniert habe und auf einem mobilen Roboter. Ziel ist es, dass der Arduino an der Station dem mobilen Roboter bekannt gibt wenn die Station fertig ist.
Bei zwei Stationen funktioniert, dass hervorragend. Aber bei der dritten habe ich ein Problem. Bei dieser muss der mobile Roboter bekannt geben das er da ist, damit die Station starten kann. Der Arduino an der Station empfängt das UDP-Paket und schaltet darauf hin einen digitalen Ausgang. Wenn die Station fertig ist, setzt die übergeordnete SPS ihren Ausgang. Der Arduino registriert dies und sendet dem mobilen Roboter wieder ein UDP-Paket. Soweit zur Theorie.
Mein Problem ist nun, dass diese Kommunikation nicht zu Stande kommt. Der Arduino am Roboter sendet zwar das Paket, der an der Station reagiert aber nicht. Das selbe gilt umgekehrt. Die Station sendet, der mobile Roboter empfängt aber nichts.
Ich hab den Code schon überprüft, indem ich mich mit meine Laptop in das Netzwerk eingeklinkt habe und per Wireshark die Kommunikation aufgezeichnet habe. Und tatsächlich, es wird zwar an meinen PC gesendet, aber nicht an den anderen Arduino, soweit ich sehe. Sende ich aber von meinem PC ein UDP-Paket an einen der Arduinos kommt dieses an und er reagiert so wie gewollt.
Weil ich langsam nicht mehr weiter weiß, poste ich hier einmal den Code für die beiden Arduinos. Die Verkabelung hab ich mehrfach überprüft und mit dem PC funktioniert es ja auch, ich weiß einfach nicht mehr weiter.
Hier einmal der Code für den Arduino am mobilen Roboter:
/*
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
char ssid[] = "linksys"; // your network SSID (name)
int keyIndex = 0; // your network key Index number (needed only for WEP)
IPAddress ip_Robot(10,0,0,3);//static IPAddress Arduino Robot
IPAddress ip_Station(10,0,0,5);//static IPAddress Arduino Station
IPAddress ip_PC(10,0,0,10);//static IPAddress PC
unsigned int localPort = 2390; // local port to listen on
unsigned int stationPort = 2391;
char packetBuffer[255]; //buffer to hold incoming packet
char SendBuffer[] = " Start";
const int buttonPin = 2;
const int startPin = 9;
WiFiUDP Udp;
void setup() {
pinMode(buttonPin, OUTPUT);
pinMode(startPin, INPUT);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
while (true);
}
WiFi.config(ip_Robotino);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
status = WiFi.begin(ssid);
delay(10000);
}
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize)
{
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
if (len == 5)
{
digitalWrite(buttonPin, HIGH);
delay(5000);
digitalWrite(buttonPin, LOW);
}
}
int state = digitalRead(startPin);
if(state == HIGH)
{
Udp.beginPacket(ip_Station,stationPort);
Udp.write(SendBuffer);
Udp.endPacket();
Udp.beginPacket(ip_PC,stationPort);
Udp.write(SendBuffer);
Udp.endPacket();
delay(1000);
}
}
Hier der Code für die Station:
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
char ssid[] = "linksys"; // your network SSID (name)
int keyIndex = 0; // your network key Index number (needed only for WEP)
IPAddress ip_Robo(10,0,0,3);//static IPAddress Arduino Robot
IPAddress ip_PC(10,0,0,10);//static IPAddress PC
IPAddress ip_Station(10,0,0,5);//static IPAddress Arduino Station
unsigned int localPort = 2391; // local port to listen on
unsigned int robotPort = 2390; // local port to listen on
char packetBuffer[255]; //buffer to hold incoming packet
char SendBuffer[] = " Start";
const int startPin = 2;//pinnumber for Station start
const int finishPin = 8;//pinnumber for Station finished
WiFiUDP Udp;
void setup() {
pinMode(startPin, OUTPUT);
pinMode(finishPin, INPUT);
if (WiFi.status() == WL_NO_SHIELD) {
while (true);
}
WiFi.config(ip_Station);
while ( status != WL_CONNECTED) {
status = WiFi.begin(ssid);
delay(10000);
}
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize)
{
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
if (len == 5)
{
digitalWrite(startPin, HIGH);
delay(5000);
digitalWrite(startPin, LOW);
}
}
int state = digitalRead(finishPin);
if(state == HIGH)
{
Udp.beginPacket(ip_Robot,robotPort);
Udp.write(SendBuffer);
Udp.endPacket();
Udp.beginPacket(ip_PC,robotPort);
Udp.write(SendBuffer);
Udp.endPacket();
delay(1000);
}
}