The backend/server infrastructure ensures seamless communication between user interfaces and smart devices, utilizing Node.js with Express.js for server operations. It employs MongoDB for data storage, Socket.io for real-time updates, JWT for secure authentication, and thorough testing for reliability.
Clone the project
git clone [email protected]:Smart-House-Engineering/Backend.git
Go to the project directory
cd Backend
Install dependencies
npm install
Create .env file in the root folder:
- add PORT=5000
- add database URI link
- add secret key
Start the server
npm run start
To run tests, run the following command
npm run test
To run tests with coverage, run the following command
npm run coverage
Server:
- Node.js
- Express.js
- Socket.io
- MongoDB
Testing:
- Jest
- Supertest,
- Mongodb-memory-server
Endpoint for adding the house/homeId to database. Done by the party that sets up the Smarthome.
POST /api/smarthome/addhome
Parameter | Type | Description |
---|---|---|
homeId |
string |
Required. The smarthouse HomeId.git |
{
"homeId": "ExampleHomeId"
}
Endpoint for adding the owner to homeId. Done by the party that sets up the Smarthome.
POST /api/smarthome/registerOwner
Parameter | Type | Description |
---|---|---|
homeId |
string |
Required. The homeId of the registered house. |
email |
string |
Required. The owner's email address. |
password |
string |
Required. The owner's password. |
{
"email": "[email protected]",
"password": "Example1",
"homeId": "ExampleHomeId"
}
Endpoint for user login.
POST /auth/login
Parameter | Type | Description |
---|---|---|
email |
string |
Required. The user's email address. |
password |
string |
Required. The user's password. |
{
"email": "[email protected]",
"password": "Example1"
}
Endpoint for user Logout.
POST /auth/logout
No parameters are required for this endpoint.
// No request body required for logout
Endpoint for getting the sensor's data. Accessible for all users logged in.
GET /api/modes/defaultMode
No parameters are required for this endpoint.
// No request body required for logout
Endpoint for getting the modes's data. Accessible for all users logged in.
GET /api/modes/otherModes
No parameters are required for this endpoint.
// No request body required for logout
Endpoint for updating the sensor data. Accessible for OWNER
and TENANT
. Only the sensors being updated need to be included in the request body.
PUT /api/homeUser/defaultMode
Parameter | Type | Description |
---|---|---|
fan |
boolean |
Optional. Indicates the status of the smarthome fan. |
RFan |
boolean |
Optional. Indicates the status of the smarthome RFan. |
motion |
boolean |
Optional. Indicates the status of the motion sensor. |
buzzer |
boolean |
Optional. Indicates the status of the buzzer. |
relay |
boolean |
Optional. Indicates the status of the relay. |
door |
number |
Optional. Indicates the status of the door sensor. |
window |
number |
Optional. Indicates the status of the window sensor. |
yellowLed |
number |
Optional. Indicates the status of the yellow LED. |
gasSensor |
number |
Optional. Indicates the status of the gas sensor. |
photocell |
number |
Optional. Indicates the status of the photocell sensor. |
soilSensor |
number |
Optional. Indicates the status of the soil sensor. |
steamSensor |
number |
Optional. Indicates the status of the steam sensor. |
whiteLed |
boolean |
Optional. Indicates the status of the white LED. |
button1 |
boolean |
Optional. Indicates the status of button 1. |
button2 |
boolean |
Optional. Indicates the status of button 2. |
lights |
boolean |
Optional. Indicates the status of the lights. |
{
"updatedDevices": {
"fan": false,
"door": 0,
"window": 1,
"yellowLed": 0
}
}
Endpoint for updating the smarthouse modes. Accessible for OWNER
and TENANT
. Only the modes being updated need to be included in the request body.
PUT /api/homeUser/otherModes
Parameter | Type | Description |
---|---|---|
emergency |
boolean |
Optional. Updates the status of the emergency mode. |
{
"updatedModes": {
"emergency": true
}
}
Endpoint for adding a new user to the smarthouse. Route is accessible only to the OWNER
. Possible to add users with role: TENANT
or EXTERNAL
.
POST /api/owner/addUser/
Parameter | Type | Description |
---|---|---|
newUserEmail |
string |
Required. The new user's email address. |
newUserPassword |
string |
Required. The new user's password. |
newUserRole |
string |
Required. The new user's password. |
{
"newUserEmail": "[email protected]",
"newUserPassword": "Example1",
"newUserRole": "TENANT"
}
Endpoint for deleteing a user from the smarthouse. Route is accessible only to OWNER
.
DEL /api/owner/deleteUser/
Parameter | Type | Description |
---|---|---|
deleteUserEmail |
string |
Required. The to be deleted user's email address. |
{
"deleteUserEmail": "[email protected]"
}
Endpoint for getting the User's data. Accessible for all users logged in.
GET /api/user/data
No parameters are required for this endpoint.
// No request body required for logout
Endpoint for getting the users info, who have been added to a specific HomeId. Accessible for all users logged in.
GET /api/user/allMembers
No parameters are required for this endpoint.
// No request body required for logout