{"id":295,"date":"2022-04-12T21:42:00","date_gmt":"2022-04-12T19:42:00","guid":{"rendered":"https:\/\/www.hh3dlab.fi\/blog\/?p=295"},"modified":"2022-04-12T21:42:00","modified_gmt":"2022-04-12T19:42:00","slug":"team-5-writing-to-the-web-with-esp32","status":"publish","type":"post","link":"https:\/\/www.hh3dlab.fi\/blog\/madrid-2022\/team-5-writing-to-the-web-with-esp32\/","title":{"rendered":"Team 5 &#8211; Writing to the Web With ESP32"},"content":{"rendered":"\n<p>In this part, our team is going to guide you how to use the ESP32 to write data to the remote server. This guide assumes that you have a PHP API up and running that at least have a POST route to receive data and a ESP32 with you. Our server accepts a string of data and writes that to a text file. <\/p>\n\n\n\n<p>This is the ESP32 that we&#8217;re using<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500.jpg?resize=374%2C362&#038;ssl=1\" alt=\"\" class=\"wp-image-296\" width=\"374\" height=\"362\" srcset=\"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?resize=1024%2C993&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?resize=300%2C291&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?resize=768%2C745&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?resize=1536%2C1490&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?resize=2048%2C1986&amp;ssl=1 2048w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?w=1280&amp;ssl=1 1280w, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/IMG_20220328_161500-scaled.jpg?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 374px) 100vw, 374px\" \/><figcaption>ESP32<\/figcaption><\/figure>\n\n\n\n<p>If you have a mini USB cable, you could plug that into the ESP32 and then plug the other end to your laptop. In order to use ESP32 with Arduino software, you should first install the ESP32 Dev Modules following this <a href=\"https:\/\/randomnerdtutorials.com\/installing-the-esp32-board-in-arduino-ide-windows-instructions\/\" target=\"_blank\" rel=\"noreferrer noopener\">instruction<\/a>.<\/p>\n\n\n\n<p>After that we start writing code, below is the code that we&#8217;re using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h&gt;\n#include &lt;HTTPClient.h&gt;\n\nconst char* ssid = &lt;your-hotspot-ssid&gt;;\nconst char* password = &lt;your-hotspot-password;\n\nString strTemp = \"25.3\";\nString strPressure = \"0.00\";\nString strLon = \"24.947167639512955\";\nString strLat = \"60.16757447480902\";\nString strAlt = \"0.00\";\nString numSats = \"0\";\n\n\nconst char* server = &lt;your-api-address&gt;;\n\nvoid setup() {\n  Serial.begin(115200);\n  delay(4000);\n\n  WiFi.begin(ssid, password);\n  Serial.println(\"Connecting to WIFI\u2026\");\n  \n  while(WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n  \n  Serial.println(\"\");\n  Serial.print(\"IP Address: \");\n  Serial.println(WiFi.localIP());\n \n  Serial.println(\"After 10 seconds the first reading will be displayed\");\n  Serial.println(\"\");\n}\n\nvoid loop() {\n  WriteWeb();\n}\n\nvoid WriteWeb() {\n   if (WiFi.status() == WL_CONNECTED) {\n    HTTPClient http;\n\n    http.begin(server);\n    http.addHeader(\"Content-Type\", \"text\/plain\");\n    \n    int httpResponseCode = http.POST(strLat + \",\" + strLon + \",\" + strTemp + \",\" + strPressure + \",\" + strAlt + \",\" + numSats);\n    String response = http.getString();\n    \n    if (httpResponseCode &gt; 0) {\n      Serial.print(\"HTTP Response Code is: \");\n      Serial.println(httpResponseCode);  \n      Serial.println(\"String was written into server\");  \n    } else {\n      Serial.print(\"Error sending on POST: \");\n      Serial.println(httpResponseCode);  \n      Serial.println(response);  \n    }\n    http.end();\n  } else {\n    Serial.println(\"Wifi is disconnected\");  \n  }\n\n  delay(10000); \n}<\/code><\/pre>\n\n\n\n<p>It looks complicated but we could break down the code and explain it for you<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;WiFi.h&gt;\n#include &lt;HTTPClient.h&gt;\n\nconst char* ssid = &lt;your-hotspot-ssid&gt;;\nconst char* password = &lt;your-hotspot-password;\n\nString strTemp = \"25.3\";\nString strPressure = \"0.00\";\nString strLon = \"24.947167639512955\";\nString strLat = \"60.16757447480902\";\nString strAlt = \"0.00\";\nString numSats = \"0\";\n\nconst char* server = &lt;your-api-endpoint&gt;;<\/code><\/pre>\n\n\n\n<p>First, we include the Wifi and HTTPClient libraries. These 2 come along when you install ESP32 Dev Modules and switch Arduino board to this one. After that, we have to define our hotspot <em>ssid <\/em>and <em>password<\/em>, you could use your phone hotspot for this. All of the String variables are just hard-coded data for printing out a full string to post to the server. Finally, we define also the endpoint that we&#8217;re going to post the data to.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void setup() {\n  Serial.begin(115200);\n  delay(4000);\n\n  WiFi.begin(ssid, password);\n  Serial.println(\"Connecting to WIFI\u2026\");\n  \n  while(WiFi.status() != WL_CONNECTED) {\n    delay(500);\n    Serial.print(\".\");\n  }\n  \n  Serial.println(\"\");\n  Serial.print(\"IP Address: \");\n  Serial.println(WiFi.localIP());\n \n  Serial.println(\"After 10 seconds the first reading will be displayed\");\n  Serial.println(\"\");\n}<\/code><\/pre>\n\n\n\n<p>The above code block is for setting up the ESP32 and checking the Wifi. When the code is uploaded to the ESP32, we can monitor it through Serial Monitor in Arduino. It starts by printing out &#8220;<em>Connecting to Wifi&#8230;<\/em>&#8220;. If there&#8217;s no Wifi or something wrong happens, it continues printing &#8220;<em>.<\/em>&#8220;. If everything is fine, it will prints the IP address and then move on from that.<\/p>\n\n\n\n<p>The WriteWeb() function is where we utilize all of the String variables, combine them into a full string and then use HTTPClient library to post it to the server. We use this function inside a loop, because we want it to write to the server every 10 seconds. The full string looks something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>60.16757447480902,24.947167639512955,25.3,0.00,0.00,0<\/code><\/pre>\n\n\n\n<p>So that&#8217;s basically how we can use ESP32 to post data to the server! Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this part, our team is going to guide you how to use the ESP32 to write data to the remote server. This guide assumes that you have a PHP API up and running that at least have a POST route to receive data and a ESP32 with you. Our server accepts a string of [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,14,29],"tags":[4,35,37],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-esp32","category-madrid-2022","category-madrid-team-5","tag-esp32","tag-madrid2022","tag-madridteam5"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":268,"url":"https:\/\/www.hh3dlab.fi\/blog\/madrid-2022\/team-5-introduction\/","url_meta":{"origin":295,"position":0},"title":"Team 5 &#8211; Introduction","author":"Madrid Team 5","date":"30.3.2022","format":false,"excerpt":"Hello all, this is an introduction post to Team 5 for Madrid seminar 2022. Our group of students from Haaga-Helia UAS will go to Madrid seminar to teach other students how to build an IoT device that sends GPS, temperature etc. data to the server and displays the information on\u2026","rel":"","context":"In &quot;ESP32&quot;","block_context":{"text":"ESP32","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/esp32\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/03\/IMG_20220328_161500-2-scaled.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":491,"url":"https:\/\/www.hh3dlab.fi\/blog\/innovation-course\/medication-dispenser-project\/","url_meta":{"origin":295,"position":1},"title":"Medication dispenser project","author":"Heikki Hietala, lab admin","date":"1.6.2023","format":false,"excerpt":"Introduction\u00a0 I have only taken Introduction of Programming course before and basically have no background of coding, neither in 3D printing. This course is a total new experience for me to combine the 3D printing and programming together and the first time to get to know about ESP32 and Arduino.\u00a0\u2026","rel":"","context":"In &quot;Innovation course&quot;","block_context":{"text":"Innovation course","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/innovation-course\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2023\/06\/image-25.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2023\/06\/image-25.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2023\/06\/image-25.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":301,"url":"https:\/\/www.hh3dlab.fi\/blog\/madrid-2022\/team-5-finalizing-and-getting-ready-for-madrid\/","url_meta":{"origin":295,"position":2},"title":"Team 5 &#8211; Finalizing and Getting Ready for Madrid!","author":"Madrid Team 5","date":"17.4.2022","format":false,"excerpt":"Time really does fly! It's time to finalize everything and get ready for Madrid. After getting the ESP32 to work, we gathered up and helped each other to combine all of our parts for the final system to work. Everyone has their own way to wire up the system. Below\u2026","rel":"","context":"In &quot;Madrid 2022&quot;","block_context":{"text":"Madrid 2022","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/madrid-2022\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2022\/04\/madrid_sketch_wriring_bb-1.jpg?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":508,"url":"https:\/\/www.hh3dlab.fi\/blog\/innovation-course\/508\/","url_meta":{"origin":295,"position":3},"title":"The Data duelist project","author":"Heikki Hietala, lab admin","date":"19.12.2023","format":false,"excerpt":"Introduction Our group members are Jonas Lemstr\u00f6m and Aku Liski. Aku has some experience with blender and 3d printing, and both of us like gaming. Jonas has some experience with game development with Unity. Our prototype is auto-battler that uses Esp32 as platform, Waveshare 7.5 inch E-Paper as screen, few\u2026","rel":"","context":"In &quot;Innovation course&quot;","block_context":{"text":"Innovation course","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/innovation-course\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":596,"url":"https:\/\/www.hh3dlab.fi\/blog\/iot\/snake-and-pong-games-on-an-esp32\/","url_meta":{"origin":295,"position":4},"title":"Snake and Pong games on an ESP32","author":"Lab Student","date":"28.10.2025","format":false,"excerpt":"Introduction Hi, our team is formed with three members Roope Rajahalme, Rasmus Rautakallio and Phong Phan. Before this course our background in programming and electronics was quite basic. We had some experience with Java programming projects but had never worked with displays or games before. We all had deep love\u2026","rel":"","context":"In &quot;ESP32&quot;","block_context":{"text":"ESP32","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/esp32\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2025\/10\/b7f9bdbb5cfd3042dea94ae15f62ccff-1024x768.jpeg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2025\/10\/b7f9bdbb5cfd3042dea94ae15f62ccff-1024x768.jpeg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2025\/10\/b7f9bdbb5cfd3042dea94ae15f62ccff-1024x768.jpeg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":550,"url":"https:\/\/www.hh3dlab.fi\/blog\/esp32\/550\/","url_meta":{"origin":295,"position":5},"title":"Air Quality and Control System","author":"Heikki Hietala, lab admin","date":"11.10.2024","format":false,"excerpt":"October 2024 - (c) Stephen Swanson Check it out on GitHub Introduction Hi! I\u2019m Stephen, a 3rd-year student at Haaga-Helia UAS. Programming and creating IoT and embedded devices are recent hobbies of mine, which I picked up in summer 2024 after some friends (Alisa Dunaeva and David Gianadda) suggested I\u2026","rel":"","context":"In &quot;BMP 280 sensor&quot;","block_context":{"text":"BMP 280 sensor","link":"https:\/\/www.hh3dlab.fi\/blog\/category\/bmp-280-sensor\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2024\/10\/Picture2.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2024\/10\/Picture2.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.hh3dlab.fi\/blog\/wp-content\/uploads\/2024\/10\/Picture2.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/posts\/295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":2,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/posts\/295\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hh3dlab.fi\/blog\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}