Temperature and Humidity project
Nicholas Howland, 5/2/2025
I recently decided to sit down and improve on an old hobby project I was working on a long time ago that involved using a DHT11 sensor to collect data about the temperature and humidity through an arduino ESP3266. The client vision I initially developed was to just have it connect to a wifi network and make the data available to anyone who discovered the IP address but I wanted it to make it a little more flexable. I recently added a new script to the github repo that will make the device into an access point and serve a webpage that auto refreshes the data from the sensor as well as adding an API endpoint to get data via JSON. There is still a lot of room for improvement especially for security considerations outlined in the last section of this blog. If you want to colaborate or suggest edits fork the repo and suggest improvements they are always welcome.
The source files can be found here as well as a basic implementation guide: https://github.com/ExylumTechnical/Arduino/tree/main/Weather-Station
What this is: a fun project
What this is not: to be used in any kind of commercial or sensitive environment.
Stuff needed
- DHT11 sensor
- Arduino ESP3266
- A wireless network to connect it to if your using the device in client mode using the client.ino file
- A creative SSID and Password if you are using the ap.ino file
Configuration
- Connect the DHT11 sensor data pin to port D4 on the ESP3266 board.
- Download the .ino files and change the SSID and password of the AP or Wireless network as required
- Upload the ap.ino file for ap mode and the client.ino for client mode to the ESP3266 board
- Either connect to the broadcasted SSID/Network name or find the IP address on the Wireless network you configured the device to connect to.
- The Arduino IDE will also require the DHT11 sensor library be installed which is available through the library downloader.
- The board configuration and libraries must be downloaded as well by putting the string
https://arduino.esp8266.com/stable/package_esp8266com_index.json
into the additional boards configuration input field. (File -> Preferences -> Additional Boards Manager URLs)
How to use
Once configured and uploaded the data should be available to view in a webbrowser by surfing to the ip address 192.168.4.1 or if you want to start pulling data via json the endpoint 192.168.4.1/api/data is available.
Client Mode
- Make sure you have pre-programed the SSID and password into the sourcecode before uploading the script
- Once the device connects to the network you may need to run an IP scan on the network to find it if you dont have access to the console directly
- Once the IP address is located you can browse to the root directory which should display a simple page displaying the temperature in ferenheit and celsius as well as the current humidity.
- This main page will update every second, if you get an error make sure the DHT11 sensor is connected properly and functioning as expected.
- Alternatively the endpoint 192.168.4.1/api/data can be used to pull data in json format
{"celsius":"0","ferenheit":"0","humidity":"0",}
AP Mode
- When in AP mode using the ap.ino file the sensor will act as an independent wireless network and can be connected to using the SSID and pre shared key (APPSK) found in the sourcecode.
- Once powered on it will broadcast the SSID and allow any device to connect to it and read data from the webserver.
Considerations
Http server
- There is some error handling if the DHT sensor gets disconnected the json output will display an error something like the following
{"error":"DHT Error"}
- The html page will auto update every second if being viewed in a browser or an automated client that allows for javascript execution.
Lost the AP information
- By connecting a microUSB to the main port on the Arduino the SSID and PSK will be output if the device is being used in an AP mode. This can be a security concern so it is best practice to keep the device enclosed and out of easy reach from the general public.
To Do and Future improvements
I would really like to add the following features to the device as time allows
- Allow for the device owner to change from AP mode to Client mode without having to recompile and upload every time.
- Allow for changing the SSID and Password when needed ill need to look into altering the device memory through post requests, however this could introduce memory safety issues and overwrites to other variubles and system crashses if not done safely.
- When the device is in client mode to allow it to be pointed to a data collection server on the LAN
- Add hidden SSID support if device SSID is abused
If you value what is posted here and feel compelled to donate you can do so here, no pressure but always appriceated.