mWebSockets: Unable to ping IP of Arduino Uno (ATmega328) w/ W5500 after uploading simple-server.ino
I have been able to successfully compile and upload simple-server.ino to my ATmega328 board with a W5500 Ethernet Shield, but I have noticed a few issues with it. Firstly, If I open the Serial Monitor, I obtain something like
14:28:02.662 -> ⸮x⸮⸮⸮
Secondly, when I try and ping the IP Address via a Terminal using an Ethernet connection connected to the same subnet as the Arduino, I cannot successfully ping it:
PING 198.162.1.177 (198.162.1.177) 56(84) bytes of data.
From 198.162.1.21 icmp_seq=1 Destination Host Unreachable
From 198.162.1.21 icmp_seq=2 Destination Host Unreachable
From 198.162.1.21 icmp_seq=3 Destination Host Unreachable
What could be causing these errors? For reference, here is the example I uploaded:
#include <WebSocketServer.h>
using namespace net;
#if PLATFORM_ARCH == PLATFORM_ARCHITECTURE_SAMD21
# define _SERIAL SerialUSB
#else
# define _SERIAL Serial
#endif
#if NETWORK_CONTROLLER == NETWORK_CONTROLLER_WIFI
constexpr char kSSID[]{"SKYNET"};
constexpr char kPassword[]{"***"};
#else
byte mac[]{0xA8, 0x61, 0x0A, 0xAE, 0x69, 0x13};
IPAddress ip(198, 162, 1, 177);
#endif
constexpr uint16_t port = 3000;
WebSocketServer wss{port};
void setup() {
_SERIAL.begin(115200);
while (!_SERIAL)
;
#if NETWORK_CONTROLLER == NETWORK_CONTROLLER_WIFI
//_SERIAL.setDebugOutput(true);
_SERIAL.printf("\nConnecting to %s ", kSSID);
WiFi.mode(WIFI_STA);
WiFi.begin(kSSID, kPassword);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
_SERIAL.print(F("."));
}
_SERIAL.println(F(" connected"));
WiFi.printDiag(_SERIAL);
_SERIAL.print(F("Device IP: "));
_SERIAL.println(WiFi.localIP());
#else
_SERIAL.println(F("Initializing ... "));
// Ethernet.init(10);
Ethernet.init(53); // Mega2560
// Ethernet.init(5); // ESPDUINO-32
// Ethernet.init(PA4); // STM32
Ethernet.begin(mac, ip);
_SERIAL.print(F("Server running at "));
_SERIAL.print(Ethernet.localIP());
_SERIAL.print(F(":"));
_SERIAL.println(port);
#endif
wss.onConnection([](WebSocket &ws) {
const auto protocol = ws.getProtocol();
if (protocol) {
_SERIAL.print(F("Client protocol: "));
_SERIAL.println(protocol);
}
ws.onMessage([](WebSocket &ws, const WebSocket::DataType dataType,
const char *message, uint16_t length) {
switch (dataType) {
case WebSocket::DataType::TEXT:
_SERIAL.print(F("Received: "));
_SERIAL.println(message);
break;
case WebSocket::DataType::BINARY:
_SERIAL.println(F("Received binary data"));
break;
}
ws.send(dataType, message, length);
});
ws.onClose([](WebSocket &, const WebSocket::CloseCode, const char *,
uint16_t) { _SERIAL.println(F("Disconnected")); });
_SERIAL.print(F("New client: "));
_SERIAL.println(ws.getRemoteIP());
const char message[]{"Hello from Arduino server!"};
ws.send(WebSocket::DataType::TEXT, message, strlen(message));
});
wss.begin();
}
void loop() { wss.listen(); }
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (12 by maintainers)
If I explicitly specify the DNSserver, the gateway and the subnet inside the sketch and add the into Etherent.begin(), the appropriate IP address is now assigned. I suspect this issue was from a network connection issue as opposed to an Arduino hardware or software issue.
Thank you very much for your help!!