0

How to send data from ESP8266 to Node.js server

I am doing a smart home project where an ESP8266 WiFi module collects data from sensors and sends the data to a website. I have programmed the ESP8266 to collect data successfully. Unfortunately, my university course does not teach us web development, so I have to learn web development by myself. After some research and learning, I managed to use Node.js to create a backend web server and launch a simple website (using my computer as local host). However, I still do not understand how to send data from the ESP8266 to the Node.js server. I found that there are a few ways to send data from the ESP8266 to a web server. Some examples are HTTP, MQTT, web socket, firebase and etc. Since I am new to this, can you guys give some suggestion on which way is better/easier to use? Kindly provide relevant tutorials if possible. Thank you.

28th May 2020, 9:38 AM
Hanz
Hanz - avatar
8 odpowiedzi
+ 1
You can build web server directly on ESP8266 using JavaScript. Follow this tutorial https://youtu.be/toT6gQ4JNrs
28th May 2020, 10:07 AM
Calviղ
Calviղ - avatar
+ 1
@Calviղ Thanks for your answer! I have tried to host a web server on ESP8266 following this tutorial: https://randomnerdtutorials.com/esp8266-web-server/ This method is indeed an easier way to create a local web server, but there's an issue - ESP8266 can only act as a local server and can't access the Internet (under the soft-AP mode). At the moment, I am hosting the server locally for development purpose. I need to host the server on the Internet (with a proper domain/ip) at the end of this project. SInce ESP8266 cannot host a website on the Internet, it will only be used to transfer data instead of being used as a local server. Your video still helps tho. I will go have a look at Espruino
28th May 2020, 11:19 AM
Hanz
Hanz - avatar
+ 1
Hanz I intend to buy oneESP8266 for my home automation, how much you bought? Where did it from? Currently I have Raspberry pi 3 and Arduino Uno, looking for a wireless module.
28th May 2020, 11:59 AM
Calviղ
Calviղ - avatar
+ 1
Martin Taylor Thanks for your reply! I am trying out http for now. Since I'm still not familiar with http, the connection keeps failing (keep getting "404 not found" =_=). Will try to look into that further, thanks for the tutorial u provided
28th May 2020, 2:52 PM
Hanz
Hanz - avatar
0
Calviղ In my university, we generally use the ESP-01 or the NodeMCU LoLin V3, and use Arduino IDE for coding. I bought them from my senior, but you can find the modules online. Esp-01 is the cheapest version of ESP8266, but is less user friendly (only 2 I/O ports, upload code from Arduino/FTDI module): https://shopee.com.my/product/32805005/544710350?smtt=0.0.9 Nodemcu lolin v3 is more costly but more user friendly (more I/O ports, upload code from computer directly): https://shopee.com.my/product/132528683/2134763370?smtt=0.0.9 Do note that there are several variations of ESP8266 in the market. Those variations have similar way of coding but have different number of I/O, pinouts etc.
28th May 2020, 3:38 PM
Hanz
Hanz - avatar
0
I am having the same problem... I am able to read my sensor data off my nodemcu but I cant figure out how to send it to my backend.. I am running an express server on my local host for now and for the life of me cant figure it out. Did you ever get it?
3rd Sep 2020, 1:01 AM
Mando Rodriguez
Mando Rodriguez - avatar
0
Did you ever figure this out? I recently started learning Node.js to use with my esp8266. I also want to communicate on an internet server and not a local host. Any luck on finding a solution?
30th Apr 2021, 2:18 AM
Jimmie Smith
Jimmie Smith - avatar
0
Hi, here's the update on my project. After trying out Node.js and HTTP, I realized I was not familiar with them and ended up using Firebase instead. Firebase is rather beginner-friendly since it has readily built database and supports useful features such as web hosting. Here I attach some links to set up the ESP8266/NodeMCU and Firebase: https://senuravihanjayadeva.medium.com/connect-google-firebase-with-nodemcu-esp8266-7905d4b759f9 https://www.instructables.com/Esp8266-Firebase-Connection/?amp_page=true I hope this would be helpful to you.
30th Apr 2021, 2:21 PM
Hanz
Hanz - avatar