Created
May 1, 2024 22:10
-
-
Save gabonator/5743f53fcb9fce16ade550afbaa220ff to your computer and use it in GitHub Desktop.
wiznet 5500 keyes ks0304
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ks0304 Keyestudio W5500 ETHERNET DEVELOPMENT BOARD (WITHOUT POE) | |
// minimal http client code with "EthernetWebServer" library from "Khoi Hoang" | |
#define SerialDebug Serial | |
#define DEBUG_ETHERNET_GENERIC_PORT SerialDebug | |
#define _ETG_LOGLEVEL_ 0 | |
#define USE_THIS_SS_PIN 10 | |
#define SENDCONTENT_P_BUFFER_SZ 512 | |
#include <SPI.h> | |
#define ETHERNET_LARGE_BUFFERS | |
#include "Ethernet_Generic.h" | |
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }; | |
IPAddress ip(192, 168, 2, 222); | |
EthernetClient client; | |
void setup() | |
{ | |
SerialDebug.begin(115200); | |
SerialDebug.print("\nStarting WebClient\n"); | |
Ethernet.init (USE_THIS_SS_PIN); | |
Ethernet.begin(mac, ip); | |
//Ethernet.begin(mac); | |
delay(1000); | |
SerialDebug.print(F("Connected! IP address: ")); | |
SerialDebug.println(Ethernet.localIP()); | |
if ( (Ethernet.getChip() == w5500) || (Ethernet.getChip() == w6100) || (Ethernet.getAltChip() == w5100s) ) | |
{ | |
SerialDebug.print(F("Speed: ")); | |
SerialDebug.print(Ethernet.speedReport()); | |
SerialDebug.print(F(", Duplex: ")); | |
SerialDebug.print(Ethernet.duplexReport()); | |
SerialDebug.print(F(", Link status: ")); | |
SerialDebug.println(Ethernet.linkReport()); | |
} | |
} | |
void printoutData() | |
{ | |
const int timeout = 300; | |
long t0 = millis(); | |
char buf[5] = {0}; | |
bool body = false; | |
while (millis() - t0 < timeout && client.connected()) | |
{ | |
while (client.available()) | |
{ | |
char c = client.read(); | |
buf[0] = buf[1]; | |
buf[1] = buf[2]; | |
buf[2] = buf[3]; | |
buf[3] = c; | |
t0 = millis(); | |
if (body) | |
SerialDebug.write(c); | |
if (strcmp(buf, "\r\n\r\n") == 0) | |
body = true; | |
} | |
} | |
} | |
void loop() | |
{ | |
if (client.connect(IPAddress(192, 168, 2, 1), 8888)) | |
{ | |
SerialDebug.print(F("Server response: ")); | |
client.println("GET /test.txt HTTP/1.1\r\nHost: 192.168.2.1\r\nConnection: close\r\n\r\n"); | |
printoutData(); | |
client.stop(); | |
} else | |
SerialDebug.println(F("Server not available")); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment