bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int port /*= DEFAULT_UDP_PORT*/, const char* local_host /*= nullptr*/) { virtual*/
| 46 | |
| 47 | //bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int port /*= DEFAULT_UDP_PORT*/, const char* local_host /*= nullptr*/) { |
| 48 | /*virtual*/ bool UDPInterface::start() { |
| 49 | const char* wifi_ssid = "wifi_ssid"; |
| 50 | const char* wifi_password = "wifi_password"; |
| 51 | const char* local_host = nullptr; |
| 52 | |
| 53 | _online = false; |
| 54 | |
| 55 | if (wifi_ssid != nullptr) { |
| 56 | _wifi_ssid = wifi_ssid; |
| 57 | } |
| 58 | if (wifi_password != nullptr) { |
| 59 | _wifi_password = wifi_password; |
| 60 | } |
| 61 | if (local_host != nullptr) { |
| 62 | _local_host = local_host; |
| 63 | } |
| 64 | // _local_port / _remote_port already initialised from |
| 65 | // DEFAULT_UDP_LOCAL_PORT / DEFAULT_UDP_REMOTE_PORT — see UDPInterface.h. |
| 66 | TRACEF("UDPInterface: local host: %s", _local_host.c_str()); |
| 67 | TRACEF("UDPInterface: local port: %d", _local_port); |
| 68 | TRACEF("UDPInterface: remote host: %s", _remote_host.c_str()); |
| 69 | TRACEF("UDPInterface: remote port: %d", _remote_port); |
| 70 | |
| 71 | #ifdef ARDUINO |
| 72 | TRACEF("UDPInterface: wifi ssid: %s", _wifi_ssid.c_str()); |
| 73 | TRACEF("UDPInterface: wifi password: %s", _wifi_password.c_str()); |
| 74 | |
| 75 | // Connect to the WiFi network |
| 76 | WiFi.begin(_wifi_ssid.c_str(), _wifi_password.c_str()); |
| 77 | Serial.println(""); |
| 78 | |
| 79 | // Wait for WiFi network connection to complete |
| 80 | Serial.print("Connecting to "); |
| 81 | Serial.print(_wifi_ssid.c_str()); |
| 82 | while (WiFi.status() != WL_CONNECTED) { |
| 83 | delay(500); |
| 84 | Serial.print("."); |
| 85 | } |
| 86 | Serial.println(""); |
| 87 | Serial.print("Connected to "); |
| 88 | Serial.println(_wifi_ssid.c_str()); |
| 89 | Serial.print("IP address: "); |
| 90 | Serial.println(WiFi.localIP()); |
| 91 | |
| 92 | // Listen for received UDP packets |
| 93 | /* |
| 94 | if (udp.listen(udpPort)) { |
| 95 | Serial.print("UDP Listening on IP: "); |
| 96 | Serial.println(WiFi.localIP()); |
| 97 | udp.onPacket([](AsyncUDPPacket packet) { |
| 98 | Serial.print("UDP Packet Type: "); |
| 99 | Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast"); |
| 100 | Serial.print(", From: "); |
| 101 | Serial.print(packet.remoteIP()); |
| 102 | Serial.print(":"); |
| 103 | Serial.print(packet.remotePort()); |
| 104 | Serial.print(", To: "); |
| 105 | Serial.print(packet.localIP()); |
no test coverage detected