This is a Node.js module available through the npm registry.
$ npm i -S locam
const Camera = require('locam');
const c = new Camera({
auth: {
username: process.env.USERNAME,
password: process.env.PASSWORD
},
camera: {
ip: '10.0.0.2',
port: 10443,
name: 'Camera_Name'
},
logging: true
});
// Get Camera Info
c.send(c.Status.info('get')).then(d => {
console.log(d);
}).catch(err => {
console.error(error);
});
// Move to Preset 2
c.send(c.Actions.preset('set', 2)).then(d => {
console.log(d);
}).catch(err => {
console.error(error);
});
// Enable Motion Tracking
c.send(c.Settings.motionTracking('set', true)).then(d => {
console.log(d);
}).catch(err => {
console.error(error);
});
// Get Night Vision Setting
c.send(c.Settings.nightVision('get')).then(d => {
console.log(d);
}).catch(err => {
console.error(error);
});
// --- Alternative Structure ---
// Define command once as vars and use vars in code
const nightVisionOff = c.Settings.nightVision('set', 'day');
const disableMotionTracking = c.Settings.motionTracking('set', false);
// ...
await c.send(nightVisionOff);
// ...
await c.send(disableMotionTracking);
// ...
- Provides access to the majority of functionality and settings
- Can send additional commands that are not included in this library
- Easy integration into other projects (custom dashboards, automations, monitoring, logging, etc)
- Should not be considered 'production ready' or used in critical implementations
- Subject to unpredictable changes which can break this implementation without notice
- Some security concerns & known vulnerabilities may exist and should be reviewed prior to using the package
The current authentication approach used has some security concerns which should be reviewed and acknowledged.
The current implementation relies generating a token based on the username
& password
used for the Kasa Smart app.
It is imperative to store the values somewhere secure but accessible by your code (see env.js or .env sections for general ideas)
This file may be created to store persistant environmental variables.
This file must be added .gitignore
& never published. See security concerns for more details.
Example of storing information in this file:
module.exports = {
username: 'user',
password: 'pass'
}
Example of getting information from this file:
const {username, password} = require('./env.js');
console.log(username, password);
This is a commonly used way to store persistant environmental variables.
In your code, you can use the dotenv package to access the stored values at runtime.
This file must be added .gitignore
& never published. See security concerns for more details.
Example of storing information in this file:
USERNAME=user
PASSWORD=pass
Example of getting information from this file:
require('dotenv').config()
console.log(process.env.USERNAME, process.env.PASSWORD);
- Get or set the state of the camera power
- type:
'get'
or'set'
- enable: bool
- Get or set the state of the local 24/7 recording
- type:
'get'
or'set'
- enable: bool
- Get or set the state of motion detection
- type:
'get'
or'set'
- enable: bool
- Get or set the level the sensitivity of motion detection
- type:
'get'
or'set'
- sensitivity:
'low'
,'medium'
,'high'
- Get or set the state of min duration of motion required
- type:
'get'
or'set'
- dayTime: integer
- milliseconds
- nightTime: integer
- milliseconds
- Get or set the state of baby crying detection
- type:
'get'
or'set'
- enable: bool
- Get or set the state of person detection
- type:
'get'
or'set'
- enable: bool
- Get or set the state of audio recording
- type:
'get'
or'set'
- enable: bool
- Get or set the state of audio detection
- type:
'get'
or'set'
- enable: bool
- Get or set the level the sensitivity of audio detection
- type:
'get'
or'set'
- sensitivity:
'low'
,'medium'
,'high'
- Get or set the state of motion tracking
- type:
'get'
or'set'
- enable: bool
- Get or set the state of camera patrolling
- type:
'get'
or'set'
- enable: bool
- Format the SD card
- type:
'set'
- Get or set the resolution
- type:
'get'
or'set'
- resolution:
'2560x1440'
,'1920x1080'
,'1280x720'
- Get or set the state of image rotation
- type:
'get'
or'set'
- degree:
0
or180
- Get or set the state of infrared lights
- type:
'get'
or'set'
- state:
'auto'
,'day'
,'night'
- day = always off
- night = always on
- Get or set the state of the camera LED
- type:
'get'
or'set'
- enable: bool
- Get or set the state of do not disturb
- type:
'get'
or'set'
- enable: bool
- Get or set the time of the camera
- type:
'get'
or'set'
- time: integer
- epoch time
- Get or set the timezone of the camera
- type:
'get'
or'set'
- timezone: string
'UTC-05:00'
- area: string
'America/New_York'
- Move camera to a preset location
- type:
'set'
- num:
1
,2
,3
,4
- Move the camera in a direction
- type:
'set'
- dir:
'left'
,'up'
,'right'
,'down'
- speed: integer
- Get or set the current position of the camera
- type:
'get'
or'set'
- x: integer
- y: integer
- Stop the camera from moving
- type:
'set'
Not implemented yet
- Get the live stream of the camera
- Display in a window or return the buffer
- type:
'get'
- view: boolean
Not implemented yet
- Save the live stream of the camera to a file
- type:
'get'
- seconds: integer
Not implemented yet
- Restream the live stream of the camera in another format
- type:
'get'
- format:
'hls'
or'rtmp'
Not implemented yet
- Get the VOD recording stream of the camera
- Display in a window or return the buffer
- type:
'get'
- view: boolean
Not implemented yet
- Send an audio stream to the camera speaker
- type:
'set'
- audioStream: buffer
- Get the link to the latest camera thumbnail image
- type:
'get'
- Get the events detected by the camera within the time window specified
- type:
'get'
- startTime: integer
- epoch time
- endTime: integer
- epoch time
- Generic information about the camera
- type:
'get'
- Information about the SD card
- type:
'get'
- Information about the SD card encryption
- type:
'get'
- Information about the connection to the cloud servers
- type:
'get'
- Complete time configuration of the device
- type:
'get'
- List of stored preset locations
- type:
'get'
- Get basic information about the VOD status
- type:
'get'
- playerId:
'abc123'
Stephen Mendez
- Website: https://www.stephenmendez.dev
- Twitter: @stephenmendez_
- Github: @401unauthorized
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a ⭐️ if this project helped you!
Consider making a donation of any amount!
Copyright © 2021 Stephen Mendez
This project is MIT licensed.
Kasa is a registered trademark of TP-LINK Research America Corporation.
Part of this README was generated with ❤️ by readme-md-generator