Skip to content

Commit 8f4d042

Browse files
authored
Merge pull request #1 from PsyChonek/feature/Nuxt
Feature/nuxt
2 parents 8932eb9 + d80be9f commit 8f4d042

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+5968
-4541
lines changed

.DS_Store

6 KB
Binary file not shown.

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"compile-hero.disable-compile-files-on-did-save-code": true
2+
"compile-hero.disable-compile-files-on-did-save-code": true,
3+
"cSpell.words": [
4+
"formkit",
5+
"nuxtjs"
6+
]
37
}

ESP/src/main.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,62 @@
1212
#define DHTTYPE DHT11
1313
#define DHTPIN 13
1414

15-
#define API_SERVER "http://localhost:9051"
15+
#define API_SERVER "http://192.168.0.110:9051"
1616

1717
AsyncWebServer server(80);
1818
StaticJsonDocument<64> reading;
1919
StaticJsonDocument<64> status;
2020

2121
DHT dht(DHTPIN, DHTTYPE);
2222

23-
// Variable sensorID to store the sensor ID
24-
String sensorID;
23+
// Variable espID to store the sensor ID
24+
String espID;
2525

2626
void connectToWifi();
2727
void setUpTime();
2828

29-
String getValuesJSON(float temperature, float humidity, int timestamp);
29+
String getValuesJSON(float temperature, float humidity, int timestamp, String espID);
3030

3131
String readReading();
3232

3333
void sendReading(String value);
3434
void sendInfo();
3535

36-
3736
void setup()
3837
{
3938
Serial.begin(115200);
4039
dht.begin();
4140
connectToWifi();
4241
server.begin();
4342

44-
// Generate a random sensorID and store it in the SPIFFS file system if already exists read it
43+
// Generate a random espID and store it in the SPIFFS file system if already exists read it
4544
if (!SPIFFS.begin(true))
4645
{
4746
Serial.println("An Error has occurred while mounting SPIFFS");
4847
}
4948
else
5049
{
51-
File file = SPIFFS.open("/sensorID.txt", "r");
50+
File file = SPIFFS.open("/espID.txt", "r");
5251
if (!file)
5352
{
5453
Serial.println("Failed to open file for reading");
5554

56-
file = SPIFFS.open("/sensorID.txt", "w");
55+
file = SPIFFS.open("/espID.txt", "w");
5756
if (!file)
5857
{
5958
Serial.println("Failed to open file for writing");
6059
}
6160
else
6261
{
63-
sensorID = String(random(1000, 9999));
64-
Serial.println("Sensor ID: " + sensorID);
62+
espID = String(random(1000, 9999));
63+
Serial.println("Esp ID: " + espID);
6564

66-
file.print(sensorID);
65+
file.print(espID);
6766
}
6867
}
6968

70-
sensorID = file.readString();
71-
Serial.println("Sensor ID: " + sensorID);
69+
espID = file.readString();
70+
Serial.println("Esp ID: " + espID);
7271

7372
file.close();
7473
}
@@ -94,24 +93,6 @@ void loop()
9493

9594
sendReading(readReading());
9695
}
97-
98-
// if (millis() - wifiCooldown >= wifiInterval)
99-
// {
100-
// wifiCooldown = millis();
101-
// if (WiFi.status() != WL_CONNECTED)
102-
// {
103-
// connectToWifi();
104-
// }
105-
// else
106-
// {
107-
// Serial.print("IP Address: ");
108-
// Serial.print(WiFi.localIP());
109-
// Serial.print(" Uptime: ");
110-
// Serial.println(millis() / 1000);
111-
112-
// sendWifiStatusEvent();
113-
// }
114-
// }
11596
}
11697

11798
void connectToWifi()
@@ -131,15 +112,16 @@ void connectToWifi()
131112

132113
String readReading()
133114
{
134-
return getValuesJSON(dht.readTemperature(), dht.readHumidity(), time(&now), sensorID);
115+
return getValuesJSON(dht.readTemperature(), dht.readHumidity(), time(&now), espID);
135116
}
136117

137118
void sendInfo()
138119
{
139-
status["sensorID"] = sensorID;
120+
status["espID"] = espID;
121+
status["ip"] = WiFi.localIP().toString();
140122

141123
String values;
142-
serializeJson(wifiStatus, values);
124+
serializeJson(status, values);
143125

144126
Serial.println("making POST request");
145127

@@ -177,7 +159,7 @@ void sendReading(String value)
177159
}
178160

179161
// Send values to web page
180-
String getValuesJSON(float temperature, float humidity, int timestamp = 0, String sensorID = "")
162+
String getValuesJSON(float temperature, float humidity, int timestamp = 0, String espID = "")
181163
{
182164
if (isnan(temperature) || isnan(humidity))
183165
{
@@ -189,7 +171,7 @@ String getValuesJSON(float temperature, float humidity, int timestamp = 0, Strin
189171
reading["temperature"] = temperature;
190172
reading["humidity"] = humidity;
191173
reading["timestamp"] = timestamp;
192-
reading["sensorID"] = sensorID;
174+
reading["espID"] = espID;
193175

194176
String values;
195177
serializeJson(reading, values);

README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
1-
# Readme
1+
# ClimateTracker
22

33
## Before you start
44

5-
This is not nice project, it is bloated and not well written. I am not proud of it, but it works.
5+
This project is a simple app for ESP to monitor humidity and temperature in the room. It is an HTML server with JavaScript, data is stored in MongoDB and can be downloaded. The website is responsive and can be used on mobile devices.
66

77
## Description
88

9-
This project is simple app for ESP to monitor humidity and temperature in the room. It is html server with javascript, data is stored in file and can be downloaded, website is responsive and can be used on mobile devices.
9+
ClimateTracker allows you to monitor humidity and temperature using an ESP device. The data is displayed on a responsive web interface and can be downloaded for further analysis.
10+
11+
## Features
12+
13+
- Real-time monitoring of temperature and humidity
14+
- Responsive web interface
15+
- Data storage and download capability
16+
- Customizable settings for data display
17+
- Support for multiple sensor types
18+
19+
## Technologies Used
20+
21+
- **PlatformIO**: An open-source ecosystem for IoT development.
22+
- **ESP32**: A low-cost, low-power system on a chip microcontroller.
23+
- **Vue.js**: A progressive JavaScript framework for building user interfaces.
24+
- **Nuxt.js**: A framework for creating Vue.js applications with server-side rendering.
25+
- **Chart.js**: A JavaScript library for creating charts.
26+
- **Vue Chart.js**: A wrapper for Chart.js in Vue.
27+
- **Tailwind CSS**: A utility-first CSS framework.
28+
- **Axios**: A promise-based HTTP client for the browser and Node.js.
29+
- **TypeScript**: A typed superset of JavaScript that compiles to plain JavaScript.
30+
- **MongoDB**: A NoSQL database for storing sensor data.
1031

1132
## How to use
1233

@@ -19,21 +40,20 @@ This project is simple app for ESP to monitor humidity and temperature in the ro
1940

2041
1. Clone this repository
2142
2. Install [PlatformIO](https://platformio.org/)
22-
3. Connect your ESP32 to computer
43+
3. Connect your ESP32 to your computer
2344
4. Open this project in PlatformIO
24-
5. Change `ssid` and `password` in `src/main.cpp` to your wifi credentials
45+
5. Change `ssid` and `password` in `src/main.cpp` to your WiFi credentials
2546
6. Change `sensorType` in `src/main.cpp` to your sensor type
26-
7. Upload project to ESP32
27-
8. Upload File System image to ESP32
28-
9. Reserve IP address for ESP32 in your router
29-
10. Set up local DNS to redirect `eps.local` to IP address of ESP32
30-
11. Open `eps.local` in your browser
31-
12. Enjoy
47+
7. Upload the project to ESP32
48+
8. Upload the File System image to ESP32
49+
9. Reserve an IP address for ESP32 in your router
50+
10. Set up local DNS to redirect `esp.local` to the IP address of ESP32
51+
11. Run `docker-compose up -d` to start MongoDB, Express, and Nuxt
52+
12. Open `esp.local` in your browser
53+
13. Enjoy
3254

3355
## Images
3456

35-
![docs/Mobile.png](docs/Mobile.png)
36-
3757
## License
3858

39-
This project is licensed under the MIT License - see the [LICENSE](LICENSE.txt) file for details.
59+
This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for details.

docs/Mobile.png

-35.4 KB
Binary file not shown.

docs/PC.png

-84.6 KB
Binary file not shown.

esp/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

esp/include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

esp/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

esp/platformio.ini

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:denky32]
12+
platform = espressif32
13+
board = denky32
14+
framework = arduino
15+
monitor_speed = 115200
16+
lib_deps =
17+
adafruit/DHT sensor library@^1.4.6
18+
adafruit/Adafruit Unified Sensor@^1.1.14
19+
esphome/ESPAsyncWebServer-esphome@^3.1.0
20+
esphome/AsyncTCP-esphome@^2.0.1
21+
bblanchon/ArduinoJson@^6.21.3

0 commit comments

Comments
 (0)