Hello,
I am trying to make simple project where I send data to serial port and it will show it on TCP and other way around, when I type something in TCP server it should show up on serial.
Board: Arduino Leonardo ETH (genuine) - connected to TP-link router via cable
Computer 1 (windows 10, using Hercules for serial monitoring and RS232 to USB adapter)
Computer 2 (Kali linux, and using terminal with netcat to connect via netcat) - this computer is connected to TP-link router via wifi
Everything seems to work expect: When I type let's say number "1" in serial terminal i get output on TCP "g" when i type "2" in serial terminal i get output of "3" in TCP
When i type "1" in TCP i get serial output "g=" when i type "2" in TCP i get serial out "3="
Here is the code, i cannot figure out whats wrong ...
#include <SPI.h>
#include <Ethernet.h>
// Arduino MAC aadress
// Arduino IP aadress
byte mac[] = {
0x90, 0xA2, 0xDA, 0x10, 0x3C, 0x74
};
IPAddress ip(192, 168, 1, 100);
#define UART_TCP_PORT 3300
#define TR_BAUD_RATE 115200
EthernetServer server(UART_TCP_PORT);
void setup() {
while (!Serial) { ; }
// initialize CS pin
Ethernet.init(10);
// initialize the ethernet device
Ethernet.begin(mac, ip);
// Open serial communication
SERIAL_PORT_HARDWARE.begin(TR_BAUD_RATE);
// start listening for clients
server.begin();
}
void loop() {
// wait for a TCP client:
EthernetClient client = server.available();
// when the TCP client is connected
if (client) {
// and sends the byte
if (client.available() > 0) {
// read the bytes incoming from the TCP client and send it to UART
SERIAL_PORT_HARDWARE.write(client.read());
}
}
// when TR module sends the byte, read it and send it to TCP client
if (SERIAL_PORT_HARDWARE.available()) {
server.write(SERIAL_PORT_HARDWARE.read());
}
}