UPD und Char to Char*

Hallo ich bin neu hier. Ich möchte Steuerbefehle über TCP/UDp an den Arduino Mega mit Ethernet Shield und DMX. Hab mich mit dem dem UPDSendReciveString versucht. Soweit läuft es auch nur es kommt ein Packet von irgendwo und dann läuft es nicht mehr.

#include <DmxSimple.h>
#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 178, 210);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "ack";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  DmxSimple.usePin(3);
  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  
    if(packetSize)
  {
    for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;

 
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());
 
    memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);
 
      char *ptr = packetBuffer;
            
      if (strncmp(ptr, "dmx", 3) == 0) {
      // get data (format: dmx000v000)
      char buff[5];
      memset(buff, 0, 5);

      // get channel
      strncpy (buff, &ptr[3], 3);
      int Channel = atoi(buff);

      // get value
      strncpy (buff, &ptr[7], 3);
      int value = atoi(buff);
      
      Serial.println(Channel);
      Serial.println(value);
      
      
      //DmxSimple.write(Channel,value)
      }  
    
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  
  delay(10);
}

Hier die Ausgabe des Serial Monitors

Received packet of size 10
From 192.168.178.21, port 8888
Contents:
dmx000v000
0
0

Received packet of size 10
From 192.168.178.21, port 8888
Contents:
dmx000v000
0
0

Received packet of size -19967
From 118.32.48.32, port 49312
Contents:

Sobald eine andere IP auftaucht läuft es nicht mehr. Warum?
Wo kommt die IP her?

Ich habe auch versucht es über TCP (Chat Server) zulösen.

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,178, 210);
IPAddress gateway(192,168,178, 1);
IPAddress subnet(255, 255, 0, 0);


// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();

  // when the client sends the first byte, say hello:
  if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();    
      Serial.println("We have a new client");
      client.println("Hello, client!"); 
      alreadyConnected = true;
    } 

      if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
       
      char *ptr = thisChar;
      
      if (strncmp(ptr, "dmx", 3) == 0) {
      // get data (format: dmx000v000)
      char buff[5];
      memset(buff, 0, 5);

      // get channel
      strncpy (buff, &ptr[3], 3);
      int Channel = atoi(buff);

      // get value
      strncpy (buff, &ptr[7], 3);
      int value = atoi(buff);
      
      Serial.println(Channel);
      Serial.println(value);


      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
}

Aber ich bekomme den Client.read() nicht hin

char thisChar = client.read();

char ptr = thisChar; (invalid conversion from ‘char’ to 'char’)

if (strncmp(ptr, “dmx”, 3) == 0) {
// get data (format: dmx000v000)
char buff[5];
memset(buff, 0, 5);

// get channel
strncpy (buff, &ptr[3], 3);
int Channel = atoi(buff);

// get value
strncpy (buff, &ptr[7], 3);
int value = atoi(buff);

vielleicht kann mir mal jemand einen Tip geben. A" warum beim UDP eine Andere IP kommt und sich der Arduino aufhängt. Und B wie man von char to char* convertiert.

So long
Squaredrone

Wie man von char to char* convertiert

Gar nicht. Da hat man was falsch verstanden. char* ist ein Zeiger auf ein (oder mehrere)char.