Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global code review #9

Open
wants to merge 122 commits into
base: reviewed
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
be1792d
refactor: change repository (#1)
Rignchen Apr 8, 2024
70f6f43
feat: implement login (#5)
jordyBSK Apr 12, 2024
9042cb9
feat: launch everything from the same docker compose (#2)
Rignchen Apr 12, 2024
308e75f
Fix: fix a few issues on the backend (#6)
Rignchen May 31, 2024
7752bef
feat: plan canvas (#8)
jordyBSK Jun 3, 2024
d85de2d
feat: get the ip address when averaging the values with the avg_date …
Rignchen Jun 7, 2024
2b4b46f
feat: setup a sqitch to handle migrations (#23)
Rignchen Jun 10, 2024
a5214ed
fix: readme and use latest docker images (#24)
Rignchen Jun 10, 2024
3148fca
refactor: reposition php code in the folder (#25)
Rignchen Jun 10, 2024
b983d79
fix: install php stan (#26)
Rignchen Jun 11, 2024
6283251
Interface next js (#28)
jordyBSK Jun 18, 2024
ad260bc
Login (#29)
jordyBSK Jun 18, 2024
16af540
Get data.ts files (#30)
jordyBSK Jun 18, 2024
d94906a
refactor: renamed file type and function for better separation (#31)
Alex-zReeZ Jun 18, 2024
e095c1b
feat: implement logout (#32)
jordyBSK Jun 19, 2024
32d7886
add Esp table (#33)
jordyBSK Jun 19, 2024
5fd26f4
fix: redirect to login when we logout (#34)
jordyBSK Jun 19, 2024
f12bde6
sort data by room ip (#35)
jordyBSK Jun 19, 2024
48db262
Revert "sort data by room ip (#35)" (#36)
jordyBSK Jun 19, 2024
00d6c9e
Revert "Revert "sort data by room ip (#35)" (#36)" (#37)
jordyBSK Jun 19, 2024
6d4434c
Plan data (#38)
jordyBSK Jun 20, 2024
38e1aec
feat: added dynamic data in dashboard and esp pages (#39)
Alex-zReeZ Jun 21, 2024
f3ed78b
Date range (#40)
jordyBSK Jun 21, 2024
8ec2912
fix: fix import duplication (#41)
jordyBSK Jun 21, 2024
2be57e8
fix: change dockerfile to work with next js
Alex-zReeZ Jun 24, 2024
4a1417d
refactor: added new Ip adresse
Alex-zReeZ Jun 24, 2024
3db6d23
refactor: removed output and added distdir to out
Alex-zReeZ Jun 24, 2024
0d16c0f
refactor: reformated file
Alex-zReeZ Jun 24, 2024
8d04934
refactor: added new Ip adresse, rounded data, moved getColor file and…
Alex-zReeZ Jun 25, 2024
4197a28
refactor: Rounded data (#42)
Alex-zReeZ Jun 25, 2024
16a782f
fix: tofixed temperature in espmap
Jun 25, 2024
36315e8
feat: added Workflow to check the format and lint (#46)
Alex-zReeZ Jun 25, 2024
1619744
refactor: resolve conflit
Jun 25, 2024
d150924
Merge branch 'Dev' of github.com:museebolo/climat_guardian into Dev
Jun 25, 2024
fbf86e5
Merge remote-tracking branch 'upstream/Dev' into Dev
Alex-zReeZ Jun 25, 2024
27f2fc5
feat: serve interface using a nodejs server (#48)
Rignchen Jun 25, 2024
b913fde
Merge remote-tracking branch 'upstream/Dev' into Dev
Alex-zReeZ Jun 25, 2024
ccd1027
fix: logout redirection (#49)
jordyBSK Jun 25, 2024
226b0a3
refactor: moved .github directory to root
Alex-zReeZ Jun 25, 2024
5934484
refactor: changed workflow execution type (#47)
Alex-zReeZ Jun 25, 2024
392eb9c
Merge branch 'Dev' of github.com:museebolo/climat_guardian into Dev
Alex-zReeZ Jun 25, 2024
f5864fb
style: properly format code
Jun 25, 2024
2a20a7e
fix: fix bugs to prepare for release (#50)
jordyBSK Jun 25, 2024
28306f3
fix: changed format commande and added format check and fix ts config…
Alex-zReeZ Jun 25, 2024
366d14c
feat: push production ready version to main (#52)
jordyBSK Jun 25, 2024
0639d73
Merge branch 'main' into fix-prettier-config
Alex-zReeZ Jun 25, 2024
f7f65b8
Revert "feat: push production ready version to main (#52)" (#53)
jordyBSK Jun 25, 2024
fa206fd
Merge pull request #54 from museebolo/Dev
jordyBSK Jun 25, 2024
df703d3
Merge branch 'main' into fix-prettier-config
Alex-zReeZ Jun 25, 2024
7940eae
refactor: removed -D flag in npm install and reformated code
Alex-zReeZ Jun 25, 2024
d456c85
Merge remote-tracking branch 'origin/fix-prettier-config' into fix-pr…
Alex-zReeZ Jun 25, 2024
5bb4b39
fix: fixed workflow not finding package lock because in the wrong dir…
Alex-zReeZ Jun 25, 2024
4a77a4a
fix: fix changed direction directory
Alex-zReeZ Jun 25, 2024
7980609
fix: fix changed cd direction
Alex-zReeZ Jun 25, 2024
92683b6
refactor: changed steps order
Alex-zReeZ Jun 25, 2024
521ba26
refactor: specified where to find package-lock.json
Alex-zReeZ Jun 25, 2024
3fb499b
refactor: removed change directory and replaced it with working-direc…
Alex-zReeZ Jun 25, 2024
c125ea7
Merge pull request #51 from Alex-zReeZ/fix-prettier-config
jordyBSK Jun 25, 2024
57152bf
fix: update developpment docker compose to work with current state of…
Rignchen Jun 26, 2024
4ef8f0a
fix: add .env inside php and nextjs folders (#57)
Rignchen Jun 26, 2024
7bcbfc3
Merge pull request #58 from museebolo/Dev
fuzoh Jun 27, 2024
5380f2a
Migration esp (#60)
jordyBSK Jun 27, 2024
f467e4d
refactor: Change interface style (#61)
Alex-zReeZ Jun 28, 2024
3ccd42e
feat: added display of the average of data in chosen range (#62)
Alex-zReeZ Jun 28, 2024
d463987
Middleware (#64)
jordyBSK Jul 1, 2024
164ee27
feat: added dark theme (#63)
Alex-zReeZ Jul 1, 2024
2c78465
feat: edit esp position (#65)
jordyBSK Jul 2, 2024
298994d
Feat: added possibility to rename an esp and added reload when adding…
Alex-zReeZ Jul 2, 2024
2567559
fix: added missing import of useState and reformated code (#67)
Alex-zReeZ Jul 2, 2024
57e298f
refactor: refactoring html structure for simpler structure (#68)
Alex-zReeZ Jul 3, 2024
38192a0
fix: resolved conflit (#71)
jordyBSK Jul 3, 2024
67625a7
refactor: changed graph hover popup, reformated files and removed unu…
Alex-zReeZ Jul 4, 2024
f694eb1
fix: replace local storage for cookies to store theme of user (#73)
Alex-zReeZ Jul 4, 2024
35505ab
refactor: changed branch and type execution of workflow to main (#74)
Alex-zReeZ Jul 4, 2024
8949ea8
ci: added workflow to check if the docker builds (#75)
Alex-zReeZ Jul 4, 2024
5146d68
style: change dark mode colors and use shadcn card (#77)
jordyBSK Jul 4, 2024
968f8fe
ci: added curl check to test (#78)
Alex-zReeZ Jul 4, 2024
0cc19ff
refactor: dashboard scroll (#79)
jordyBSK Jul 4, 2024
856f93b
Feat: added precision selector on esp page graph (#80)
Alex-zReeZ Jul 4, 2024
12f3cf3
refactor: Fix responsive in esp rooms and little details (#81)
Alex-zReeZ Jul 4, 2024
84e7b48
fix: fixed workflow to check for token (#84)
Alex-zReeZ Jul 4, 2024
d0dce56
refactor: check if token is valid (#85)
jordyBSK Jul 4, 2024
a7a3995
refactor: centered thermometer (#86)
Alex-zReeZ Jul 5, 2024
26cd04a
refactor: display ip address (#88)
jordyBSK Jul 5, 2024
92b90cc
refactor: changed border color in precision selector (#87)
Alex-zReeZ Jul 5, 2024
0056ec4
feat: allow users to remove users (#89)
Rignchen Jul 5, 2024
a856bbf
refactor: added button to show esp jwt token (#90)
Alex-zReeZ Jul 5, 2024
b3115ec
feat: implement add users in database (#91)
jordyBSK Jul 5, 2024
683f9ea
fix: fixed function getting user token instead of esp token (#92)
Alex-zReeZ Jul 5, 2024
4ec1499
feat: added gap on add user input (#93)
jordyBSK Jul 5, 2024
79b8d1b
fix: fixed jwt token fetch getting no Ip (#94)
Alex-zReeZ Jul 5, 2024
b7364e6
refactor: install the slim router for the php (#27)
Rignchen Jul 5, 2024
d8a64f5
feat: remove reload on move esp (#96)
jordyBSK Jul 8, 2024
d9a1758
feat: remove the choice of precision according to the days chosen (#95)
jordyBSK Jul 8, 2024
3aa4305
refactor: removed window reload when adding new esp to display new es…
Alex-zReeZ Jul 9, 2024
313a2a9
refactor: added verification of IP input with js (#99)
Alex-zReeZ Jul 9, 2024
e591139
docs: update readme (#101)
Rignchen Jul 9, 2024
ed38067
feat: Seperate days by a bar and added time stamp of data on graph (#…
Alex-zReeZ Jul 10, 2024
4a32441
fix: allow esp to know who they are (#106)
Rignchen Jul 10, 2024
f95ef11
fix: removed hardcoded localhost link (#107)
Alex-zReeZ Jul 10, 2024
4697933
refactor: added timestamp in graph xAxis (#108)
Alex-zReeZ Jul 10, 2024
bab4e08
refactor: removed readme in nextjs interface (#110)
Alex-zReeZ Jul 10, 2024
5e7e65a
fix: fix check build workflow and set timezon UTC+02:00 (#112)
Alex-zReeZ Aug 5, 2024
26ed858
fix: fix warning "list should have unique key" (#118)
Alex-zReeZ Aug 6, 2024
01c45dc
feat: added zooming interface in plan (#121)
adbme Aug 14, 2024
04cba05
feat: show the day when clicking on it (#122)
adbme Aug 15, 2024
c5c372f
Fix espid link when clicking on day (#123)
adbme Aug 16, 2024
5db9cfd
feat: show variance between days with two esp (#124)
adbme Aug 27, 2024
c451411
docs: add database and migrations documentation (#125)
fuzoh Aug 28, 2024
558a92a
ci: setup dependabot for automatic versions updates (#128)
fuzoh Aug 28, 2024
8c667f1
build: refactor dockerfiles name to avoid file type mismatches (#134)
fuzoh Aug 28, 2024
775dc2f
build(deps): bump micromatch from 4.0.7 to 4.0.8 in /nextjs-interface…
dependabot[bot] Aug 28, 2024
08e569a
build(deps-dev): bump @types/react in /nextjs-interface (#133)
dependabot[bot] Aug 28, 2024
0e4ecff
build(deps-dev): bump typescript in /nextjs-interface (#140)
dependabot[bot] Sep 4, 2024
e2b7852
build(deps): bump @radix-ui/react-popover in /nextjs-interface (#131)
dependabot[bot] Sep 4, 2024
7ee95a3
build(deps): bump @radix-ui/react-label in /nextjs-interface (#130)
dependabot[bot] Sep 4, 2024
2964325
build(deps): bump @radix-ui/react-slot in /nextjs-interface (#129)
dependabot[bot] Sep 4, 2024
c6b1400
build(deps-dev): bump typescript in /nextjs-interface (#141)
dependabot[bot] Oct 1, 2024
7ecabdd
build(deps): bump @radix-ui/react-select in /nextjs-interface (#152)
dependabot[bot] Oct 22, 2024
5fb51b5
build(deps): bump next from 14.2.3 to 14.2.10 in /nextjs-interface (#…
dependabot[bot] Oct 25, 2024
dd2853a
build(deps): bump @hookform/resolvers in /nextjs-interface (#142)
dependabot[bot] Oct 25, 2024
07bf449
build(deps): bump @radix-ui/react-tooltip in /nextjs-interface (#162)
dependabot[bot] Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .assets/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/esp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/hardware-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/software-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .assets/users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
POSTGREST_API=http://postg-rest:3000
DETAILED_ERRORS=false

ESP_PATH=./esp32/config
DB_PATH=./database/data

JWT_SECRET=
POSTGRES_PASSWORD=
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# $schema: https://json.schemastore.org/dependabot-2.0.json

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/nextjs-interface" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "composer"
directory: "/php"
schedule:
interval: "weekly"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
43 changes: 43 additions & 0 deletions .github/workflows/Build-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: check docker build

on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: copie .env file
run: |
cp .env.example .env
cp esp32/config/secrets.yaml.example esp32/config/secrets.yaml

- name: generate random jwt secret token
run: |
sed -i '/JWT_SECRET/d' .env
echo "JWT_SECRET=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32)" >> .env

- name: generate random password for jwt token
run: |
sed -i '/POSTGRES_PASSWORD/d' .env
echo "POSTGRES_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32)" >> .env

- name: build and test
run: docker compose -f docker-compose.prod.yml up -d --remove-orphans --build

- name: test login with admin return token
run: |
sleep 10
export TOKEN=$(curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "admin"}' http://localhost/php/login | jq ".token")
if [ "$TOKEN" == "null" ] || [ -z "$TOKEN" ]; then
echo "token is empty"
exit 1
fi
47 changes: 47 additions & 0 deletions .github/workflows/formating.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Check formatting of project files with Prettier

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: nextjs-interface/package-lock.json
- name: Install dependencies
run: npm install
working-directory: nextjs-interface/
- name: Check code style with Prettier
run: npm run format:check
working-directory: nextjs-interface/

eslint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: nextjs-interface/package-lock.json
- name: Install dependencies
run: npm install
working-directory: nextjs-interface/
- name: Lint code with Eslint
run: npm run lint
working-directory: nextjs-interface/
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea/
# vim backup files
*.sw[pon]
.env
# nohup
nohup.out
10 changes: 10 additions & 0 deletions Dockerfile/Nginx.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# nginx 1.26 on port 80, keep the build output, nginx config
FROM nginx:1.26-alpine-otel
COPY ../.env /var/www/memoires-info/html/.env

# copy the nginx config
COPY ../nginx.conf /etc/nginx/conf.d/default.conf
RUN sed -i '/location \/adminer\//,/}/d' /etc/nginx/conf.d/default.conf
# copy php files for ngnix to know they exist
COPY ../php/public /var/www/memoires-info/php/public

18 changes: 18 additions & 0 deletions Dockerfile/Node.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:20.12.2-alpine3.19 as base

# node 20, build the application
FROM base
WORKDIR /app
COPY ../nextjs-interface .
COPY ../.env .
RUN npm install
RUN node_modules/.bin/next build

# serve the application
FROM base
WORKDIR /var/www/memoires-info/html
COPY --from=1 /app/out ./out
COPY --from=1 /app/node_modules/ ./node_modules/
COPY --from=1 /app/next.config.mjs .
CMD ["node_modules/.bin/next", "start"]

5 changes: 5 additions & 0 deletions Dockerfile/Node.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:20.12.2-alpine3.19
WORKDIR /var/www/memoires-info/html/
COPY ../.env ../
ENTRYPOINT ["npm", "run", "dev"]

13 changes: 13 additions & 0 deletions Dockerfile/Php.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# php 8.3 with the files, install dependencies
FROM composer:2.7
COPY ../php .
RUN composer install

# copy required files to new image
FROM php:8.3-fpm-alpine
COPY ../php/public /var/www/memoires-info/php/public
COPY ../php/src /var/www/memoires-info/php/src
COPY ../php/lib.php /var/www/memoires-info/php
COPY ../.env /var/www/memoires-info/php/
COPY --from=0 ../app/vendor /var/www/memoires-info/php/vendor

4 changes: 4 additions & 0 deletions Dockerfile/Php.dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM php:8.3-fpm-alpine
WORKDIR /var/www/memoires-info/php
COPY ../.env ../

115 changes: 113 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,113 @@
# climat_guardian
Système de surveillance climatique
[Info]: <> (
All the information that are likely to need to be updated have a comment above them like this one
)
# Climate-Guardian
This project was made for the non-profit organization memoires-informatiques\
Memoires-informatiques has a lot of old computers and other electronic devices that need to be stored in a controlled environment\
The goal of this project is to monitor the temperature and humidity of the different rooms of the organization and to display the data on a web interface

## Documentation and development

If you are interested in contributing or want to make specific configuration changes,
don't hesitate to check the [documentation](./docs). You will find information
to set up the development environment, architecture considerations and some details
to correctly use the tooling.

**! Warning**, the doc’s folder is a work in progress.
For the moment, you can still find the old documentation below.

## Setup
From now on, the computer that runs the docker will be called "server" and
the computer used by the user will be called "computer"

## Network
The server and the esp need to be connected to the same network, it is recommended to give both of them a static ip address\
The computer can be connected from any network as long as the network has open ports, otherwise you'll have to be on the same network as the server

![hardware](/.assets/hardware-diagram.png)\
![software](/.assets/software-diagram.png)

## Requirements
For this project to work you need to have the following installed on the server:
- Linux (Tested on [Ubuntu Server 22.04](https://ubuntu.com/download/server) and [Fedora 40](https://fedoraproject.org/workstation/download))
- [Docker Engine](https://docs.docker.com/engine/install/ubuntu/)
- [Docker Compose](https://docs.docker.com/compose/install/)
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)

## Installation
First thing you need to do is to clone the repository from GitHub on the server
```bash
git clone https://github.com/museebolo/climat_guardian.git
cd climat-guardian
```

--
[Info]: <> (
This is the list of all the files that end with .example
)
Once the repository is cloned you can remove the `.example` at the end of the following files:
- .env.example
- esp32/config/secrets.yaml.example
```bash
cp .env.example .env
cp esp32/config/secrets.yaml.example esp32/config/secrets.yaml
```

---
Now you want to generate a secret key for the jwt tokens used by the api
```bash
sed -i '/JWT_SECRET/d' .env
echo "JWT_SECRET=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32)" >> .env
```

You may also want to generate a random password for the database
```bash
sed -i '/POSTGRES_PASSWORD/d' .env
echo "POSTGRES_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 32)" >> .env
```

It is recommended to let the other environment variables as they are

---
Finally, you **have to** fill the Wi-Fi credentials in `esp32/config/secrets.yaml`\
You also **have to** change the `127.0.0.1` in `esp32/config/secrets.yaml` by the ip address of the server

## Start the project
Once everything is configured on the server, you can start the project by running the docker compose on the server
```bash
docker compose -f docker-compose.prod.yml up -d --remove-orphans --build
```
Once the docker is running you can access the web interface by going to the ip address of the server in the web browser of the computer\
the default user is `admin` and has `admin` as password, it is recommended to create a new user and delete the default one once you are connected, you can do so under the ``Users`` tab

![Dashboard](/.assets/dashboard.png)
![Plan](/.assets/plan.png)
![Users](/.assets/users.png)
![Esp page](/.assets/esp.png)

## ESP 32 Installation
This project uses [esp home](https://github.com/esphome/esphome) to manage the esp32, you can configure the esp32 by following the instructions below
- Connect yourself to the esp home interface by going to `127.0.0.1/esp` in the web browser of the computer (replace `127.0.0.1` with the ip address of the server)
- Plug the esp32 to the server
- Press the `+ NEW DEVICE` button inside esp home
- Name your device
- Select `ESP32` (on the top of the list)
- Press `INSTALL` and select `Plug into the computer running ESPHome Dashboard` (the 3rd option)
- Select the device with ``/dev/ttyUSB0`` as path
- Wait for the installation to finish\
Be sure to memorize the ip address of the esp32 (you can find it in the logs)
$${\color{gray} \text{[15:39:12]} \color{magenta} \text{[C]\[wifi:416\]: IP Address: 172.16.5.65}}$$
- You can now unplug the esp32 and plug it to any other power source
- Connect yourself to the dashboard from another tab in the web browser of the computer
- Press the ``ajouter un esp`` button on the left and enter the ip address of the esp32 with the name you want it to have in the interface
- Press the ``...`` on the right of the page and press ``Afficher et Copier le Token``
- Back on the esphome, press `Edit` at the bottom of the logs
- Copy everything from the line 31 of the file `esp32/esp32.yaml` on the server and paste it at the end of your esp32's configuration file
```bash
clear && cat esp32/esp32.yaml | sed -n '31,$p'
```
- Replace the XXX... at the end of the code with the token you copied
- Press `INSTALL` and select `Wirelessly` (the 1st option)
- Wait for the installation to finish
- Press `STOP` to exit the logs

1 change: 1 addition & 0 deletions database/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
8 changes: 8 additions & 0 deletions database/migration/deploy/2024-07-05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Deploy climat-guardian:2024-07-05 to pg

BEGIN;

grant delete, select on api.users to web_user; -- any user can remove users
alter table api.users alter column password type varchar(255);

COMMIT;
7 changes: 7 additions & 0 deletions database/migration/deploy/2024-07-10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Deploy climat-guardian:2024-07-10 to pg

BEGIN;

grant select on table api.esp to esp32;

COMMIT;
56 changes: 56 additions & 0 deletions database/migration/deploy/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Deploy climat-guardian:data to pg

BEGIN;

create table api.data (
temperature real,
humidity real,
timestamp timestamp NOT NULL,
ip character varying(15) NOT NULL
);
grant select on api.data to web_user;

-- convert unix timestamp to timestamp and insert it
create or replace function api.insert_data(
temperature real,
humidity real,
ip varchar(15),
unix_timestamp bigint
)
returns void as $$
begin
-- if the ip said in the token is not the same as the one in the request, then this means that the user is not who he pretends to be and we should throw an error
if (current_setting('request.jwt.claims', true)::json->>'ip' != ip) then
raise exception insufficient_privilege
using hint = 'You are not who you pretend to be';
end if;
-- insert the data
insert into api.data("temperature", "humidity", "ip", "timestamp") values (temperature, humidity, ip, to_timestamp(unix_timestamp));
end $$ language plpgsql;
grant insert on api.data to esp32;

-- create a function to get the average temperature and humidity of each delta time
create function api.avg_date(
delta varchar
)
returns table(
avg_temperature double precision,
avg_humidity double precision,
date timestamp,
ip character varying(15),
count bigint
) as $$
begin
return query select
avg(temperature) as avg_temperature,
avg(humidity) as avg_humidity,
date_trunc(delta, timestamp) as date,
data.ip,
count(*) as count
from api.data
group by date, data.ip
order by date;
end;
$$ language plpgsql;

COMMIT;
Loading
Loading