homebridge-plugins / node-arlo Goto Github PK
View Code? Open in Web Editor NEWJS library for Arlo Cameras
JS library for Arlo Cameras
Describe The Bug:
Unable to serialise the device classes.
To Reproduce:
JSON.stringify(device)
Expected behavior:
Serialise device to JSON.
Logs:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'ArloBaseStation'
| property 'parent' -> object with constructor 'Arlo'
| property 'devices' -> object with constructor 'Object'
Environment:
In client.ts chunk is buffer it is not a string so the code below errors out. Also the regex results in a JSON string that is not properly formatted see suggested changes at bottom.
response.message.addListener('data', (chunk) => { let data: Responses.SubscribeChunkData; try { data = JSON.parse(chunk.replace(/^event:\s*/, '"event": "').replace(/\s*data:\s*/, '", "data": ')).data; } catch (error) { throw new Error(error); }
Changing FROM
data = JSON.parse(chunk.replace(/^event:\s*/, '"event": "').replace(/\s*data:\s*/, '", "data": ')).data;
TO
data = JSON.parse(chunk.toString().trimEnd().replace(/^event:\s*/, '{"event": "').replace(/\s*data:\s*/, '", "data": ').concat('}'));
Is your feature request related to a problem? Please describe.
Function Arlo.getDevices() emits event EVENT_GOT_DEVICES, but the constant is not accessible to clients. Clients have to use the string literal directly in order to catch the event.
Describe the solution you'd like
Constant Constants.EVENT_GOT_DEVICES
should be exposed to clients.
Is your feature request related to a problem? Please describe.
Currently properties like basestation mode, camera battery level and charging state are only provided via event notification when the values actually change. The values cannot be queried on demand.
Describe the solution you'd like
Add possibility to query these values on demand or internally query and cache the initial values and notify the cached values when subscribing for a certain event.
@EpicKris, would you move this back over also?
Hey, I am using node-red-contrib-arlo which I uses this library.
I wrote https://flows.nodered.org/node/node-red-contrib-alarm which acts as a node-red powered alarm panel. You hook up various sensors to it and sirens and it is your alarm panel. Hue Motion Sensors, zwave door sensors, arlo camera motion, etc can all act as sensors.
I would like to see if I can use the siren in the Arlo base station as the siren for the node-red powered alarm system.
This golang library provides SirenOn/SirenOff commands, so it shouldn't be too hard to figure out how:
https://github.com/jeffreydwalter/arlo/wiki/API-Documentation
Really, I would like to basically trigger an "entrance delay" style "pip, pip" alert and then a full blown internal siren, or just an internal siren if that's the best we can do. But surely they have a warning mode as well as a full blast?
Thoughts?
@EpicKris, Just wondering if you are going to continue to work on this or if you want to transfer ownership back?
Haven’t seen any movement that’s why I am asking
Hello,
I am the recent owner of an Arlo camera and came to your package out of curiosity to see how I could take advantage of it with code.
Unfortunately there is no documentation at all for how to use your package, which is too bad, especially since it seems that you put a lot of effort to write clean code and maintain it.
Do you want to add documentation at some point?
Arlo just introduced 2 factor authentication.
Old authentication API still works for accounts with 2FA disabled, but enabling 2FA would be a great security improvement.
Thank you in advance.
Regards.
What type of license are we allowed to use this in for commercial and private use?
Not sure if I'm posting this correctly didn't see how to associate it with the Beta which issues are expected....
Problem / Bug overall is not able to receive event notifications will post a support request with my code looking for advice as I may not interacting with node-arlo correctly however by inspection I found a few issues the below being one
In the Beta branch the basestation.ts has action: Resources.NotifyAction.GET, when it should be SET see Master ArloBaseStation.js, or pyhton version https://github.com/jeffreydwalter/arlo, or HAR from web client. The 30s heartbeat for notify is a SET action
async subscribe(): Promise<boolean> { let notify: boolean | null; try { notify = await this.client.createNotify(this.data.deviceId, { from:
${this.data.userId}_web, to: this.data.deviceId, action: Resources.NotifyAction.GET, resource: Resources.NotifyResources.SUBSCRIPTIONS, publish: false, properties: { devices: [this.data.deviceId] } }, this.data.xCloudId); } catch (error) { throw new Error(error); } if (!notify) return false; return notify; }
Is your feature request related to a problem? Please describe.
First thing first: great job!
I'm trying to use this plugin for a personal project but it looks like accounts without MFA are not supported yet!
Describe the solution you'd like
I'd like to just provide the arloUser
and arloPassword
properties.
Additional context
For these accounts, when the _getAuthToken()
is invoked, arlo will return this response:
{
_type: 'AccessTokenV2',
token: '...mytoken...',
userId: '...myuserid...',
authenticated: 1644240464,
issued: 1644240464,
expiresIn: 1645536464,
mfa: false,
authCompleted: true,
type: 'USER',
MFA_State: 'ENABLED'
}
When mfa = false
the library should just skip the MFA validation and return true to the login()
method.
Is there some kind of sample js available on how to set this up and get camera notifications?
-jayvee
https://github.com/EpicKris/node-arlo/blob/beta/src/resources/notify.ts
line 124
SUBSCRIPTIONS = 'subsriptions'
S/B
SUBSCRIPTIONS = 'subscriptions'
Is there a way to set the mode to custom mode? I'm trying
basestation.setMode("mode2", function() {
// some code
});
mode2 is taken from the URL of the mode definition on the Arlo website.
Thanks
The Arlo Q Plus (device type "arloqs" is supported), but not Arlo Q (device type "arloq"). They're pretty much the same: https://smartrobotichome.com/arlo-q-vs-arlo-q-plus/
Not sure if I'm posting this correctly didn't see how to associate it with the Beta which issues are expected....
Problem / Bug overall is not able to receive event notifications. I will post a support request with my code looking for advice as I may not interacting with node-arlo correctly however by inspection I found a few issues the below being one
In the Beta branch client.js uses the default PersonalAccessTokenCredentialHandler implementation
{ PersonalAccessTokenCredentialHandler } from 'typed-rest-client/Handlers';
Arlo is expecting the the raw token returned from the login.
The PersonalAccessTokenCredentialHandler implements prepareRequest as:
prepareRequest(options) { options.headers['Authorization'] =
Basic ${Buffer.from(PAT:${this.token}
).toString('base64')}; options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; }
Arlo API is not expecting the token to have 'Basic ' as a prefix nor have it be base64 encoded. The work around I choose to allow me to try and get further with being able to receive notification was to override the prepareRequest function after in the client constructor adding the line
this.handler.prepareRequest = function (options) { options.headers['Authorization'] = this.token; options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; }.bind(this.handler);
client.js in Beta branch with above override of prepareRequest
constructor(userAgent = 'node-arlo', baseUrl = 'https://arlo.netgear.com/hmsweb') { this.userAgent = userAgent; this.baseUrl = baseUrl; /** * Handler. */ this.handler = new Handlers_1.PersonalAccessTokenCredentialHandler(''); this.handler.prepareRequest = function (options) { options.headers['Authorization'] = this.token; options.headers['X-TFS-FedAuthRedirect'] = 'Suppress'; }.bind(this.handler); this.restClient = new typed_rest_client_1.RestClient(userAgent, baseUrl, [this.handler]); }
Related to Issue #24
Header winds up with two values for Authorization which is rejected as invalid and the response error is caught in client.js getDevices catch(error)
{ statusCode: 401, result: { data: { error: "1022", message: "Access token is invalid.", reason: "Access token is invalid", }, success: false, }, }
Inspecting the raw header of the request for getDevices there are two authorization tokens apparently the one the is in the wrong format see issue #24 is the one being used by the server.
{ authorization: "21JthtSu2f4gEsGmbFFRXKza5k73Ihq_DUCj1L7G-8YrRZGq7bjdP077XYWwqN0GsOEF17xE2FAfsbo0Ih2C60IoWEFA_5tOSqZtKVYkSFJafww02TWYb0FTRFWb17EaN0dfYbNjfHz__WPLFTkLJcRMFg_LEn3Wh3byqniiiqfSi", accept: "application/json", "user-agent": "node-arlo", Authorization: "Basic UAFUOjJfNUp0aHRTdTJmNGdFc0dtYkZGUlhLemE1azczSWhxG0RVQ2oxTDdHLThZclJaR3E3YmpkUDA3NzRZ03dxTjBHc09FRjE3eEUyRkRmc2JvMElxMkM2MElvV0VIQV81dE9TcVp0S1ZZa1NGSmFmd3cwMlRXWWIwRlRJRldiMTdFYU4wZGZZ5k5qZkh6X19XQExiVGtMSmNSTUZnX0xFbjNXaDNieXFuaWlpcWZTaQ==", "X-TFS-FedAuthRedirect": "Suppress", }
I suspect the addtionalHeaders options below is intended to override the authorization token the PersonalAccessTokenCredentialHandler is creating??? This isn't working also would expect the authorization token is needed for more than just get devices the current web api uses the token for many of the requests depending upon the resolution of #24 the need for addtionalHeaders may go away?
/** * Get devices. */ async getDevices() { let response; try { let options = { additionalHeaders: { Authorization: this.handler.token } }; response = await this.restClient.get('users/devices', options); } catch (error) { throw new Error(error); } return response.result; }
Hello,
could you please provide a simple example for listening for motion events?
I tried to listen on 'statusUpdate', but this did not work. Thank you!
Is your feature request related to a problem? Please describe.
Currently mode change notifications use the mode name as event name. This means clients need to subscribe for every possible mode in order to be notified about their activation.
Describe the solution you'd like
Emit a general mode change event when the mode has changed and pass the activated mode as additional argument to the event.
When emitting mode change events, the incorrect parameter is sourced from the arlo event. The parameter name should be 'activeMode'.
Anyone have an example that works for subscribing to events? The below authorizes the subscription returns with {"event":"message","data":{"status":"connected"}} and getDevices returns with all the devices.... but that's it Notify returning status code 200 saying it's all good but it's not. No events are coming across and when I login to arlo using that same username and password I should see a logout event and that doesn't occur either. Either I'm doing something wrong ( very likely ) or the way node-arlo is handling the Server Side Event connection is not correct.
Below is code used with the Beta branch I was also not successful with the master at getting subscribed events working.
`async function sleep(milliseconds) {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
var Arlo = require('node-arlo').Arlo;
const Responses = require('node-arlo').Responses
arlo = new Arlo();
arlo.addListener('login', function (data) {
console.log('Login ' + JSON.stringify(data))
});
arlo.addListener('cameras', function (data) {
console.log('Camera ' + JSON.stringify(data))
});
arlo.addListener('found', function (data) {
console.log('Found ' + JSON.stringify(data))
});
arlo.addListener('action', function (data) {
console.log('action ' + JSON.stringify(data))
});
arlo.addListener('status', function (data) {
console.log('status ' + JSON.stringify(data))
});
arlo.addListener('default', function (data) {
console.log('default ' + JSON.stringify(data))
});
async function init() {
try {
await arlo.login('[email protected]', 'supersecretpasswd');
data = await arlo.getDevices();
let sub = await arlo.subscribe(); //returns a new subscription object not sure if events will show here or on arlo object listner above
sub.addListener('default', function (data) {
console.log('Arlo Subscribe default ' + JSON.stringify(data))
});
while(true){
result = await arlo.devices["5R05997AA9EBD"].subscribe(); //my base station id
console.log('Notify Done ' + result);
await sleep(20*1000);
}
} catch (err) {
console.log(err);
}
};`
This is great code for a very tricky API - I'm tinkering with it here https://glitch.com/edit/#!/rootshiregarden , with the goal of adding the missing timelapse feature to my Arlo setup ;) I'm finding that sometimes arlo.devices is not "filled" depending on how quickly I call .devices after login. One thing that would be helpful (I think, correct me if I'm using it incorrectly) is a callback on login and ensuring callback gets called in getdevices. This would allow us to be sure getdevices has completed before continuing :
arlo.login(username,password,function(err,res,data){ if(!err) doStuffWithDevices(arlo.devices); })
I think this would be a matter of changing line 54 of Arlo.js to login(username,password, callback) and adding this in getDevices around line 49 and 66:
if (callback) callback(err,res,data);
I think this wouldn't break any existing code that works. I can try to do a PR if you'd like.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.