udp controller

Hey guys

So I have a project for school and I want to use an arduino as a controller.
I have a LOLIN32 which has a wifi connection.
Ihave already made some code for sending the UDP packet:

#include <WiFi.h>
#include <WiFiUdp.h>

// WiFi network name and password:
const char * networkName = "mywifi";
const char * networkPswd = "pasword";

//IP address to send UDP data to:
// either use the ip address of the server or
// a network broadcast address
const char * udpAddress = "my ip";
const int udpPort = 25;

//Are we currently connected?
boolean connected = false;

//The udp library class
WiFiUDP udp;

void setup(){
  // Initilize hardware serial:
  Serial.begin(115200);
 
  //Connect to the WiFi network
  connectToWiFi(networkName, networkPswd);
}

void loop(){
  //only send data when connected
  if(connected){
    //Send a packet
    udp.beginPacket(udpAddress,udpPort);
    udp.printf("Seconds since boot: %u", millis()/1000);
    udp.endPacket();
  }
  //Wait for 1 second
  delay(1000);
}

void connectToWiFi(const char * ssid, const char * pwd){
  Serial.println("Connecting to WiFi network: " + String(ssid));

  // delete old config
  WiFi.disconnect(true);
  //register event handler
  WiFi.onEvent(WiFiEvent);
 
  //Initiate connection
  WiFi.begin(ssid, pwd);

  Serial.println("Waiting for WIFI connection...");
}

//wifi event handler
void WiFiEvent(WiFiEvent_t event){
    switch(event) {
      case SYSTEM_EVENT_STA_GOT_IP:
          //When connected set
          Serial.print("WiFi connected! IP address: ");
          Serial.println(WiFi.localIP());
          //initializes the UDP state
          //This initializes the transfer buffer
          udp.begin(WiFi.localIP(),udpPort);
          connected = true;
          break;
      case SYSTEM_EVENT_STA_DISCONNECTED:
          Serial.println("WiFi lost connection");
          connected = false;
          break;
    }
}
[/code ]

But I have little experience with Csharp and i want to know how to receive a UDP packet, read it and then have something happen in unity.
Does anyone here know how to receive UDP packets in unity?
Sorry for my bad grammar.

Kind regards
Ethan

hey guys
I just changed the UDP port to 25.
And I downloaded a free microsoft app.
And it works!
Cheers
Ethan

1 Like

how do you manage the data in unity?

Please create your own thread detailing your problem rather than posting a vague question necroing a several year old thread.

1 Like