Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoTAssignment
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
samuel.hobman
IoTAssignment
Commits
8d95ad9e
Commit
8d95ad9e
authored
Jan 04, 2021
by
samuel.hobman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update humidity.js
parent
63780dfd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
humidity.js
humidity.js
+7
-7
No files found.
humidity.js
View file @
8d95ad9e
const
Discord
=
require
(
"
Discord.js
"
);
const
Discord
=
require
(
"
Discord.js
"
);
const
config
=
require
(
'
./config.json
'
);
const
config
=
require
(
'
./config.json
'
);
// This includes the discord Token. Which is required to lock on.
const
client
=
new
Discord
.
Client
;
const
client
=
new
Discord
.
Client
;
const
fs
=
require
(
"
fs
"
);
const
fs
=
require
(
"
fs
"
);
const
MongoClient
=
require
(
'
mongodb
'
).
MongoClient
;
const
MongoClient
=
require
(
'
mongodb
'
).
MongoClient
;
const
uri
=
"
mongodb+srv://Sam:assignment@cluster0.issnm.mongodb.net/enclosure?retryWrites=true&w=majority
"
;
const
uri
=
"
mongodb+srv://Sam:assignment@cluster0.issnm.mongodb.net/enclosure?retryWrites=true&w=majority
"
;
// this contains the password to the cluster specifically.
const
mongoClient
=
new
MongoClient
(
uri
,
{
useNewUrlParser
:
true
});
const
mongoClient
=
new
MongoClient
(
uri
,
{
useNewUrlParser
:
true
});
const
currentTime
=
new
Date
();
const
currentTime
=
new
Date
();
// date in unix epoch time.
var
intervalID
=
setInterval
(
checkData
,
60000
);
var
intervalID
=
setInterval
(
checkData
,
60000
);
client
.
once
(
'
ready
'
,
()
=>
{
client
.
once
(
'
ready
'
,
()
=>
{
console
.
log
(
"
I'm logged on!
"
);
console
.
log
(
"
I'm logged on!
"
);
});
});
client
.
on
(
'
message
'
,
async
message
=>
{
client
.
on
(
'
message
'
,
async
message
=>
{
if
(
!
message
.
content
.
startsWith
(
'
!
'
)
||
message
.
author
.
bot
)
return
if
(
!
message
.
content
.
startsWith
(
'
!
'
)
||
message
.
author
.
bot
)
return
// otherwise, a bot might constantly message itself.
const
command
=
message
.
content
.
toLowerCase
();
const
command
=
message
.
content
.
toLowerCase
();
switch
(
command
)
{
switch
(
command
)
{
case
"
!report
"
:
case
"
!report
"
:
...
@@ -83,7 +83,7 @@ async function checkData(flag){ // if flagged, the code simply sends the current
...
@@ -83,7 +83,7 @@ async function checkData(flag){ // if flagged, the code simply sends the current
function
sendToUser
(
person
,
temperature
,
humidity
){
function
sendToUser
(
person
,
temperature
,
humidity
){
person
.
send
(
"
Temperature of the enclosure is currently
"
+
temperature
+
"
C, humidity is:
"
+
humidity
+
"
%
"
);
person
.
send
(
"
Temperature of the enclosure is currently
"
+
temperature
+
"
C, humidity is:
"
+
humidity
+
"
%
"
);
}
}
function
alertHumidity
(
person
,
humidity
,
tooHumid
)
{
function
alertHumidity
(
person
,
humidity
,
tooHumid
)
{
// tooHumid defaults to false.
if
(
tooHumid
)
{
if
(
tooHumid
)
{
person
.
send
(
"
Sir, your enclosure is too humid. It is currently
"
+
humidity
+
"
%
"
);
person
.
send
(
"
Sir, your enclosure is too humid. It is currently
"
+
humidity
+
"
%
"
);
}
}
...
@@ -100,7 +100,7 @@ else {
...
@@ -100,7 +100,7 @@ else {
}
}
}
}
async
function
insertIntoMongo
(
enclosureData
){
async
function
insertIntoMongo
(
enclosureData
){
const
user
=
await
client
.
users
.
fetch
(
"
226082168294735872
"
);
const
user
=
await
client
.
users
.
fetch
(
"
226082168294735872
"
);
// this is my own Discord ID, required to make it contact me directly.
try
{
try
{
const
thisSession
=
await
mongoClient
.
connect
();
// returns a promise to connect
const
thisSession
=
await
mongoClient
.
connect
();
// returns a promise to connect
const
database
=
thisSession
.
db
(
"
enclosure
"
);
const
database
=
thisSession
.
db
(
"
enclosure
"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment