{"id":466424,"date":"2025-07-07T21:02:42","date_gmt":"2025-07-07T21:02:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466424"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466424","title":{"rendered":"<span>\u0420\u0443\u043b\u0438\u043c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u043f\u043e UDP \u0438 ESP8266<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3c0\/297\/817\/3c029781722f7520b429434e5721a05f.png\" width=\"1280\" height=\"720\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/3c0\/297\/817\/3c029781722f7520b429434e5721a05f.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3c0\/297\/817\/3c029781722f7520b429434e5721a05f.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/strong><br \/>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c <strong>UDP<\/strong> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c <strong>ESP8266<\/strong>, \u0433\u0434\u0435 \u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0441 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 <strong>DHT11<\/strong>. \u0412\u0441\u0451 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437 Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 UDP?<\/h2>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u043e \u043f\u0440\u0438\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 UDP.UDP (User Datagram Protocol) \u2014 \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 \u0441\u0442\u0435\u043a\u0435 TCP\/IP. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0432 \u0441\u0435\u0442\u0438 \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0430, \u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0438 \u043f\u0430\u043a\u0435\u0442\u044b \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0438\u0445 \u043e\u0431\u043c\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435. <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f95\/b89\/024\/f95b89024f80914f069ae9dbf3a15b61.png\" alt=\"\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b UDP\" title=\"\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b UDP\" width=\"1813\" height=\"589\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/f95\/b89\/024\/f95b89024f80914f069ae9dbf3a15b61.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f95\/b89\/024\/f95b89024f80914f069ae9dbf3a15b61.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b UDP<\/figcaption><\/div>\n<\/figure>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <strong>ESP8266<\/strong>, \u0441\u043d\u0430\u0431\u0436\u0451\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u0435\u043c Wi-Fi, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0440\u043e\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041a \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0441 \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u043e\u043c \u043d\u0430 <strong>20 \u043a\u041e\u043c<\/strong> (\u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u0430 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u0432\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0442\u0443\u0441\u043a\u043b\u043e), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u0435\u043d\u0441\u043e\u0440 <strong>DHT11<\/strong>. \u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/852\/a0a\/6a1\/852a0a6a1cc4fae82c37f9ed529cfb31.png\" alt=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\" title=\"\u0421\u0445\u0435\u043c\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\" width=\"1237\" height=\"1075\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/852\/a0a\/6a1\/852a0a6a1cc4fae82c37f9ed529cfb31.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/852\/a0a\/6a1\/852a0a6a1cc4fae82c37f9ed529cfb31.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<h2>\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c ESP8266<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e <strong>UDP<\/strong>, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <code>WiFiUdp.h<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>ESP8266WiFi.h<\/code> \u2014 \u0441 \u0435\u0451 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u041d\u0443 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>DHT.h<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u043c \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u043c.<\/p>\n<p><code>#include &lt;DHT.h&gt;<\/code><\/p>\n<p><code>#include &lt;ESP8266WiFi.h&gt;<\/code><\/p>\n<p><code>#include &lt;WiFiUdp.h&gt;<\/code><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432: <code>DHT <\/code>\u0438 <code>WiFiUDP<\/code>. <\/p>\n<p><code>#define DHT_PIN \u00a0 \u00a0 \u00a0 \u00a0 13<\/code><\/p>\n<p><code>const char* ssid = \"ESP8266\";<\/code><\/p>\n<p><code>const int port = 4210;<\/code><\/p>\n<p><code>char incomingBytes[20];<\/code><\/p>\n<p><code>DHT dht(DHT_PIN, DHT11);<\/code><\/p>\n<p><code>WiFiUDP udp;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>setup()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0451\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0432\u0441\u0435\u0439 \u043f\u0435\u0440\u0438\u0444\u0435\u0440\u0438\u0438.<\/p>\n<p><code>void setup() {<\/code><\/p>\n<p><code>\u00a0 WiFi.mode(WIFI_AP);<\/code><\/p>\n<p><code>\u00a0 WiFi.softAP(ssid);<\/code><\/p>\n<p><code>\u00a0 dht.begin();<\/code><\/p>\n<p><code>\u00a0 udp.begin(port);<\/code><\/p>\n<p><code>\u00a0 Serial.begin(9600);<\/code><\/p>\n<p><code>\u00a0 pinMode(15, OUTPUT);<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p>\u0412 <code>loop()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 <strong>UDP<\/strong>-\u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0417\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>udpHandler<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p><code>void loop() {<\/code><\/p>\n<p><code>\u00a0 int packetSize = udp.parsePacket();<\/code><\/p>\n<p><code>\u00a0 if (packetSize){<\/code><\/p>\n<p><code>\u00a0 \u00a0 int len = udp.read(incomingBytes, 20);<\/code><\/p>\n<p><code>\u00a0 \u00a0 incomingBytes[len] = '\\0';<\/code><\/p>\n<p><code>\u00a0 \u00a0 if (len){<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 char* str = (char*)incomingBytes;<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 udpHandler(str);<\/code><\/p>\n<p><code>\u00a0 \u00a0 }<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>\"LedOn\"<\/code> \u2014 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 <code>\"LedOff\"<\/code> \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>strcmp<\/code> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 0, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f.<br \/>\u0415\u0441\u043b\u0438 \u0432 <strong>UDP<\/strong>-\u043f\u0430\u043a\u0435\u0442\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <code>\"Temperature\"<\/code> \u2014 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0441 \u0441\u0435\u043d\u0441\u043e\u0440\u0430 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u043e IP \u0438 \u043f\u043e\u0440\u0442\u0443.<\/p>\n<p><code>void udpHandler(char* message){<\/code><\/p>\n<p><code>\u00a0 Serial.println(message);<\/code><\/p>\n<p><code>\u00a0 if (!strcmp(message,\"LedOn\")){digitalWrite(15, HIGH);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message,\"LedOff\")){digitalWrite(15, LOW);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message, \"Temperature\")){<\/code><\/p>\n<p><code>\u00a0 \u00a0 float temp = dht.readTemperature(); <\/code><\/p>\n<p><code>\u00a0 \u00a0 char replyPacket[10];<\/code><\/p>\n<p><code>\u00a0 \u00a0 snprintf(replyPacket, sizeof(replyPacket), \"%.2f\", temp);<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.beginPacket(udp.remoteIP(), udp.remotePort());<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.write(replyPacket, strlen(replyPacket));<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.endPacket();<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 <strong>ESP8266<\/strong> \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u2014 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043d\u0430 Java.<\/p>\n<p><code>#include &lt;DHT.h&gt;<\/code><\/p>\n<p><code>#include &lt;ESP8266WiFi.h&gt;<\/code><\/p>\n<p><code>#include &lt;WiFiUdp.h&gt;<\/code><\/p>\n<p><code>#define DHT_PIN \u00a0 \u00a0 \u00a0 \u00a0 13<\/code><\/p>\n<p><code>const char* ssid = \"ESP8266\";<\/code><\/p>\n<p><code>const int port = 4210;<\/code><\/p>\n<p><code>char incomingBytes[20];<\/code><\/p>\n<p><code>DHT dht(DHT_PIN, DHT11);<\/code><\/p>\n<p><code>WiFiUDP udp;<\/code><\/p>\n<p><code>void setup() {<\/code><\/p>\n<p><code>\u00a0 WiFi.mode(WIFI_AP);<\/code><\/p>\n<p><code>\u00a0 WiFi.softAP(ssid);<\/code><\/p>\n<p><code>\u00a0 dht.begin();<\/code><\/p>\n<p><code>\u00a0 udp.begin(port);<\/code><\/p>\n<p><code>\u00a0 pinMode(15, OUTPUT);<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>void loop() {<\/code><\/p>\n<p><code>\u00a0 int packetSize = udp.parsePacket();<\/code><\/p>\n<p><code>\u00a0 if (packetSize){<\/code><\/p>\n<p><code>\u00a0 \u00a0 int len = udp.read(incomingBytes, 20);<\/code><\/p>\n<p><code>\u00a0 \u00a0 incomingBytes[len] = '\\0';<\/code><\/p>\n<p><code>\u00a0 \u00a0 if (len){<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 char* str = (char*)incomingBytes;<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 udpHandler(str);<\/code><\/p>\n<p><code>\u00a0 \u00a0 }<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>void udpHandler(char* message){<\/code><\/p>\n<p><code>\u00a0 if (!strcmp(message,\"LedOn\")){digitalWrite(15, HIGH);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message,\"LedOff\")){digitalWrite(15, LOW);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message, \"Temperature\")){<\/code><\/p>\n<p><code>\u00a0 \u00a0 float temp = dht.readTemperature(); <\/code><\/p>\n<p><code>\u00a0 \u00a0 char replyPacket[10];<\/code><\/p>\n<p><code>\u00a0 \u00a0 snprintf(replyPacket, sizeof(replyPacket), \"%.2f\", temp);<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.beginPacket(udp.remoteIP(), udp.remotePort());<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.write(replyPacket, strlen(replyPacket));<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.endPacket();<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c &#171;\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435&#187;<\/h2>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0440\u0438 \u043a\u043d\u043e\u043f\u043a\u0438 <code>Button<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0434\u0438\u043d <code>TextView<\/code>, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 XML-\u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043d\u0438\u0436\u0435.<\/p>\n<p><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt; &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"     xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"     xmlns:tools=\"http:\/\/schemas.android.com\/tools\"     android:id=\"@+id\/main\"     android:layout_width=\"match_parent\"     android:layout_height=\"match_parent\"     tools:context=\".MainActivity\"&gt;      &lt;Button         android:id=\"@+id\/Temp_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Temperature\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/led_off_btn\" \/&gt;      &lt;Button         android:id=\"@+id\/led_on_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Led On\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintHorizontal_bias=\"0.498\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/temp_view\" \/&gt;      &lt;Button         android:id=\"@+id\/led_off_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Led Off\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintHorizontal_bias=\"0.498\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/led_on_btn\" \/&gt;      &lt;TextView         android:id=\"@+id\/temp_view\"         android:layout_width=\"wrap_content\"         android:layout_height=\"wrap_content\"         android:layout_marginTop=\"50dp\"         android:textColor=\"@color\/black\"         android:textSize=\"34sp\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toTopOf=\"parent\" \/&gt; &lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;<\/code><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dd0\/718\/02c\/dd071802cd350cc6d7fcf173cf497d33.png\" alt=\"\u041e\u0431\u0449\u0438\u0439 \u0432\u0438\u0434 UI\" title=\"\u041e\u0431\u0449\u0438\u0439 \u0432\u0438\u0434 UI\" width=\"576\" height=\"1280\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/dd0\/718\/02c\/dd071802cd350cc6d7fcf173cf497d33.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dd0\/718\/02c\/dd071802cd350cc6d7fcf173cf497d33.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041e\u0431\u0449\u0438\u0439 \u0432\u0438\u0434 UI<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e, \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443.<\/p>\n<p><code>&lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>MainActivity<\/code>. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 UI \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u041f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0438\u0445 ID \u0438\u0437 XML.<br \/>\u041e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442: \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0446\u0432\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0435\u043b\u044b\u043c (\u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0440\u0451\u043c \u0444\u0438\u043e\u043b\u0435\u0442\u043e\u0432\u0443\u044e \u043f\u043e\u043b\u043e\u0441\u0443 \u0441\u0432\u0435\u0440\u0445\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>udpPost<\/code>, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e UDP. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<br \/>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <strong>UDP<\/strong>-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>DatagramSocket<\/code>. \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0430 \u0431\u0443\u0444\u0435\u0440\u0430: \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>DatagramPacket<\/code> \u2014 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f UDP-\u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0412 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0430\u0448\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, IP-\u0430\u0434\u0440\u0435\u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 (\u043e\u043d \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0442\u043e\u0447\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430) \u0438 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 UI-\u043f\u043e\u0442\u043e\u043a \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>TextView<\/code> \u2014 \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0435. \u0415\u0441\u043b\u0438 \u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u2014 \u043e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442, \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p><code>void udpPost(String message){    <\/code><\/p>\n<p><code>new Thread(new Runnable() {        <\/code><\/p>\n<p><code>@Override         <\/code><\/p>\n<p><code>public void run() {            <\/code><\/p>\n<p><code>try {                <\/code><\/p>\n<p><code>DatagramSocket datagramSocket = new DatagramSocket();                <\/code><\/p>\n<p><code>byte sendBuffer[] = message.getBytes();                <\/code><\/p>\n<p><code>byte[] receiveBuffer = new byte[1024];                <\/code><\/p>\n<p><code>DatagramPacket packet = new DatagramPacket(sendBuffer, sendBuffer.length, InetAddress.getByName(ip), port);                <\/code><\/p>\n<p><code>DatagramPacket receivePacket = new DatagramPacket(receiveBuffer, receiveBuffer.length);                <\/code><\/p>\n<p><code>datagramSocket.send(packet);                datagramSocket.receive(receivePacket);                <\/code><\/p>\n<p><code>String message = new String(receivePacket.getData(), 0, receivePacket.getLength());                <\/code><\/p>\n<p><code>runOnUiThread(new Runnable() {                    <\/code><\/p>\n<p><code>@Override                     <\/code><\/p>\n<p><code>public void run() {                        <\/code><\/p>\n<p><code>if (message != \"\"){                            <\/code><\/p>\n<p><code>tempView.setText(message + \"\u00b0C\");                        <\/code><\/p>\n<p><code>}                    <\/code><\/p>\n<p><code>}                <\/code><\/p>\n<p><code>});            <\/code><\/p>\n<p><code>} catch (SocketException | UnknownHostException e) {                 e.printStackTrace();             } catch (IOException e) {                 e.printStackTrace();             }         }     }).start(); }<\/code><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>onCreate()<\/code>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f. \u0412\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p><code>package com.example.udpclient;import android.annotation.SuppressLint;<\/code><br \/><code>import android.graphics.Color;<\/code><br \/><code>import android.os.Bundle;<\/code><br \/><code>import android.view.View;<\/code><br \/><code>import android.view.WindowManager;<\/code><br \/><code>import android.widget.Button;<\/code><br \/><code>import android.widget.TextView;import androidx.activity.EdgeToEdge;<\/code><br \/><code>import androidx.appcompat.app.AppCompatActivity;<\/code><br \/><code>import androidx.constraintlayout.widget.ConstraintLayout;<\/code><br \/><code>import androidx.core.graphics.Insets;<\/code><br \/><code>import androidx.core.view.ViewCompat;<\/code><br \/><code>import androidx.core.view.WindowInsetsCompat;import java.io.IOException;<\/code><br \/><code>import java.net.DatagramPacket;<\/code><br \/><code>import java.net.DatagramSocket;<\/code><br \/><code>import java.net.InetAddress;<\/code><br \/><code>import java.net.SocketException;<\/code><br \/><code>import java.net.UnknownHostException;public class MainActivity extends AppCompatActivity {<\/code><br \/><code>    ConstraintLayout constraintLayout;<\/code><br \/><code>    Button ledOn, ledOff, temp;<\/code><br \/><code>    TextView tempView;<\/code><br \/><code>    int port = 4210;<\/code><br \/><code>    String ip = \"192.168.4.1\";<\/code><br \/><code>    @SuppressLint(\"MissingInflatedId\")<\/code><br \/><code>    @Override<\/code><br \/><code>    protected void onCreate(Bundle savedInstanceState) {<\/code><br \/><code>        super.onCreate(savedInstanceState);<\/code><br \/><code>        EdgeToEdge.enable(this);<\/code><br \/><code>        setContentView(R.layout.activity_main);<\/code><br \/><code>        getWindow().setFlags(<\/code><br \/><code>                WindowManager.LayoutParams.FLAG_FULLSCREEN,<\/code><br \/><code>                WindowManager.LayoutParams.FLAG_FULLSCREEN<\/code><br \/><code>        );<\/code><br \/><code>        constraintLayout = findViewById(R.id.main);<\/code><br \/><code>        constraintLayout.setBackgroundColor(Color.WHITE);<\/code><br \/><code>        ledOn = findViewById(R.id.led_on_btn);<\/code><br \/><code>        ledOff = findViewById(R.id.led_off_btn);<\/code><br \/><code>        temp = findViewById(R.id.Temp_btn);<\/code><br \/><code>        tempView = findViewById(R.id.temp_view);        ledOn.setOnClickListener(new View.OnClickListener() {<\/code><br \/><code>            @Override<\/code><br \/><code>            public void onClick(View v) {<\/code><br \/><code>                udpPost(\"LedOn\");<\/code><br \/><code>            }<\/code><br \/><code>        });<\/code><br \/><code>        ledOff.setOnClickListener(new View.OnClickListener() {<\/code><br \/><code>            @Override<\/code><br \/><code>            public void onClick(View v) {<\/code><br \/><code>                udpPost(\"LedOff\");<\/code><br \/><code>            }<\/code><br \/><code>        });<\/code><br \/><code>        temp.setOnClickListener(new View.OnClickListener() {<\/code><br \/><code>            @Override<\/code><br \/><code>            public void onClick(View v) {<\/code><br \/><code>                udpPost(\"Temperature\");<\/code><br \/><code>            }<\/code><br \/><code>        });<\/code><br \/><code>    }<\/code><br \/><code>    void udpPost(String message){<\/code><br \/><code>        new Thread(new Runnable() {<\/code><br \/><code>            @Override<\/code><br \/><code>            public void run() {<\/code><br \/><code>                try {<\/code><br \/><code>                    DatagramSocket datagramSocket = new DatagramSocket();<\/code><br \/><code>                    byte sendBuffer[] = message.getBytes();<\/code><br \/><code>                    byte[] receiveBuffer = new byte[1024];<\/code><br \/><code>                    DatagramPacket packet = new DatagramPacket(sendBuffer, sendBuffer.length, InetAddress.getByName(ip), port);<\/code><br \/><code>                    DatagramPacket receivePacket = new DatagramPacket(receiveBuffer, receiveBuffer.length);<\/code><br \/><code>                    datagramSocket.send(packet);<\/code><br \/><code>                    datagramSocket.receive(receivePacket);<\/code><br \/><code>                    String message = new String(receivePacket.getData(), 0, receivePacket.getLength());<\/code><br \/><code>                    runOnUiThread(new Runnable() {<\/code><br \/><code>                        @Override<\/code><br \/><code>                        public void run() {<\/code><br \/><code>                            if (message != \"\"){<\/code><br \/><code>                                tempView.setText(message + \"\u00b0C\");<\/code><br \/><code>                            }<\/code><br \/><code>                        }<\/code><br \/><code>                    });                } catch (SocketException | UnknownHostException e) {<\/code><br \/><code>                    e.printStackTrace();<\/code><br \/><code>                } catch (IOException e) {<\/code><br \/><code>                    e.printStackTrace();<\/code><br \/><code>                }<\/code><br \/><code>            }<\/code><br \/><code>        }).start();<\/code><br \/><code>    }<\/code><br \/><code>}<\/code><\/p>\n<h2>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p>\u041d\u0430\u0441\u0442\u0430\u043b\u0430 \u043f\u043e\u0440\u0430 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Android-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u0440\u043e\u0448\u0438\u0432\u043a\u0443 \u0432 <strong>ESP8266<\/strong>. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u0441\u043e \u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d\u0430 \u043a \u0442\u043e\u0447\u043a\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0433\u0434\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u2014 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 (\u0438\u043b\u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f) \u043f\u0440\u044f\u043c\u043e \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e wifi \u0441\u0435\u0442\u0438.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a97\/38c\/185\/a9738c1854c67fa0d04541d39613ea5c.png\" alt=\"\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430\" title=\"\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430\" width=\"1280\" height=\"1269\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/a97\/38c\/185\/a9738c1854c67fa0d04541d39613ea5c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a97\/38c\/185\/a9738c1854c67fa0d04541d39613ea5c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/77a\/c47\/927\/77ac4792703fb39946d00aea6c060e48.png\" alt=\"\u0412\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430\" title=\"\u0412\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430\" width=\"1280\" height=\"1153\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/77a\/c47\/927\/77ac4792703fb39946d00aea6c060e48.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/77a\/c47\/927\/77ac4792703fb39946d00aea6c060e48.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0412\u044b\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u0430<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6dd\/f79\/b52\/6ddf79b52cb989be485ad1a586fb4cd7.png\" alt=\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b\" title=\"\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b\" width=\"576\" height=\"1280\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/6dd\/f79\/b52\/6ddf79b52cb989be485ad1a586fb4cd7.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6dd\/f79\/b52\/6ddf79b52cb989be485ad1a586fb4cd7.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/925800\/\"> https:\/\/habr.com\/ru\/articles\/925800\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/strong><br \/>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u043f\u043e\u0434\u0435\u043b\u044e\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c <strong>UDP<\/strong> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u043c <strong>ESP8266<\/strong>, \u0433\u0434\u0435 \u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u043b \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0443 \u0441 \u0434\u0430\u0442\u0447\u0438\u043a\u0430 <strong>DHT11<\/strong>. \u0412\u0441\u0451 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0437 Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e.<\/p>\n<h2>\u041f\u043e\u0447\u0435\u043c\u0443 UDP?<\/h2>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438 \u043e \u043f\u0440\u0438\u0440\u043e\u0434\u0435 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 UDP.UDP (User Datagram Protocol) \u2014 \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432 \u0441\u0442\u0435\u043a\u0435 TCP\/IP. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0432 \u0441\u0435\u0442\u0438 \u0431\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\u044e, \u043e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0435\u043d\u0430, \u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0438 \u043f\u0430\u043a\u0435\u0442\u044b \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0438\u0445 \u043e\u0431\u043c\u0435\u043d \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435. <\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b UDP<\/figcaption><\/div>\n<\/figure>\n<h2>\u0421\u0445\u0435\u043c\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/h2>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <strong>ESP8266<\/strong>, \u0441\u043d\u0430\u0431\u0436\u0451\u043d\u043d\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u0435\u043c Wi-Fi, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0440\u043e\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041a \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0443 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0441 \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u043e\u043c \u043d\u0430 <strong>20 \u043a\u041e\u043c<\/strong> (\u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u0434 \u0440\u0443\u043a\u043e\u0439 \u0440\u0435\u0437\u0438\u0441\u0442\u043e\u0440\u0430 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u043d\u043e\u043c\u0438\u043d\u0430\u043b\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u0432\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u0442\u0443\u0441\u043a\u043b\u043e), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u0439 \u0441\u0435\u043d\u0441\u043e\u0440 <strong>DHT11<\/strong>. \u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0438\u0436\u0435.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u0445\u0435\u043c\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/figcaption><\/div>\n<\/figure>\n<h2>\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c ESP8266<\/h2>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u043e <strong>UDP<\/strong>, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <code>WiFiUdp.h<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>ESP8266WiFi.h<\/code> \u2014 \u0441 \u0435\u0451 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u041d\u0443 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>DHT.h<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u043d\u044b\u043c \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u043c.<\/p>\n<p><code>#include &lt;DHT.h&gt;<\/code><\/p>\n<p><code>#include &lt;ESP8266WiFi.h&gt;<\/code><\/p>\n<p><code>#include &lt;WiFiUdp.h&gt;<\/code><\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u0441\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0430 \u0442\u0430\u043a\u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432: <code>DHT <\/code>\u0438 <code>WiFiUDP<\/code>. <\/p>\n<p><code>#define DHT_PIN \u00a0 \u00a0 \u00a0 \u00a0 13<\/code><\/p>\n<p><code>const char* ssid = \"ESP8266\";<\/code><\/p>\n<p><code>const int port = 4210;<\/code><\/p>\n<p><code>char incomingBytes[20];<\/code><\/p>\n<p><code>DHT dht(DHT_PIN, DHT11);<\/code><\/p>\n<p><code>WiFiUDP udp;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435, \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>setup()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0451\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0432\u0441\u0435\u0439 \u043f\u0435\u0440\u0438\u0444\u0435\u0440\u0438\u0438.<\/p>\n<p><code>void setup() {<\/code><\/p>\n<p><code>\u00a0 WiFi.mode(WIFI_AP);<\/code><\/p>\n<p><code>\u00a0 WiFi.softAP(ssid);<\/code><\/p>\n<p><code>\u00a0 dht.begin();<\/code><\/p>\n<p><code>\u00a0 udp.begin(port);<\/code><\/p>\n<p><code>\u00a0 Serial.begin(9600);<\/code><\/p>\n<p><code>\u00a0 pinMode(15, OUTPUT);<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p>\u0412 <code>loop()<\/code> \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 <strong>UDP<\/strong>-\u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0417\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>udpHandler<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u0440\u0438\u043d\u044f\u0442\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p><code>void loop() {<\/code><\/p>\n<p><code>\u00a0 int packetSize = udp.parsePacket();<\/code><\/p>\n<p><code>\u00a0 if (packetSize){<\/code><\/p>\n<p><code>\u00a0 \u00a0 int len = udp.read(incomingBytes, 20);<\/code><\/p>\n<p><code>\u00a0 \u00a0 incomingBytes[len] = '\\0';<\/code><\/p>\n<p><code>\u00a0 \u00a0 if (len){<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 char* str = (char*)incomingBytes;<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 udpHandler(str);<\/code><\/p>\n<p><code>\u00a0 \u00a0 }<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <code>\"LedOn\"<\/code> \u2014 \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 <code>\"LedOff\"<\/code> \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>strcmp<\/code> \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 0, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u2014 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f.<br \/>\u0415\u0441\u043b\u0438 \u0432 <strong>UDP<\/strong>-\u043f\u0430\u043a\u0435\u0442\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 <code>\"Temperature\"<\/code> \u2014 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430 \u0441 \u0441\u0435\u043d\u0441\u043e\u0440\u0430 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u043e IP \u0438 \u043f\u043e\u0440\u0442\u0443.<\/p>\n<p><code>void udpHandler(char* message){<\/code><\/p>\n<p><code>\u00a0 Serial.println(message);<\/code><\/p>\n<p><code>\u00a0 if (!strcmp(message,\"LedOn\")){digitalWrite(15, HIGH);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message,\"LedOff\")){digitalWrite(15, LOW);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message, \"Temperature\")){<\/code><\/p>\n<p><code>\u00a0 \u00a0 float temp = dht.readTemperature(); <\/code><\/p>\n<p><code>\u00a0 \u00a0 char replyPacket[10];<\/code><\/p>\n<p><code>\u00a0 \u00a0 snprintf(replyPacket, sizeof(replyPacket), \"%.2f\", temp);<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.beginPacket(udp.remoteIP(), udp.remotePort());<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.write(replyPacket, strlen(replyPacket));<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.endPacket();<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 <strong>ESP8266<\/strong> \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430 \u2014 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a Android-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043d\u0430 Java.<\/p>\n<p><code>#include &lt;DHT.h&gt;<\/code><\/p>\n<p><code>#include &lt;ESP8266WiFi.h&gt;<\/code><\/p>\n<p><code>#include &lt;WiFiUdp.h&gt;<\/code><\/p>\n<p><code>#define DHT_PIN \u00a0 \u00a0 \u00a0 \u00a0 13<\/code><\/p>\n<p><code>const char* ssid = \"ESP8266\";<\/code><\/p>\n<p><code>const int port = 4210;<\/code><\/p>\n<p><code>char incomingBytes[20];<\/code><\/p>\n<p><code>DHT dht(DHT_PIN, DHT11);<\/code><\/p>\n<p><code>WiFiUDP udp;<\/code><\/p>\n<p><code>void setup() {<\/code><\/p>\n<p><code>\u00a0 WiFi.mode(WIFI_AP);<\/code><\/p>\n<p><code>\u00a0 WiFi.softAP(ssid);<\/code><\/p>\n<p><code>\u00a0 dht.begin();<\/code><\/p>\n<p><code>\u00a0 udp.begin(port);<\/code><\/p>\n<p><code>\u00a0 pinMode(15, OUTPUT);<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>void loop() {<\/code><\/p>\n<p><code>\u00a0 int packetSize = udp.parsePacket();<\/code><\/p>\n<p><code>\u00a0 if (packetSize){<\/code><\/p>\n<p><code>\u00a0 \u00a0 int len = udp.read(incomingBytes, 20);<\/code><\/p>\n<p><code>\u00a0 \u00a0 incomingBytes[len] = '\\0';<\/code><\/p>\n<p><code>\u00a0 \u00a0 if (len){<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 char* str = (char*)incomingBytes;<\/code><\/p>\n<p><code>\u00a0 \u00a0 \u00a0 udpHandler(str);<\/code><\/p>\n<p><code>\u00a0 \u00a0 }<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>void udpHandler(char* message){<\/code><\/p>\n<p><code>\u00a0 if (!strcmp(message,\"LedOn\")){digitalWrite(15, HIGH);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message,\"LedOff\")){digitalWrite(15, LOW);}<\/code><\/p>\n<p><code>\u00a0 else if (!strcmp(message, \"Temperature\")){<\/code><\/p>\n<p><code>\u00a0 \u00a0 float temp = dht.readTemperature(); <\/code><\/p>\n<p><code>\u00a0 \u00a0 char replyPacket[10];<\/code><\/p>\n<p><code>\u00a0 \u00a0 snprintf(replyPacket, sizeof(replyPacket), \"%.2f\", temp);<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.beginPacket(udp.remoteIP(), udp.remotePort());<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.write(replyPacket, strlen(replyPacket));<\/code><\/p>\n<p><code>\u00a0 \u00a0 udp.endPacket();<\/code><\/p>\n<p><code>\u00a0 }<\/code><\/p>\n<p><code>}<\/code><\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c &#171;\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435&#187;<\/h2>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0440\u0438 \u043a\u043d\u043e\u043f\u043a\u0438 <code>Button<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0434\u0438\u043d <code>TextView<\/code>, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430. \u0412\u0435\u0441\u044c \u043a\u043e\u0434 XML-\u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043d\u0438\u0436\u0435.<\/p>\n<p><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt; &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"     xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"     xmlns:tools=\"http:\/\/schemas.android.com\/tools\"     android:id=\"@+id\/main\"     android:layout_width=\"match_parent\"     android:layout_height=\"match_parent\"     tools:context=\".MainActivity\"&gt;      &lt;Button         android:id=\"@+id\/Temp_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Temperature\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/led_off_btn\" \/&gt;      &lt;Button         android:id=\"@+id\/led_on_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Led On\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintHorizontal_bias=\"0.498\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/temp_view\" \/&gt;      &lt;Button         android:id=\"@+id\/led_off_btn\"         android:layout_width=\"181dp\"         android:layout_height=\"51dp\"         android:layout_marginTop=\"50dp\"         android:text=\"Led Off\"         android:textColor=\"@color\/black\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintHorizontal_bias=\"0.498\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toBottomOf=\"@+id\/led_on_btn\" \/&gt;      &lt;TextView         android:id=\"@+id\/temp_view\"         android:layout_width=\"wrap_content\"         android:layout_height=\"wrap_content\"         android:layout_marginTop=\"50dp\"         android:textColor=\"@color\/black\"         android:textSize=\"34sp\"         android:textStyle=\"bold\"         app:layout_constraintEnd_toEndOf=\"parent\"         app:layout_constraintStart_toStartOf=\"parent\"         app:layout_constraintTop_toTopOf=\"parent\" \/&gt; &lt;\/androidx.constraintlayout.widget.ConstraintLayout&gt;<\/code><\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041e\u0431\u0449\u0438\u0439 \u0432\u0438\u0434 UI<\/figcaption><\/div>\n<\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e, \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443.<\/p>\n<p><code>&lt;uses-permission android:name=\"android.permission.INTERNET\" \/&gt;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 <code>MainActivity<\/code>. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 UI \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432. \u041f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0438\u0445 ID \u0438\u0437 XML.<br \/>\u041e\u0434\u0438\u043d \u043c\u043e\u043c\u0435\u043d\u0442: \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u0444\u043e\u043d\u043e\u0432\u044b\u0439 \u0446\u0432\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0431\u0435\u043b\u044b\u043c (\u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u043c), \u0430 \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0440\u0451\u043c \u0444\u0438\u043e\u043b\u0435\u0442\u043e\u0432\u0443\u044e \u043f\u043e\u043b\u043e\u0441\u0443 \u0441\u0432\u0435\u0440\u0445\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0439 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>udpPost<\/code>, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043f\u043e UDP. \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<br \/>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <strong>UDP<\/strong>-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>DatagramSocket<\/code>. \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0430 \u0431\u0443\u0444\u0435\u0440\u0430: \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>DatagramPacket<\/code> \u2014 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f UDP-\u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0412 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043d\u0430\u0448\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, IP-\u0430\u0434\u0440\u0435\u0441 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 (\u043e\u043d \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0442\u043e\u0447\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430) \u0438 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0442\u0432\u0435\u0442. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0432 UI-\u043f\u043e\u0442\u043e\u043a \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 <code>TextView<\/code> \u2014 \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0435. \u0415\u0441\u043b\u0438 \u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u2014 \u043e\u0442\u0432\u0435\u0442 \u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442, \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e.<\/p>\n<p><code>void udpPost(String message){    <\/code><\/p>\n<p><code>new Thread(new Runnable() {        <\/code><\/p>\n<p><code>@Override         <\/code><\/p>\n<p><code>public void run() {            <\/code><\/p>\n<p><code>try {                <\/code><\/p>\n<p><code>DatagramSocket datagramSocket = new DatagramSocket();                <\/code><\/p>\n<p><code>byte sendBuffer[] = message.getBytes();                <\/code><\/p>\n<p><code>byte[] receiveBuffer = new byte[1024];                <\/code><\/p>\n<p><code>DatagramPacket packet = new DatagramPacket(sendBuffer, sendBuffer.length, InetAddress.getByName(ip), port);                <\/code><\/p>\n<p><code>DatagramPacket receivePacket = new DatagramPacket(receiveBuffer, receiveBuffer.length);                <\/code><\/p>\n<p><code>datagramSocket.send(packet);                datagramSocket.receive(receivePacket);                <\/code><\/p>\n<p><code>String message = new String(receivePacket.getData(), 0, receivePacket.getLength());                <\/code><\/p>\n<p><code>runOnUiThread(new Runnable() {                    <\/code><\/p>\n<p><code>@Override                     <\/code><\/p>\n<p><code>public void run() {                        <\/code><\/p>\n<p><code>if (message != \"\"){                            <\/code><\/p>\n<p><code>tempView.setText(message + \"\u00b0C\");                        <\/code><\/p>\n<p><code>}                    <\/code><\/p>\n<p><code>}                <\/code><\/p>\n<p><code>});            <\/code><\/p>\n<p><code>} catch (SocketException | UnknownHostException e) {                 e.printStackTrace();             } catch (IOException e) {                 e.printStackTrace();             }         }     }).start(); }<\/code><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>onCreate()<\/code>, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u044f. \u0412\u043d\u0443\u0442\u0440\u0438 \u043d\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.<\/p>\n<p><code>package com.example.udpclient;import android.annotation.SuppressLint;<\/code><br \/><code>import android.graphics.Color;<\/code><br \/><code>import android.os.Bundle;<\/code><br \/><code>import android.view.View;<\/code><br \/><code>import android.view.WindowManager;<\/code><br \/><code>import android.widget.Button;<\/code><br \/><code>import android.widget.TextView;import androidx.activity.EdgeToEdge;<\/code><br \/><code>import androidx.appcompat.app.AppCompatActivity;<\/code><br \/><code>import androidx.constraintlayout.widget.ConstraintLayout;<\/code><br \/><code>import<\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466424","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466424"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466424\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}