I have the issue that I want to send a UDP package via Powershell to my Arduino. Thus far this worked but I ran into my problem: When I am sending my UDP package with powershell after the Arduino received the UDP package once it appears that it will never run/do anything with the Ethernet.parsePackage() again.
It only ever spits out the package size and the data within it but then i can send a UDP package via powershell as often as I want and nothing will happen again.
This is just a test program to get me used to program the project that I am planning to do, however I need to be able to turn on a Relay every single time the Arduino is pinged and not only once.
I am using a Arduino Nano together with a ENC26J60 Ethernet breakout board.
I suspect I am missing something that causes this?
What size packet are you sending your your Nano? The code only reads one byte. Is messageSize == 1? If you post the output of SerialMonitor, that would be helpful.
If your packet is larger than 1, you never finish reading it so you can never start reading a new packet.
Also, every time you run powershell, you are opening the serial port (I am guessing) which resets your Nano so a best practice would be to have to print something in setup() like "hello world" so you can detect that an know it is ready before pinging it.
This is the powershell script I have for pinging the arduino, dont mind the changed Port Number since I have changed the port for the arduino too for testing if that fixes it. It didnt.
When pinging the arduino the Serial Monitor shows "11" followed by a "112" which i assume to be correct. The test password of "password123" has 11 bytes and printing the message will probably just convert that into hexadecimal or something and that is why it reads incorrect.
However as you say now since my package reads 11 and itll never finish reading if the package is larger than 1 I assume this is my issue? How would i go about fixing that?
# Define the target IP and port
>> $targetIp = "192.168.178.25" # Replace with your Arduino's IP address
>> $targetPort = 1496 # The port Arduino is listening on
>>
>> # Create a UDP client
>> $udpClient = New-Object System.Net.Sockets.UdpClient
>>
>> # Encode the message as a byte array
>> $password = "password123"
>> $bytes = [System.Text.Encoding]::ASCII.GetBytes($password)
>>
>> # Send the UDP packet to the Arduino
>> $udpClient.Send($bytes, $bytes.Length, $targetIp, $targetPort)
>>
>> # Close the UDP client
>> $udpClient.Close()
>>
>> Write-Output "Password sent to Arduino."
Thank you, that indeed fixed the problem without any additional code.
I had already suggested rather shady workarounds by ending the UDP Protocol with udp.stop() and instantly restarting it again with udp.begin() in the if statement.