Skip to content

Commit 815e17b

Browse files
Add WiFiClient example for w6100 for CI (earlephilhower#2348)
1 parent 32f0311 commit 815e17b

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
This sketch establishes a TCP connection to a "quote of the day" service.
3+
It sends a "hello" message, and then prints received data.
4+
*/
5+
6+
#include <W6100lwIP.h>
7+
8+
const char* host = "djxmmx.net";
9+
const uint16_t port = 17;
10+
11+
Wiznet6100lwIP eth(1 /* chip select */);
12+
13+
void setup() {
14+
// Set up SPI pinout to match your HW
15+
SPI.setRX(0);
16+
SPI.setCS(1);
17+
SPI.setSCK(2);
18+
SPI.setTX(3);
19+
20+
Serial.begin(115200);
21+
delay(5000);
22+
Serial.println();
23+
Serial.println();
24+
Serial.println("Starting Ethernet port");
25+
26+
// Start the Ethernet port
27+
if (!eth.begin()) {
28+
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
29+
while (1) {
30+
delay(1000);
31+
}
32+
}
33+
34+
while (!eth.connected()) {
35+
Serial.print(".");
36+
delay(500);
37+
}
38+
39+
Serial.println("");
40+
Serial.println("Ethernet connected");
41+
Serial.println("IP address: ");
42+
Serial.println(eth.localIP());
43+
}
44+
45+
void loop() {
46+
static bool wait = false;
47+
48+
Serial.print("connecting to ");
49+
Serial.print(host);
50+
Serial.print(':');
51+
Serial.println(port);
52+
53+
// Use WiFiClient class to create TCP connections
54+
WiFiClient client;
55+
if (!client.connect(host, port)) {
56+
Serial.println("connection failed");
57+
delay(5000);
58+
return;
59+
}
60+
61+
// This will send a string to the server
62+
Serial.println("sending data to server");
63+
if (client.connected()) {
64+
client.println("hello from RP2040");
65+
}
66+
67+
// wait for data to be available
68+
unsigned long timeout = millis();
69+
while (client.available() == 0) {
70+
if (millis() - timeout > 5000) {
71+
Serial.println(">>> Client Timeout !");
72+
client.stop();
73+
delay(60000);
74+
return;
75+
}
76+
}
77+
78+
// Read all the lines of the reply from server and print them to Serial
79+
Serial.println("receiving from remote server");
80+
// not testing 'client.connected()' since we do not need to send data here
81+
while (client.available()) {
82+
char ch = static_cast<char>(client.read());
83+
Serial.print(ch);
84+
}
85+
86+
// Close the connection
87+
Serial.println();
88+
Serial.println("closing connection");
89+
client.stop();
90+
91+
if (wait) {
92+
delay(300000); // execute once every 5 minutes, don't flood remote service
93+
}
94+
wait = true;
95+
}

libraries/lwIP_w6100/keywords.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Library (KEYWORD1)
7+
#######################################
8+
9+
W6100lwIP KEYWORD1
10+
Wiznet6100lwIP KEYWORD1
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
#######################################
17+
# Constants (LITERAL1)
18+
#######################################
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=lwIP_w6100
2+
version=1
3+
author=Stefan Nuernberger
4+
maintainer=esp8266/Arduino
5+
sentence=Ethernet driver
6+
paragraph=Wiznet6100 ethernet drivers for lwIP and esp8266 Arduino from https://github.com/njh/W5100MacRaw
7+
category=Communication
8+
url=https://github.com/esp8266/Arduino
9+
architectures=rp2040
10+
dot_a_linkage=true

0 commit comments

Comments
 (0)