#include <SPI.h>
#include <Ethernet.h>
// Set up Ethernet connection
byte mac[] = { 0x56, 0x25, 0xDF, 0x9E, 0x43, 0x1E };
IPAddress ip(192, 168, 42, 52);
// Set up LED pin
int ledPin = 9;
EthernetClient client; // Define an EthernetClient object
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
Ethernet.begin(mac, ip); // Start Ethernet with the given MAC and IP addresses
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
// Make sure Ethernet is connected and client is available
if (Ethernet.hardwareStatus() == EthernetNoHardware || Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet not connected");
return;
}
// Make a GET request to the server
if (client.connect("192.168.42.52", 80)) {
Serial.println("Connected to server");
client.println("GET /E:\\lio/pexels-asad-photo-maldives-1456291 HTTP/1.1");
client.println("Host: 192.168.42.52");
client.println("Connection: close");
client.println();
} else {
Serial.println("Connection failed");
return;
}
// Check if there are incoming bytes available
while (client.connected() && !client.available()) {
delay(1);
}
// Read and process incoming bytes
while (client.available()) {
char c = client.read(); // Read byte by byte
digitalWrite(ledPin, HIGH); // Turn on LED
delayMicroseconds(c * 10); // Modulate LED with file data (adjust delay as needed)
digitalWrite(ledPin, LOW); // Turn off LED
delayMicroseconds(10); // Small delay
}
// Disconnect from the server
client.stop();
// Wait before making another request
delay(1000);
}