Upload files to "eth_tcp_sender"
This commit is contained in:
commit
2df4f31675
80
eth_tcp_sender/eth_tcp_sender.ino
Normal file
80
eth_tcp_sender/eth_tcp_sender.ino
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include <NativeEthernet.h>
|
||||||
|
|
||||||
|
byte mac[] = { 0x04, 0xE9, 0xE5, 0x10, 0x00, 0x01 };
|
||||||
|
IPAddress ip(192, 168, 1, 100);
|
||||||
|
IPAddress serverIP(192, 168, 1, 101);
|
||||||
|
const int serverPort = 8888;
|
||||||
|
int i;
|
||||||
|
byte cnt = 0;
|
||||||
|
|
||||||
|
union split_u16{
|
||||||
|
uint16_t size16;
|
||||||
|
byte size8[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
union split_u16 split;
|
||||||
|
|
||||||
|
EthernetClient client;
|
||||||
|
#define max_package_size 1024
|
||||||
|
|
||||||
|
uint16_t package_size = 1024;
|
||||||
|
byte buffer[max_package_size];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(921600);
|
||||||
|
//while (!Serial);
|
||||||
|
|
||||||
|
Serial.println("Initializing Ethernet...");
|
||||||
|
Ethernet.begin(mac, ip);
|
||||||
|
|
||||||
|
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
|
||||||
|
Serial.println("Ethernet hardware not found!");
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Ethernet.linkStatus() == LinkOFF) {
|
||||||
|
Serial.println("Ethernet cable not connected!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("Connecting to server...");
|
||||||
|
|
||||||
|
if (client.connect(serverIP, serverPort)) {
|
||||||
|
Serial.println("Connected to server!");
|
||||||
|
} else {
|
||||||
|
Serial.println("Connection failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < max_package_size/*-random(300)*/; i++) {
|
||||||
|
buffer[i] = i; // Fill buffer with sample data (0-255)
|
||||||
|
}
|
||||||
|
|
||||||
|
package_size=i;
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
send_package();
|
||||||
|
//delayMicroseconds(100); // Small delay to avoid overloading the receiver
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_package(){
|
||||||
|
if (!client.connected()) {
|
||||||
|
Serial.println("Connection lost. Reconnecting...");
|
||||||
|
client.stop();
|
||||||
|
delay(1000);
|
||||||
|
client.connect(serverIP, serverPort);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char SendMsg[] = "P_A";
|
||||||
|
|
||||||
|
//Confirm request is sent
|
||||||
|
client.write(SendMsg, sizeof(SendMsg));
|
||||||
|
|
||||||
|
//Serial.println("Sending packet...");
|
||||||
|
client.write(buffer, package_size);
|
||||||
|
cnt++; buffer[0] = cnt;
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user