How can I run a webserver in a Arduino Uno? I want to use my Arduino to monitor things in my home such as temperature. I want to be able to access this data through the internet.
2 Answers
You'll need something like the Ethernet Shield to connect your Arduino Uno to a LAN.
As for webserver functionality, the Webserver Example sketch does the bulk of what you need.
For the "access this data through the internet" part, assuming you want access beyond your LAN; you'll need to perform Port Forwarding on your local router (i.e. allow the "Internet" to see your Arduino).
If you need wifi, then personally I prefer the CC3300 to the Arduino Wifi shield.
-
7it's easier to let the arduino just emit periodic UDP packets with the relevant data and have another computer do the heavy lifting of hosting the webserver (and it can do logging) Commented Mar 5, 2014 at 14:10
-
1It's important to note that many new users to Arduino don't realise quite how small it is, and how limited a web server you can build. Don't even expect anything near to a home router's config pages in complexity. Commented Mar 5, 2014 at 15:09
-
UDP is great, but don't forget that UDP is open to packet loss. If you need each and every sample you'd need to make sure you send it multiple times. Then you'd also need to timestamp or identify it. So UDP can become cumbersome. The Original Poster requested info on implementing a Server. The data sent can be as little as just the temperature value. We shouldn't assume a fancy Webpage is required. Commented Mar 5, 2014 at 17:39
-
@akellyirl with a direct connection and one-way traffic (or connected to a switch with store-and-forward) there will be no packet loss unless the cable is bad Commented Mar 6, 2014 at 12:42
The Arduino Yún has been made with this use case in mind. The Bridge library allows your sketch to publish data such as sensor readings: this data is available through a REST api.
Say you want to publish the temperature of your living room: you'll write something like
Bridge.put("living_room", String(19)); //celsius
You can then access the data via web with a URL like
http://arduino.local/data/get/living_room
You can get all sensor readings without specifying the key name, with
http://arduino.local/data/get