I've been trying to get this connection established for some time, using several different AI-generated sketches but have been unable to get anything to work. UDP is working on other scripts between the arduino & NTP servers though. I have both the arduino & pc on the same wireless router, on the same subnet on a Mikrotik router running torch. I never see any UDP traffic show up from either end. both are connecting to the router.
arduino code:
#include <WiFiS3.h>
#include <WiFiUdp.h>
#include "arduino-secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
while (!Serial) {};
// Connect to Wi-Fi
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
delay(5000);
}
server.begin();
printWifiStatus();
}
void loop() {
// Listen for incoming Windows 11 clients
WiFiClient client = server.available();
if (client) {
Serial.println("New Windows client connected!");
// Transfer packet data
client.println("Hello from Arduino UNO R4 WiFi!");
// Close the connection to allow a clean reset
client.stop();
Serial.println("Packet sent and client disconnected.");
}
}
void printWifiStatus() {
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
Python code Running on Thonny (if that makes a difference):
import socket
# Replace with your Arduino's IP address printed to the Serial Monitor
arduino_ip = '192.168.88.118'
arduino_port = 80
try:
# Create a TCP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((arduino_ip, arduino_port))
# Receive the packet data
data = client_socket.recv(1024)
print("Received Packet:", data.decode('utf-8'))
except Exception as e:
print(f"Error: {e}")
finally:
client_socket.close()
The arduino makes it through the setup, but prints nothing else on the serial console after that. The python console gives me the error message: Error: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Both sketch & script were generated in the same request for an example of how to transfer several bytes between machines. I updated the WiFiS3 firmware to 0.6.0, which seems to be the latest.
In addition to the base R4 WiFi, I have a 3/5" touchscreen display & a custom board attached to D10-D13 which work on my main script. I will be using this code to transfer a timestamp from the arduino to the PC to be used as a file name for a 4 byte data packet to be stored on the pc. Initially I had the pc connected to a wired ethernet connection on the same subnet but when I couldn't see any UDP packets making it thouugh the router, I shifted to wireless.
I tried several other options, other UDP code, POST, RUDP, nothing works. (I don't really care what protocol I end up with, the 2 machines will be same subnet & if I loose a packet it won't be the end of the world.)
Almost all my experience has been in hardware design for over 50 years & needless to say going from assembly language back then to C now is being quite a learning curve!
I'd say that this is giving me grey hair if I didn't already have it!
Peace, Pat