Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/modem-internet'
Browse files Browse the repository at this point in the history
  • Loading branch information
daaru00 committed Apr 14, 2018
2 parents 36959b8 + f2bd899 commit 3d7ddb9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export MSG_MOTION_DEACTIVATED=
export MSG_BUTTON_CLICKED=
export MSG_NOT_A_COMMAND=
export MSG_COMMAND_NOT_FOUND=
export MSG_ADMIN_DISCONNECTED=
export MSG_ADMIN_CONNECTED=
export MSG_WELCOME=
export MSG_ACK=Ok

Expand Down
9 changes: 9 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ module.exports.elaborateCommand = (event, context, callback) => {
}
})
break;
case "/modem":
iot.getThingShadow("Modem", function(err, data){
if(err){
callback(err);
}else{
telegram.sendMessage("Download: "+data.download+"Mb/s \nUpload: "+data.upload+"Mb/s \nIP: "+data.publicIP, callback);
}
})
break;
case "/buzz":
iot.publishOnTopic('buzzer-ring', JSON.stringify({
timeout: 2000
Expand Down
30 changes: 30 additions & 0 deletions notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ module.exports.motionDectivated = (event, context, callback) => {
})

};

module.exports.adminConnected = (event, context, callback) => {

iot.updateThingShadow('Motion', {
enable: 0
}, function(err, data){
if(err){
console.error("Error publishing message");
callback(err);
}else{
telegram.sendMessage(process.env.MSG_ADMIN_CONNECTED, callback)
}
})

};

module.exports.adminDisconnected = (event, context, callback) => {

iot.updateThingShadow('Motion', {
enable: 1
}, function(err, data){
if(err){
console.error("Error publishing message");
callback(err);
}else{
telegram.sendMessage(process.env.MSG_ADMIN_DISCONNECTED, callback)
}
})

};
18 changes: 18 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ functions:
sql: "SELECT * FROM 'motion-deactivated'"
enabled: true

telegramAdminConnected:
handler: notify.adminConnected
environment:
MSG_ADMIN_CONNECTED: ${env:MSG_ADMIN_CONNECTED}
events:
- iot:
sql: "SELECT * FROM 'modem-admin-connected'"
enabled: true

telegramAdminDisconnected:
handler: notify.adminDisconnected
environment:
MSG_ADMIN_DISCONNECTED: ${env:MSG_ADMIN_DISCONNECTED}
events:
- iot:
sql: "SELECT * FROM 'modem-admin-disconnected'"
enabled: true

telegramCommand:
handler: command.elaborateCommand
environment:
Expand Down

0 comments on commit 3d7ddb9

Please sign in to comment.