{"id":5068,"date":"2026-03-26T14:44:45","date_gmt":"2026-03-26T05:44:45","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5068"},"modified":"2026-03-26T15:46:36","modified_gmt":"2026-03-26T06:46:36","slug":"arduino-esp32-http-comm-macos","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/03\/26\/arduino-esp32-http-comm-macos\/","title":{"rendered":"[Arduino]ESP32 http \ud1b5\uc2e0\/ESP32 HTTP communication(MacOS)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffbhttp \ud504\ub85c\ud1a0\ucf5c\uc744 \uc774\uc6a9\ud574\uc11c Esp32\uc5d0\uc11c nodejs\uc11c\ubc84\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\ub294 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc744 \uc124\uba85\ud569\ub2c8\ub2e4.<br>This explains how to implement the functionality to send messages from ESP32 to a Node.js server using the HTTP protocol.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uadf8\ub9ac\uace0 nodejs\uc11c\ubc84\uc5d0\uc11c Esp32\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\ub294 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc744 \uc124\uba85\ud569\ub2c8\ub2e4.<br>And I will explain how to implement the functionality to send messages from a Node.js server to ESP32.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb IDE\uc5d0\uc11c \uc5c5\ub85c\ub4dc \uc18d\ub3c4(11520),\ubaa8\ub4c8\uc124\uc815(Esp32 DevModule),\ud3ec\ud2b8\uc124\uc815(\/dev\/cu.usbserial-120 \ub610\ub294 140)\uc740 \ub3d9\uc77c\ud569\ub2c8\ub2e4.<br>In the IDE, the upload speed (11520), module setting (Esp32 DevModule), and port setting (\/dev\/cu.usbserial-120 or 140) are the same.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\uc758 \uc21c\uc11c\ub300\ub85c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Execute in the following order.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1)IDE\uc5d0\uc11c \uc544\ub798\uc758 \ucf54\ub4dc\ub97c \uc5c5\ub85c\ub4dc \ud569\ub2c8\ub2e4.<br>Upload the code below in the IDE.<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h>\n#include &lt;WebServer.h>\n#include &lt;HTTPClient.h>\n\nconst char* ssid = \"YOURID\";\nconst char* password = \"YOURPASSWORD\";\n\nWebServer server(80);\n\n\/\/ \uc608\uc2dc \uc13c\uc11c\uac12 (\ub098\uc911\uc5d0 \uc2e4\uc81c \uc13c\uc11c \uac12\uc73c\ub85c \ub300\uccb4)\n\/\/ Example sensor value (replaced with actual sensor value later)\nint sensorValue = 42;\n\n\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 \uc13c\uc11c\uac12 \uc694\uccad\n\/\/ Client requests sensor value\nvoid handleGetSensor() {\n  String json = \"{\\\"sensor\\\":\" + String(sensorValue) + \"}\";\n  server.send(200, \"application\/json\", json);\n}\n\n\/\/ \ud074\ub77c\uc774\uc5b8\ud2b8\uac00 ESP32\uc5d0 \uba85\ub839 \ubcf4\ub0b4\uae30\n\/\/ Client sends commands to ESP32\nvoid handlePostControl() {\n  if (!server.hasArg(\"plain\")) {\n    server.send(400, \"text\/plain\", \"No body\");\n    return;\n  }\n  String body = server.arg(\"plain\");\n  Serial.print(\"RX control: \");\n  Serial.println(body);\n\n  \/\/ \uc5ec\uae30\uc11c body \ud30c\uc2f1\ud574\uc11c \uc81c\uc5b4 \ucc98\ub9ac\ud558\uba74 \ub428\n  \/\/ You can parse the body and handle the control here.\n  server.send(200, \"text\/plain\", \"OK\");\n}\n\/\/ nodejs\uc5d0\uc11c get\ubc29\uc2dd \uc815\ubcf4 \ubc1b\uae30\n\/\/ Receiving GET method information in Node.js\nvoid handleControl() {\n  if (server.hasArg(\"led\")) {\n    String led = server.arg(\"led\");\n    Serial.print(\"LED: \");\n    Serial.println(led);\n  }\n  server.send(200, \"text\/plain\", \"OK\");\n}\n\n\/\/ ESP32\uac00 \uc678\ubd80 \uc11c\ubc84\ub85c \uc13c\uc11c \ub370\uc774\ud130 \ubcf4\ub0b4\uae30\n\/\/ ESP32 sends sensor data to an external server\n\nvoid postToServer() {\n  HTTPClient http;\n  http.begin(\"http:\/\/192.168.0.100:3000\/sensor\");\n  http.addHeader(\"Content-Type\", \"application\/json\");\n\n  String payload = \"{\\\"sensor\\\":\" + String(sensorValue) + \"}\";\n  int code = http.POST(payload);\n  Serial.print(\"POST result: \");\n  Serial.println(code);\n\n  http.end();\n}\n\nvoid setup() {\n  Serial.begin(115200);\n\n  WiFi.begin(ssid, password);\n  while (WiFi.status() != WL_CONNECTED) { delay(500); }\n\n  Serial.print(\"IP: \");\n  Serial.println(WiFi.localIP());\n\n  server.on(\"\/sensor\", HTTP_GET, handleGetSensor);\n  \n  \/\/ post\n  \/\/server.on(\"\/control\", HTTP_POST, handlePostControl);\n  \n  \/\/ get\n  server.on(\"\/control\", HTTP_GET, handleControl);\n\n\n  server.begin();\n}\n\nvoid loop() {\n  server.handleClient();\n\n  \/\/ 5\ucd08\ub9c8\ub2e4 \uc678\ubd80 \uc11c\ubc84\ub85c \uc13c\uc11c \ub370\uc774\ud130 \uc5c5\ub85c\ub4dc\n  \/\/ Upload sensor data to external server every 5 seconds\n  static unsigned long lastPost = 0;\n  if (millis() - lastPost > 5000) {\n    lastPost = millis();\n    postToServer();\n  }\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2)nodejs \uc11c\ubc84\ub97c \uc14b\ud305\ud569\ub2c8\ub2e4.<br>Set up the Node.js server.<\/h3>\n\n\n\n<p>\u2714\ufe0f\ud504\ub85c\uc81d\ud2b8 \uc0dd\uc131 \/ Create project<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir nodejs-server\ncd nodejs-server\nnpm init -y\nnpm install express<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f server.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const express = require(\"express\");\nconst app = express();\napp.use(express.json());\n\n\/\/ Node 18+\ub294 fetch \ub0b4\uc7a5\n\/\/ Node 18+ has built-in fetch\nconst esp32Ip = \"192.168.0.100\"; \/\/YOUR ESP32 IP ADDRESS\n\napp.post(\"\/sensor\", (req, res) => {\n  console.log(\"sensor data:\", req.body);\n  res.json({ ok: true });\n});\n\n\/\/ app.post(\"\/control\", (req, res) => {\n\/\/   console.log(\"control:\", req.body);\n\/\/   res.json({ ok: true });\n\/\/ });\n\n\napp.get(\"\/control\", async (req, res) => {\n  console.log(\"control:\", req.query); \n  try {\n    const r = await fetch(`http:\/\/${esp32Ip}\/control?led=${req.query.led}`);\n    const text = await r.text();\n    res.json({ ok: true, esp32: text });\n  } catch (err) {\n    console.error(err);\n    res.status(500).json({ ok: false, error: String(err) });\n  }\n});\n\n\napp.get(\"\/\", (req, res) => {\n  res.send(\"Server OK\");\n});\n\napp.listen(3000, () => {\n  console.log(\"Server running on http:\/\/192.168.0.100:3000\");\n});\n\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f nodejs \uc11c\ubc84 \uc2e4\ud589 \/ Run Node.js server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>node server.js<\/code><\/pre>\n\n\n\n<p>3)\uc2e4\ud589 \/ Run<\/p>\n\n\n\n<p>\u2714\ufe0f ESP32\ucf54\ub4dc\uac00 \uc815\uc0c1\uc801\uc73c\ub85c \uc5c5\ub85c\ub4dc\ub418\uace0 nodejs\uc11c\ubc84\ub97c \uc2e4\ud589\ud558\uba74 \ub2e4\uc74c\uacfc \uac19\uc774 \uba54\uc138\uc9c0\uac00 5\ucd08\ub9c8\ub2e4 \ucd9c\ub825\ub418\ub294 \uac83\uc744 \ud655\uc778 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>Once the ESP32 code is successfully uploaded and the nodejs server is run, you can see that the following message is printed every 5 seconds.<\/p>\n\n\n\n<p>&#8212; nodejs server<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"822\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/1.node-message.jpg\" alt=\"\" class=\"wp-image-5072\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/1.node-message.jpg 714w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/1.node-message-261x300.jpg 261w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/1.node-message-400x461.jpg 400w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>&#8212; Arduino IDE<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"634\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-1024x634.jpg\" alt=\"\" class=\"wp-image-5074\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-1024x634.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-300x186.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-768x476.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-400x248.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect-800x496.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/2.ide-connect.jpg 1430w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f \ube0c\ub77c\uc6b0\uc800\uc5d0 http:\/\/nodejs\uc11c\ubc84\uc8fc\uc18c:3000 \uc73c\ub85c \uc811\uc18d\ud558\uba74 \ube0c\ub77c\uc6b0\uc800\uc5d0 \uba54\uc138\uc9c0\uac00 \ucd9c\ub825\ub429\ub2c8\ub2e4.<br>If you access http:\/\/nodejsserveraddress:3000 in your browser, a message will be displayed in the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"496\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/3.br-root.jpg\" alt=\"\" class=\"wp-image-5076\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/3.br-root.jpg 728w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/3.br-root-300x204.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/3.br-root-400x273.jpg 400w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f get\ubc29\uc2dd\uc73c\ub85c \uba54\uc138\uc9c0\ub97c \uc804\uc1a1\ud569\ub2c8\ub2e4.(control?led=1)<br>Sends a message using the GET method.(control?led=1)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"448\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1.jpg\" alt=\"\" class=\"wp-image-5078\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1.jpg 980w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1-300x137.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1-768x351.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1-400x183.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/4.br-led-1-800x366.jpg 800w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f \uc804\uc1a1\ub41c \uba54\uc138\uc9c0\uac00 Esp32\ub85c \uc804\uc1a1\ub418\ub294\uac83\uc744 \ud655\uc778 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can verify that the transmitted message is sent to the Esp32.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"840\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/5.ide-led-1.jpg\" alt=\"\" class=\"wp-image-5079\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/5.ide-led-1.jpg 780w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/5.ide-led-1-279x300.jpg 279w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/5.ide-led-1-768x827.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/03\/5.ide-led-1-400x431.jpg 400w\" sizes=\"auto, (max-width: 780px) 100vw, 780px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffbhttp \ud504\ub85c\ud1a0\ucf5c\uc744 \uc774\uc6a9\ud574\uc11c Esp32\uc5d0\uc11c nodejs\uc11c\ubc84\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\ub294 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc744 \uc124\uba85\ud569\ub2c8\ub2e4.This explains how to implement the functionality to send messages from ESP32 to a Node.js server using the HTTP protocol. \ud83d\udc49\ud83c\udffb \uadf8\ub9ac\uace0 nodejs\uc11c\ubc84\uc5d0\uc11c Esp32\ub85c \uba54\uc138\uc9c0\ub97c \ubcf4\ub0b4\ub294 \uae30\ub2a5\uc744 \uad6c\ud604\ud558\ub294 \ubc29\ubc95\uc744 \uc124\uba85\ud569\ub2c8\ub2e4.And I will explain how to implement the functionality to send messages from a Node.js server [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1],"tags":[],"class_list":["post-5068","post","type-post","status-publish","format-standard","hentry","category-arduino","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5068"}],"version-history":[{"count":22,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5068\/revisions"}],"predecessor-version":[{"id":5096,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5068\/revisions\/5096"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}