






Started logging.

<<<
Content-Length: 3218

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":17120,"clientInfo":{"name":"vscode","version":"1.50.0"},"rootPath":"c:\\Users\\zhang'pei\\Desktop\\ESP32-2432S028例子\\arduino\\Source code\\4_6_WIFI_STA_UDP","rootUri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"off","workspaceFolders":[{"uri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP","name":"4_6_WIFI_STA_UDP"}]}}
>>>
Content-Length: 598

{"id":0,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"triggerCharacters":[".","\u003e",":"]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n"},"renameProvider":false,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]}}},"jsonrpc":"2.0"}
<<<
Content-Length: 52

{"jsonrpc":"2.0","method":"initialized","params":{}}Content-Length: 2353

{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP/4_6_WIFI_STA_UDP.ino","languageId":"cpp","version":1,"text":"#include <WiFi.h>\r\n#include <AsyncUDP.h> //引用以使用异步UDP\r\n\r\nconst char *ssid = \"@snail\";\r\nconst char *password = \"ss559550\";\r\n\r\nAsyncUDP udp;                     //创建UDP对象\r\nunsigned int localUdpPort = 10000; //本地端口号\r\n\r\nunsigned int broadcastPort = localUdpPort;\r\nconst char *broadcastData = \"broadcast data\";\r\n// const uint8_t broadcastData[] = {\"broadcast data\"};\r\n\r\nvoid onPacketCallBack(AsyncUDPPacket packet)\r\n{\r\n  Serial.print(\"UDP数据包来源类型: \");\r\n  Serial.println(packet.isBroadcast() ? \"广播数据\" : (packet.isMulticast() ? \"组播\" : \"单播\"));\r\n  Serial.print(\"远端地址及端口号: \");\r\n  Serial.print(packet.remoteIP());\r\n  Serial.print(\":\");\r\n  Serial.println(packet.remotePort());\r\n  Serial.print(\"目标地址及端口号: \");\r\n  Serial.print(packet.localIP());\r\n  Serial.print(\":\");\r\n  Serial.println(packet.localPort());\r\n  Serial.print(\"数据长度: \");\r\n  Serial.println(packet.length());\r\n  Serial.print(\"数据内容: \");\r\n  Serial.write(packet.data(), packet.length());\r\n  Serial.println();\r\n\r\n  packet.print(\"reply data\");\r\n  broadcastPort = packet.remotePort();\r\n}\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(115200);\r\n  Serial.println();\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  while (!WiFi.isConnected())\r\n  {\r\n    delay(500);\r\n    Serial.print(\".\");\r\n  }\r\n  Serial.println(\"Connected\");\r\n  Serial.print(\"IP Address:\");\r\n  Serial.println(WiFi.localIP());\r\n\r\n  while (!udp.listen(localUdpPort)) //等待udp监听设置成功\r\n  {\r\n  }\r\n  udp.onPacket(onPacketCallBack); //注册收到数据包事件\r\n}\r\n\r\nvoid loop()\r\n{\r\n  delay(5000);\r\n\r\n  udp.broadcastTo(broadcastData, broadcastPort); //可以使用该方法广播信息\r\n\r\n  // IPAddress broadcastAddr((~(uint32_t)WiFi.subnetMask())|((uint32_t)WiFi.localIP())); //计算广播地址\r\n  // udp.writeTo(broadcastData, sizeof(broadcastData), broadcastAddr, localUdpPort); //广播数据\r\n}\r\n"}}}






Started logging.

<<<
Content-Length: 3218

{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":17052,"clientInfo":{"name":"vscode","version":"1.50.0"},"rootPath":"c:\\Users\\zhang'pei\\Desktop\\ESP32-2432S028例子\\arduino\\Source code\\4_6_WIFI_STA_UDP","rootUri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration":true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]}},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"parameterInformation":{"labelOffsetSupport":true}},"contextSupport":true},"definition":{"dynamicRegistration":true,"linkSupport":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"codeAction":{"dynamicRegistration":true,"isPreferredSupport":true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true,"linkSupport":true},"implementation":{"dynamicRegistration":true,"linkSupport":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"declaration":{"dynamicRegistration":true,"linkSupport":true},"selectionRange":{"dynamicRegistration":true}},"window":{"workDoneProgress":true}},"initializationOptions":{},"trace":"off","workspaceFolders":[{"uri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP","name":"4_6_WIFI_STA_UDP"}]}}
>>>
Content-Length: 598

{"id":0,"result":{"capabilities":{"textDocumentSync":2,"hoverProvider":true,"completionProvider":{"triggerCharacters":[".","\u003e",":"]},"signatureHelpProvider":{"triggerCharacters":["(",","]},"definitionProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":true,"documentFormattingProvider":true,"documentRangeFormattingProvider":true,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n"},"renameProvider":false,"executeCommandProvider":{"commands":["clangd.applyFix","clangd.applyTweak"]}}},"jsonrpc":"2.0"}
<<<
Content-Length: 52

{"jsonrpc":"2.0","method":"initialized","params":{}}Content-Length: 2355

{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///c%3A/Users/zhang%27pei/Desktop/ESP32-2432S028%E4%BE%8B%E5%AD%90/arduino/Source%20code/4_6_WIFI_STA_UDP/4_6_WIFI_STA_UDP.ino","languageId":"cpp","version":1,"text":"#include <WiFi.h>\r\n#include <AsyncUDP.h> //引用以使用异步UDP\r\n\r\nconst char *ssid = \"CMCC-404\";\r\nconst char *password = \"12345678\";\r\n\r\nAsyncUDP udp;                     //创建UDP对象\r\nunsigned int localUdpPort = 10000; //本地端口号\r\n\r\nunsigned int broadcastPort = localUdpPort;\r\nconst char *broadcastData = \"broadcast data\";\r\n// const uint8_t broadcastData[] = {\"broadcast data\"};\r\n\r\nvoid onPacketCallBack(AsyncUDPPacket packet)\r\n{\r\n  Serial.print(\"UDP数据包来源类型: \");\r\n  Serial.println(packet.isBroadcast() ? \"广播数据\" : (packet.isMulticast() ? \"组播\" : \"单播\"));\r\n  Serial.print(\"远端地址及端口号: \");\r\n  Serial.print(packet.remoteIP());\r\n  Serial.print(\":\");\r\n  Serial.println(packet.remotePort());\r\n  Serial.print(\"目标地址及端口号: \");\r\n  Serial.print(packet.localIP());\r\n  Serial.print(\":\");\r\n  Serial.println(packet.localPort());\r\n  Serial.print(\"数据长度: \");\r\n  Serial.println(packet.length());\r\n  Serial.print(\"数据内容: \");\r\n  Serial.write(packet.data(), packet.length());\r\n  Serial.println();\r\n\r\n  packet.print(\"reply data\");\r\n  broadcastPort = packet.remotePort();\r\n}\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(115200);\r\n  Serial.println();\r\n\r\n  WiFi.mode(WIFI_STA);\r\n  WiFi.begin(ssid, password);\r\n  while (!WiFi.isConnected())\r\n  {\r\n    delay(500);\r\n    Serial.print(\".\");\r\n  }\r\n  Serial.println(\"Connected\");\r\n  Serial.print(\"IP Address:\");\r\n  Serial.println(WiFi.localIP());\r\n\r\n  while (!udp.listen(localUdpPort)) //等待udp监听设置成功\r\n  {\r\n  }\r\n  udp.onPacket(onPacketCallBack); //注册收到数据包事件\r\n}\r\n\r\nvoid loop()\r\n{\r\n  delay(5000);\r\n\r\n  udp.broadcastTo(broadcastData, broadcastPort); //可以使用该方法广播信息\r\n\r\n  // IPAddress broadcastAddr((~(uint32_t)WiFi.subnetMask())|((uint32_t)WiFi.localIP())); //计算广播地址\r\n  // udp.writeTo(broadcastData, sizeof(broadcastData), broadcastAddr, localUdpPort); //广播数据\r\n}\r\n"}}}