Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.10.2 to fix bug if using QNEthernet staticIP
Browse files Browse the repository at this point in the history
### Release v1.10.2

1. Fix bug when using `QNEthernet` staticIP. Check [QNEthernet and NativeEthernet staticIP not working with WS Server #39](#39)
2. Add staticIP option to `NativeEthernet` examples
2. Update `Packages' Patches`
  • Loading branch information
khoih-prog authored Mar 14, 2022
1 parent 9a5c131 commit 0d5fced
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,24 @@ byte mac[6];
// Enter websockets server port.
const uint16_t port = 81;

// Define how many clients we accpet simultaneously.
// Define how many clients we accept simultaneously.
const byte maxClients = 4;

WebsocketsClient clients[maxClients];
WebsocketsServer server;

//#define USING_DHCP true
#define USING_DHCP false

#if !USING_DHCP
// Set the static IP address to use if the DHCP fails to assign
IPAddress myIP(192, 168, 2, 222);
IPAddress myNetmask(255, 255, 255, 0);
IPAddress myGW(192, 168, 2, 1);
//IPAddress mydnsServer(192, 168, 2, 1);
IPAddress mydnsServer(8, 8, 8, 8);
#endif

void setup()
{
// Set the MAC address.
Expand All @@ -83,15 +95,32 @@ void setup()
Serial.println(WEBSOCKETS2_GENERIC_VERSION);

// Connect to ethernet.
if (Ethernet.begin(mac))
#if USING_DHCP
if (Ethernet.begin(mac))
{
Serial.println("Ethernet connected");
Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");
}
else
else
{
Serial.println("Ethernet failed");
}

// give the Ethernet shield minimum 1 sec for DHCP
delay(1000);
#else
// Use Static IP
Ethernet.begin(mac, myIP, mydnsServer);

Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");

// give the Ethernet shield minimum 2 secs for staticP to initialize:
delay(2000);
#endif

// Start websockets server.
server.listen(port);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ WebsocketsServer socketServer;
//EthernetServer httpServer;
EthernetServer httpServer(WEBSERVER_PORT);

//#define USING_DHCP true
#define USING_DHCP false

#if !USING_DHCP
// Set the static IP address to use if the DHCP fails to assign
IPAddress myIP(192, 168, 2, 222);
IPAddress myNetmask(255, 255, 255, 0);
IPAddress myGW(192, 168, 2, 1);
//IPAddress mydnsServer(192, 168, 2, 1);
IPAddress mydnsServer(8, 8, 8, 8);
#endif

void setup()
{
// Set the MAC address.
Expand All @@ -88,15 +100,32 @@ void setup()
Serial.println(WEBSOCKETS2_GENERIC_VERSION);

// Connect to ethernet.
if (Ethernet.begin(mac))
#if USING_DHCP
if (Ethernet.begin(mac))
{
Serial.println("Ethernet connected");
Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");
}
else
else
{
Serial.println("Ethernet failed");
}

// give the Ethernet shield minimum 1 sec for DHCP
delay(1000);
#else
// Use Static IP
Ethernet.begin(mac, myIP, mydnsServer);

Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");

// give the Ethernet shield minimum 2 secs for staticP to initialize:
delay(2000);
#endif

// Start websockets server.
socketServer.listen(websocketsPort);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ byte mac[6];
//const char* url = "ws://echo.websocket.org";
const char* url = "ws://192.168.2.30:8080";

void setup() {
//#define USING_DHCP true
#define USING_DHCP false

#if !USING_DHCP
// Set the static IP address to use if the DHCP fails to assign
IPAddress myIP(192, 168, 2, 222);
IPAddress myNetmask(255, 255, 255, 0);
IPAddress myGW(192, 168, 2, 1);
//IPAddress mydnsServer(192, 168, 2, 1);
IPAddress mydnsServer(8, 8, 8, 8);
#endif

void setup()
{
// Set the MAC address.
teensyMAC(mac);

Expand All @@ -73,17 +86,32 @@ void setup() {
Serial.println(WEBSOCKETS2_GENERIC_VERSION);

// Connect to ethernet.
#if USING_DHCP
if (Ethernet.begin(mac))
{
Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");
}
}
else
{
Serial.println("Ethernet failed");
}

// give the Ethernet shield minimum 1 sec for DHCP
delay(1000);
#else
// Use Static IP
Ethernet.begin(mac, myIP, mydnsServer);

Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");

// give the Ethernet shield minimum 2 secs for staticP to initialize:
delay(2000);
#endif

// Connect to websocket server.
if (client.connect(url))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ byte mac[6];
// Enter websockets server port.
const uint16_t port = 80;

//#define USING_DHCP true
#define USING_DHCP false

#if !USING_DHCP
// Set the static IP address to use if the DHCP fails to assign
IPAddress myIP(192, 168, 2, 222);
IPAddress myNetmask(255, 255, 255, 0);
IPAddress myGW(192, 168, 2, 1);
//IPAddress mydnsServer(192, 168, 2, 1);
IPAddress mydnsServer(8, 8, 8, 8);
#endif

void setup()
{
// Set the MAC address.
Expand All @@ -72,13 +84,32 @@ void setup()
Serial.println(WEBSOCKETS2_GENERIC_VERSION);

// Connect to ethernet.
if (Ethernet.begin(mac))
#if USING_DHCP
if (Ethernet.begin(mac))
{
Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");
}
else
{
Serial.println("Ethernet connected");
} else {
Serial.println("Ethernet failed");
}

// give the Ethernet shield minimum 1 sec for DHCP
delay(1000);
#else
// Use Static IP
Ethernet.begin(mac, myIP, mydnsServer);

Serial.print("Ethernet connected (");
Serial.print(Ethernet.localIP());
Serial.println(")");

// give the Ethernet shield minimum 2 secs for staticP to initialize:
delay(2000);
#endif

// Start websockets server.
server.listen(port);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ void setup()

#endif

// give the Ethernet shield minimum 1 sec for DHCP and 2 secs for staticP to initialize:
#if USING_DHCP
delay(1000);
#else
delay(2000);
#endif

// Start websockets server.
server.listen(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ void setup()

#endif

// give the Ethernet shield minimum 1 sec for DHCP and 2 secs for staticP to initialize:
#if USING_DHCP
delay(1000);
#else
delay(2000);
#endif

// Start websockets server.
socketServer.listen(websocketsPort);

Expand Down
Loading

0 comments on commit 0d5fced

Please sign in to comment.