Greetings, dear ones.
Please tell a beginner how to adopt this code on Teensy 4.1 ?
with Arduino NANO and W5500, it works very well, but there were not enough free pins,
I've been fighting for two days, nothing works, please help!
I looked at the QNEthernet library, but for me it is very difficult to understand.
Please tell a beginner how to adopt this code on Teensy 4.1 ?
with Arduino NANO and W5500, it works very well, but there were not enough free pins,
I've been fighting for two days, nothing works, please help!
I looked at the QNEthernet library, but for me it is very difficult to understand.
Code:
#include <Ethernet.h>
#define UDP_Port 5007 // UDP Port
EthernetUDP udpServer;
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetServer tcpServer(5005); // TCP Port
boolean alreadyConnected = false; // regardless of whether the client was connected earlier or not
char packetBufferTCP[256];
byte len = 0;
void setup() {
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
while (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected!");
for (;;); // There's no point in continuing, we're not doing anything else
}
Serial.println("Start...");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP!");
for (;;); // There's no point in continuing, we're not doing anything else
}
Ethernet.begin(mac, Ethernet.localIP()); // Launching Ethernet and UDP
Serial.print("Connected, local IP address: ");
Serial.println(Ethernet.localIP());
udpServer.begin(UDP_Port);
tcpServer.begin();
}
void loop() {
uint8_t packetSize = udpServer.parsePacket(); // if there is available data, we read the package
EthernetClient tcpClient = tcpServer.available(); // we are waiting for a new client
// when the client sends the first byte
if (tcpClient) {
tcpClient.flush(); // clear the input buffer:
if (tcpClient.available() > 0) { // we read the bytes coming from the client
len = tcpClient.read(packetBufferTCP, 256); // reading the packet and transferring it to the buffer
}
}
//...
//...
} //===== End Loop =====
Last edited: