diff --git a/MyCore/Services/ArloService.cs b/MyCore/Services/ArloService.cs index 887edf6..b40d0b7 100644 --- a/MyCore/Services/ArloService.cs +++ b/MyCore/Services/ArloService.cs @@ -70,6 +70,30 @@ namespace MyCore.Services public long dateCreated; } + // Motion Detection Test - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"motionSetupModeEnabled":true,"motionSetupModeSensitivity":80}} + + public class MotionDetection + { + public string from; + public string to; + public string action; + public string resource; + public string transId; + public bool publishResponse = true; + public PropertiesRequestMotionSubscription properties; + } + + public class PropertiesRequest + { + public bool motionSetupModeEnabled; + public int motionSetupModeSensitivity; + } + + public class PropertiesRequestMotionSubscription + { + public string[] devices; + } + public enum RequestType { Get, @@ -194,9 +218,56 @@ namespace MyCore.Services var evt = new EventSourceReader(new Uri($"{_clientSubscribeUrl}?token={resultToken.token}")).Start(); evt.MessageReceived += - (object sender, EventSourceMessageEventArgs e) - => - Console.WriteLine($"{e.Event} : {e.Message}"); + async (object sender, EventSourceMessageEventArgs e) + => + { + using (var client = new HttpClient()) + { + ArloDevice baseStation = allArloDevices.Where(d => d.deviceType == "basestation").FirstOrDefault(); + ArloDevice camera = allArloDevices.Where(d => d.deviceType == "camera").FirstOrDefault(); + + Console.WriteLine($"{e.Event} : {e.Message}"); + + // ask for motion event test + //Motion Detection Test - { "from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{ "motionSetupModeEnabled":true,"motionSetupModeSensitivity":80} } + /*MotionDetection motionDetection = new MotionDetection(); + motionDetection.from = $"{baseStation.userId}_web"; + motionDetection.to = $"{baseStation.deviceId}"; + motionDetection.action = "set"; + motionDetection.resource = $"cameras/{camera.deviceId}"; + motionDetection.transId = $"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX"; + motionDetection.publishResponse = true; + PropertiesRequest propertiesRequest = new PropertiesRequest(); + propertiesRequest.motionSetupModeEnabled = true; + propertiesRequest.motionSetupModeSensitivity = 80; + motionDetection.properties = propertiesRequest; + + var body = JsonConvert.SerializeObject(motionDetection).ToString();*/ + + // Try to subscribe to motion for camera + /*MotionDetection motionDetection = new MotionDetection(); + motionDetection.from = $"{baseStation.userId}_web"; + motionDetection.to = $"{baseStation.deviceId}"; + motionDetection.action = "set"; + motionDetection.resource = $"subscriptions/{baseStation.userId}_web"; + motionDetection.transId = $"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX"; + motionDetection.publishResponse = false; + PropertiesRequestMotionSubscription propertiesRequestMotionSubscription = new PropertiesRequestMotionSubscription(); + propertiesRequestMotionSubscription.devices = new string[] { camera.deviceId }; + motionDetection.properties = propertiesRequestMotionSubscription; + + var body = JsonConvert.SerializeObject(motionDetection).ToString(); + + HttpContent c = new StringContent(body, Encoding.UTF8, "application/json"); + client.DefaultRequestHeaders.Add("xcloudId", baseStation.xCloudId); + client.DefaultRequestHeaders.Add("Authorization", resultToken.token); + HttpResponseMessage result = await client.PostAsync($"{ _userDevicesNotifyUrl}/{baseStation.deviceId}", c); + if (result.IsSuccessStatusCode) + { + var response = await result.Content.ReadAsStringAsync(); + }*/ + } + }; evt.Disconnected += async (object sender, DisconnectEventArgs e) => { Console.WriteLine($"Retry: {e.ReconnectDelay} - Error: {e.Exception}"); await Task.Delay(e.ReconnectDelay); diff --git a/RPI Code/Arlo/FUNDING.yml b/RPI Code/Arlo/FUNDING.yml new file mode 100644 index 0000000..61da9c3 --- /dev/null +++ b/RPI Code/Arlo/FUNDING.yml @@ -0,0 +1,9 @@ +# These are supported funding model platforms + +github: [jeffreydwalter] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +custom: # Replace with a single custom sponsorship URL diff --git a/RPI Code/Arlo/ISSUE_TEMPLATE.md b/RPI Code/Arlo/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..0071113 --- /dev/null +++ b/RPI Code/Arlo/ISSUE_TEMPLATE.md @@ -0,0 +1,43 @@ +Please answer these questions before submitting your issue. Thanks! + + +### What version of Python are you using (`python -V`)? + + +### What operating system and processor architecture are you using (`python -c 'import platform; print(platform.uname());'`)? + + +### Which Python packages do you have installed (run the `pip freeze` or `pip3 freeze` command and paste output)? +``` +Paste your ouptut here +``` + +### Which version of ffmpeg are you using (`ffmpeg -version`)? +``` +Paste your output here +``` + +### Which Arlo hardware do you have (camera types - [Arlo, Pro, Q, etc.], basestation model, etc.)? + + +### What did you do? + +If possible, provide the steps you took to reproduce the issue. +A complete runnable program is good. (don't include your user/password or any sensitive info) +``` +Paste your ouptut here +``` + +### What did you expect to see? +``` +Paste your ouptut here +``` + +### What did you see instead? +``` +Paste your ouptut here +``` + +### Does this issue reproduce with the latest release? + + diff --git a/RPI Code/Arlo/LICENSE b/RPI Code/Arlo/LICENSE new file mode 100644 index 0000000..8dada3e --- /dev/null +++ b/RPI Code/Arlo/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/RPI Code/Arlo/Makefile b/RPI Code/Arlo/Makefile new file mode 100644 index 0000000..8ba1fa2 --- /dev/null +++ b/RPI Code/Arlo/Makefile @@ -0,0 +1,48 @@ +#red:=$(shell tput setaf 1) +#reset:=$(shell tput sgr0) + +init: + pip install -r requirements.txt + +clean: + rm -rf *.pyc + rm -rf dist + rm -rf build + rm -rf __pycache__ + rm -rf arlo.egg-info + +doc: + #pydoc -w ../arlo/arlo.py + #mv arlo.html arlo_api_doc.md + #git add arlo_api_doc.md + pdoc --overwrite --html --html-no-source --html-dir docs arlo.py + sed -i'.bak' 's/#sidebar{width:30%}#content{width:70%;/#sidebar{width:45%}#content{width:55%;/g' docs/arlo.html + rm docs/arlo.html.bak + python dev/html2text.py docs/arlo.html > docs/README.md + git add docs/* + +rev: + python dev/rev.py setup.py + git add setup.py + +commit: +ifndef message + $(error "Error: commit message required. Usage: make $(MAKECMDGOALS) message=''") +endif + + git add Makefile + + git add dev/* + + git add arlo.py + git add request.py + git add eventstream.py + git add requirements.txt + + git commit -m "$(message)" + git push + +release: clean rev doc commit + python3 setup.py sdist + python3 setup.py bdist_wheel --universal + twine upload --skip-existing dist/* diff --git a/RPI Code/Arlo/README.md b/RPI Code/Arlo/README.md new file mode 100644 index 0000000..db0b0c2 --- /dev/null +++ b/RPI Code/Arlo/README.md @@ -0,0 +1,134 @@ +![](logo.png) +# arlo ![](https://img.shields.io/badge/python-2.7%2C%203.4%2C%203.5%2C%203.6-blue.svg) +> Python module for interacting with Netgear's Arlo camera system. +> +>### Now in Golang! +>If you love the Go programming language, check out [arlo-golang](https://github.com/jeffreydwalter/arlo-golang). +>My goal is to bring parity to the Python version asap. If you know what you're doing in Go, I would appreciate any feedback on the >general structure of the library, and contributions, etc. + +--- +### GETTING STARTED +Check out the [API DOCS](https://github.com/jeffreydwalter/arlo/tree/master/docs) + +**IMPORTANT:** There is a regression in `sseclient 0.0.24` that breaks this package. Please ensure you have `seeclient 0.0.22` installed. + +**IMPORTANT:** Please ensure you don't have ANY other `sseclient` packages installed in addition to `sseclient 0.0.22`! This may cause this package to fail in unexpected ways. A common one that is known to cause issues is the `sseclient-py 1.7` package. If you have a hard requirement to have more than one, please let me know and we can look into making that work. + +**IMPORTANT:** my.arlo.com requires TLS 1.2 for their API. So, if you're getting ssl errors, it's most likely related to your version of openssl. You may need to upgrade your openssl library. +If you're running this library on OSX or macOS, they ship with `openssl v0.9.x` which does not support TLS 1.2. You should follow the instructions found [here](https://comeroutewithme.com/2016/03/13/python-osx-openssl-issue/) to upgrade your openssl library. + +--- +### Filing an Issue +Please read the [Issue Guidelines and Policies](https://github.com/jeffreydwalter/arlo/wiki/Issue-Guidelines-and-Policies) wiki page **BEFORE** you file an issue. Thanks. + +--- +## Install +```bash +# Install latest stable package +$ pip install arlo + +--or-- + +# Install from master branch +$ pip install git+https://github.com/jeffreydwalter/arlo +``` + +--- +This just a personal utility that I created out of necessity. It is by no means complete, although it does expose quite a bit of the Arlo interface in an easy to use Python pacakge. As such, this package does not come with unit tests (feel free to add them) or guarantees. +**All [contributions](https://github.com/jeffreydwalter/arlo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) are welcome and appreciated!** +-- +**If you have a specific Arlo device that you want to improve support for, please consider sending me one! Since this project is solely maintained by yours truely and I don't have unlimited funds to support it, I can only really test and debug the code with the first gen Arlo cameras and basestation that I have. I also highly encourage and appreciate Pull Requests!** + +**Please, feel free to [contribute](https://github.com/jeffreydwalter/arlo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) to this repo or buy Jeff a beer!** [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=R77B7UXMLA6ML&lc=US&item_name=Jeff%20Needs%20Beer&item_number=buyjeffabeer¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) + +--- +### Generous Benefactors (Thank you!) +* [apsteinmetz](https://github.com/apsteinmetz) - 🍺 +* [mhallikainen](https://github.com/mhallikainen) - 🍺🍺 +* [tinsheep](https://github.com/tinsheep) - 🍺🍺 +* [cubewot](https://github.com/cubewot) - 🍺🍺 +* [imopen](https://github.com/imopen) - 🍺 +* [notalifeform](https://github.com/notalifeform) - 🍺🍺 +* [anonymous](https://github.com/jeffreydwalter/arlo) - 🍺🍺🍺🍺 +* [kewashi](https://github.com/kewashi) - 🍺 + +--- +### Awesomely Smart Contributors (Thank you!) +* [alvin-chang](https://github.com/alvin-chang) - Dec 15, 2019 - Updated some print statements to work with Python 3 in an example script. +* [pabloNZ](https://github.com/pabloNZ) - Jun 4, 2019 - Added the Arlo doorbell, Ultra camera and basestation schemas to the wiki. +* [m3ntalsp00n](https://github.com/m3ntalsp00n) - May 18, 2019 - Expanded ArloQ device support. +* [burken-](https://github.com/burken-) - Apr 17, 2019 - Fixed arming/disarming ArloQ devices. +* [m0urs](https://github.com/m0urs) - Apr 16, 2019 - Updated fqdn to new Arlo domain. +* [kimc78](https://github.com/kimc78) - Aug 16, 2018 - Added method to get CVR recording list. +* [jurgenweber](https://github.com/jurgenweber) - Apr 25, 2018 - Added Arlo Baby APIs! +* [pliablepixels](https://github.com/pliablepixels) - Apr 3, 2018 - Fixed up issues with the README. +* [manluk](https://github.com/manluk) - Mar 2, 2018 - Squashed a couple of bugs. +* [notalifeform](https://github.com/notalifeform) - Feb 10, 2018 - Fixed bug and formatting in example script. +* [erosen](https://github.com/erosen) - Jan 27, 2018 - Added the ArloQ camera schema to the wiki. +* [deanmcguire](https://github.com/deanmcguire) - Dec 7, 2017 - Unravelled the mysteries of RTSP streaming video. +* [andijakl](https://github.com/andijakl) - Jul 24, 2017 - Added Python 3 support and cleaned up examples. +* [cemeyer2](https://github.com/cemeyer2) - Nov 26, 2016 - Fixed setup issues. +* [LenShustek](https://github.com/LenShustek) - Sep 14, 2016, - Added Logout(). + +If You'd like to make a diffrence in the world and get your name on this most prestegious list, have a look at our [help wanted](https://github.com/jeffreydwalter/arlo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) section! + +After installing all of the required libraries, you can import and use this library like so: + +```python +from arlo import Arlo + +from datetime import timedelta, date +import datetime +import sys + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + today = (date.today()-timedelta(days=0)).strftime("%Y%m%d") + seven_days_ago = (date.today()-timedelta(days=7)).strftime("%Y%m%d") + + # Get all of the recordings for a date range. + library = arlo.GetLibrary(seven_days_ago, today) + + # Iterate through the recordings in the library. + for recording in library: + + videofilename = datetime.datetime.fromtimestamp(int(recording['name'])//1000).strftime('%Y-%m-%d %H-%M-%S') + ' ' + recording['uniqueId'] + '.mp4' + ## + # The videos produced by Arlo are pretty small, even in their longest, best quality settings, + # but you should probably prefer the chunked stream (see below). + ### + # # Download the whole video into memory as a single chunk. + # video = arlo.GetRecording(recording['presignedContentUrl']) + # with open('videos/'+videofilename, 'wb') as f: + # f.write(video) + # f.close() + # Or: + # + # Get video as a chunked stream; this function returns a generator. + stream = arlo.StreamRecording(recording['presignedContentUrl']) + with open('videos/'+videofilename, 'wb') as f: + for chunk in stream: + f.write(chunk) + f.close() + + print('Downloaded video '+videofilename+' from '+recording['createdDate']+'.') + + # Delete all of the videos you just downloaded from the Arlo library. + # Notice that you can pass the "library" object we got back from the GetLibrary() call. + result = arlo.BatchDeleteRecordings(library) + + # If we made it here without an exception, then the videos were successfully deleted. + print('Batch deletion of videos completed successfully.') + +except Exception as e: + print(e) +``` + +**For more code examples check out the [wiki](https://github.com/jeffreydwalter/arlo/wiki)** diff --git a/RPI Code/Arlo/__pycache__/arlo.cpython-37.pyc b/RPI Code/Arlo/__pycache__/arlo.cpython-37.pyc new file mode 100644 index 0000000..39ccdfb Binary files /dev/null and b/RPI Code/Arlo/__pycache__/arlo.cpython-37.pyc differ diff --git a/RPI Code/Arlo/__pycache__/eventstream.cpython-37.pyc b/RPI Code/Arlo/__pycache__/eventstream.cpython-37.pyc new file mode 100644 index 0000000..f153fe2 Binary files /dev/null and b/RPI Code/Arlo/__pycache__/eventstream.cpython-37.pyc differ diff --git a/RPI Code/Arlo/__pycache__/request.cpython-37.pyc b/RPI Code/Arlo/__pycache__/request.cpython-37.pyc new file mode 100644 index 0000000..9b6a967 Binary files /dev/null and b/RPI Code/Arlo/__pycache__/request.cpython-37.pyc differ diff --git a/RPI Code/Arlo/_config.yml b/RPI Code/Arlo/_config.yml new file mode 100644 index 0000000..3397c9a --- /dev/null +++ b/RPI Code/Arlo/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-architect \ No newline at end of file diff --git a/RPI Code/Arlo/arlo-motiondetect.py b/RPI Code/Arlo/arlo-motiondetect.py new file mode 100644 index 0000000..712dc89 --- /dev/null +++ b/RPI Code/Arlo/arlo-motiondetect.py @@ -0,0 +1,40 @@ +import paho.mqtt.client as mqtt +from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' +broker="192.168.31.140" + +mqttc = mqtt.Client("Hassio_Arlo") +mqttc.username_pw_set("mqtt", "mqtt") +mqttc.connect(broker, 1883) + +try: + + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + cameras = arlo.GetDevices('camera') + # Define a callback function that will get called once for each motion event. + def callback(arlo, event): + # Here you will have access to self, basestation_id, xcloud_id, and the event schema. + print("motion event detected!") + print(event) + print(arlo) + print("try to send via mqtt") + mqttc.publish("Arlo", "motion event detected!") + #print("try to take snapshot") + #snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]) + #arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg') + + #print(basestations) + + # Subscribe to motion events. This method blocks until the event stream is closed. (You can close the event stream in the callback if you no longer want to listen for events.) + arlo.SubscribeToMotionEvents(basestations[0], callback) +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/arlo-snapshot.py b/RPI Code/Arlo/arlo-snapshot.py new file mode 100644 index 0000000..95f3374 --- /dev/null +++ b/RPI Code/Arlo/arlo-snapshot.py @@ -0,0 +1,44 @@ +from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the cameras. + # This will return an array of cameras, including all of the cameras' associated metadata. + cameras = arlo.GetDevices('camera') + + # Trigger the snapshot. + url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]); + + # Download snapshot. + arlo.DownloadSnapshot(url, 'snapshot.jpg') + + # If you are already recording, or have a need to snapshot while recording, you can do so like this: + """ + # Starting recording with a camera. + arlo.StartRecording(basestations[0], cameras[0]); + + # Wait for 4 seconds while the camera records. (There are probably better ways to do this, but you get the idea.) + time.sleep(4) + + # Trigger the snapshot. + url = arlo.TriggerStreamSnapshot(basestations[0], cameras[0]); + + # Download snapshot. + arlo.DownloadSnapshot(url, 'snapshot.jpg') + + # Stop recording. + arlo.StopRecording(cameras[0]); + """ +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/arlo.py b/RPI Code/Arlo/arlo.py new file mode 100644 index 0000000..22c3266 --- /dev/null +++ b/RPI Code/Arlo/arlo.py @@ -0,0 +1,1533 @@ +""" +Copyright 2016 Jeffrey D. Walter + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS ISBASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +# 14 Sep 2016, Len Shustek: Added Logout() +# 17 Jul 2017, Andreas Jakl: Port to Python 3 (https://www.andreasjakl.com/using-netgear-arlo-security-cameras-for-periodic-recording/) + +# Import helper classes that are part of this library. +from request import Request +from eventstream import EventStream + +# Import all of the other stuff. +from six import string_types, text_type +from datetime import datetime + +import calendar +import json +#import logging +import math +import os +import random +import requests +import signal +import time +import sys + +if sys.version[0] == '2': + import Queue as queue +else: + import queue as queue + +#logging.basicConfig(level=logging.DEBUG,format='[%(levelname)s] (%(threadName)-10s) %(message)s',) + +class Arlo(object): + TRANSID_PREFIX = 'web' + def __init__(self, username, password): + + # signals only work in main thread + try: + signal.signal(signal.SIGINT, self.interrupt_handler) + except: + pass + + self.event_streams = {} + self.request = None + + self.Login(username, password) + + def interrupt_handler(self, signum, frame): + print("Caught Ctrl-C, exiting.") + os._exit(1) + + def to_timestamp(self, dt): + if sys.version[0] == '2': + epoch = datetime.utcfromtimestamp(0) + return int((dt - epoch).total_seconds() * 1e3) + else: + return int(dt.timestamp() * 1e3) + + def genTransId(self, trans_type=TRANSID_PREFIX): + def float2hex(f): + MAXHEXADECIMALS = 15 + w = f // 1 + d = f % 1 + + # Do the whole: + if w == 0: result = '0' + else: result = '' + while w: + w, r = divmod(w, 16) + r = int(r) + if r > 9: r = chr(r+55) + else: r = str(r) + result = r + result + + # And now the part: + if d == 0: return result + + result += '.' + count = 0 + while d: + d = d * 16 + w, d = divmod(d, 1) + w = int(w) + if w > 9: w = chr(w+55) + else: w = str(w) + result += w + count += 1 + if count > MAXHEXADECIMALS: break + + return result + + now = datetime.today() + return trans_type+"!" + float2hex(random.random() * math.pow(2, 32)).lower() + "!" + str(int((time.mktime(now.timetuple())*1e3 + now.microsecond/1e3))) + + def Login(self, username, password): + """ + This call returns the following: + { + "userId":"XXX-XXXXXXX", + "email":"user@example.com", + "token":"2_5HicFJMXXXXX-S_7IuK2EqOUHXXXXXXXXXXX1CXKWTThgU18Va_XXXXXX5S00hUafv3PV_if_Bl_rhiFsDHYwhxI3CxlVnR5f3q2XXXXXX-Wnt9F7D82uN1f4cXXXXX-FMUsWF_6tMBqwn6DpzOaIB7ciJrnr2QJyKewbQouGM6", + "paymentId":"XXXXXXXX", + "authenticated":1472961381, + "accountStatus":"registered", + "serialNumber":"XXXXXXXXXXXXX", + "countryCode":"US", + "tocUpdate":false, + "policyUpdate":false, + "validEmail":true + } + """ + self.username = username + self.password = password + + self.request = Request() + + body = self.request.post('https://my.arlo.com/hmsweb/login/v2', {'email': self.username, 'password': self.password}) + + headers = { + 'DNT': '1', + 'schemaVersion': '1', + 'Host': 'my.arlo.com', + 'Content-Type': 'application/json; charset=utf-8;', + 'Referer': 'https://my.arlo.com/', + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_1_2 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Mobile/15B202 NETGEAR/v1 (iOS Vuezone)', + 'Authorization': body['token'] + } + self.request.session.headers.update(headers) + + self.user_id = body['userId'] + return body + + def Logout(self): + event_streams = self.event_streams.copy() + for basestation_id in event_streams.keys(): + self.Unsubscribe(basestation_id) + return self.request.put('https://my.arlo.com/hmsweb/logout') + + def Subscribe(self, basestation): + """ + Arlo uses the EventStream interface in the browser to do pub/sub style messaging. + Unfortunately, this appears to be the only way Arlo communicates these messages. + + This function makes the initial GET request to /subscribe, which returns the EventStream socket. + Once we have that socket, the API requires a POST request to /notify with the "subscriptionsresource. + This call "registersthe device (which should be the basestation) so that events will be sent to the EventStream + when subsequent calls to /notify are made. + + Since this interface is asynchronous, and this is a quick and dirty hack to get this working, I'm using a thread + to listen to the EventStream. This thread puts events into a queue. Some polling is required (see NotifyAndGetResponse()) because + the event messages aren't guaranteed to be delivered in any specific order, but I wanted to maintain a synchronous style API. + + You generally shouldn't need to call Subscribe() directly, although I'm leaving it "publicfor now. + """ + basestation_id = basestation.get('deviceId') + + def Register(self): + if basestation_id in self.event_streams and self.event_streams[basestation_id].connected: + self.Notify(basestation, {"action":"set","resource":"subscriptions/"+self.user_id+"_web","publishResponse":False,"properties":{"devices":[basestation_id]}}) + event = self.event_streams[basestation_id].Get() + if event is None or self.event_streams[basestation_id].event_stream_stop_event.is_set(): + return None + elif event: + self.event_streams[basestation_id].Register() + return event + + def QueueEvents(self, event_stream, stop_event): + for event in event_stream: + if event is None or stop_event.is_set(): + return None + + response = json.loads(event.data) + if basestation_id in self.event_streams: + if self.event_streams[basestation_id].connected: + if response.get('action') == 'logout': + self.event_streams[basestation_id].Disconnect() + return None + else: + self.event_streams[basestation_id].queue.put(response) + elif response.get('status') == 'connected': + self.event_streams[basestation_id].Connect() + + def Heartbeat(self, stop_event): + while not stop_event.wait(30.0): + try: + self.Ping(basestation) + except: + pass + + if basestation_id not in self.event_streams or not self.event_streams[basestation_id].connected: + self.event_streams[basestation_id] = EventStream(QueueEvents, Heartbeat, args=(self, )) + self.event_streams[basestation_id].Start() + while not self.event_streams[basestation_id].connected and not self.event_streams[basestation_id].event_stream_stop_event.is_set(): + time.sleep(0.5) + + if not self.event_streams[basestation_id].registered: + Register(self) + + def Unsubscribe(self, basestation): + """ This method stops the EventStream subscription and removes it from the event_stream collection. """ + if isinstance(basestation, (text_type, string_types)): + basestation_id = basestation + else: + basestation_id = basestation.get('deviceId') + if basestation_id in self.event_streams: + if self.event_streams[basestation_id].connected: + self.request.get('https://my.arlo.com/hmsweb/client/unsubscribe') + self.event_streams[basestation_id].Disconnect() + + del self.event_streams[basestation_id] + + def Notify(self, basestation, body): + """ + The following are examples of the json you would need to pass in the body of the Notify() call to interact with Arlo: + + ############################################################################################################################## + ############################################################################################################################## + NOTE: While you can call Notify() directly, responses from these notify calls are sent to the EventStream (see Subscribe()), + and so it's better to use the Get/Set methods that are implemented using the NotifyAndGetResponse() method. + ############################################################################################################################## + ############################################################################################################################## + + Set System Mode (Armed, Disarmed) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"modes","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"active":"mode0"}} + Set System Mode (Calendar) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"schedule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"active":true}} + Configure The Schedule (Calendar) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"schedule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"schedule":[{"modeId":"mode0","startTime":0},{"modeId":"mode2","startTime":28800000},{"modeId":"mode0","startTime":64800000},{"modeId":"mode0","startTime":86400000},{"modeId":"mode2","startTime":115200000},{"modeId":"mode0","startTime":151200000},{"modeId":"mode0","startTime":172800000},{"modeId":"mode2","startTime":201600000},{"modeId":"mode0","startTime":237600000},{"modeId":"mode0","startTime":259200000},{"modeId":"mode2","startTime":288000000},{"modeId":"mode0","startTime":324000000},{"modeId":"mode0","startTime":345600000},{"modeId":"mode2","startTime":374400000},{"modeId":"mode0","startTime":410400000},{"modeId":"mode0","startTime":432000000},{"modeId":"mode0","startTime":518400000}]} + Create Mode - + {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"add","resource":"rules","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"name":"Record video on Camera 1 if Camera 1 detects motion","id":"ruleNew","triggers":[{"type":"pirMotionActive","deviceId":"XXXXXXXXXXXXX","sensitivity":80}],"actions":[{"deviceId":"XXXXXXXXXXXXX","type":"recordVideo","stopCondition":{"type":"timeout","timeout":15}},{"type":"sendEmailAlert","recipients":["__OWNER_EMAIL__"]},{"type":"pushNotification"}]}} + {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"add","resource":"modes","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"name":"Test","rules":["rule3"]}} + Delete Mode - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"delete","resource":"modes/mode3","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true} + Camera Off - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"privacyActive":false}} + Night Vision On - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"zoom":{"topleftx":0,"toplefty":0,"bottomrightx":1280,"bottomrighty":720},"mirror":true,"flip":true,"nightVisionMode":1,"powerSaveMode":2}} + Motion Detection Test - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"motionSetupModeEnabled":true,"motionSetupModeSensitivity":80}} + + device_id = locations.data.uniqueIds + + System Properties: ("resource":"modes") + active (string) - Mode Selection (mode2 = All Motion On, mode1 = Armed, mode0 = Disarmed, etc.) + + System Properties: ("resource":"schedule") + active (bool) - Mode Selection (true = Calendar) + + Camera Properties: ("resource":"cameras/{id}") + privacyActive (bool) - Camera On/Off + zoom (topleftx (int), toplefty (int), bottomrightx (int), bottomrighty (int)) - Camera Zoom Level + mirror (bool) - Mirror Image (left-to-right or right-to-left) + flip (bool) - Flip Image Vertically + nightVisionMode (int) - Night Mode Enabled/Disabled (1, 0) + powerSaveMode (int) - PowerSaver Mode (3 = Best Video, 2 = Optimized, 1 = Best Battery Life) + motionSetupModeEnabled (bool) - Motion Detection Setup Enabled/Disabled + motionSetupModeSensitivity (int 0-100) - Motion Detection Sensitivity + """ + basestation_id = basestation.get('deviceId') + + body['transId'] = self.genTransId() + body['from'] = self.user_id+'_web' + body['to'] = basestation_id + + print(body) + + self.request.post('https://my.arlo.com/hmsweb/users/devices/notify/'+body['to'], body, headers={"xcloudId":basestation.get('xCloudId')}) + return body.get('transId') + + def NotifyAndGetResponse(self, basestation, body, timeout=120): + basestation_id = basestation.get('deviceId') + + self.Subscribe(basestation) + + if basestation_id in self.event_streams and self.event_streams[basestation_id].connected and self.event_streams[basestation_id].registered: + transId = self.Notify(basestation, body) + + event = self.event_streams[basestation_id].Get(timeout=timeout) + if event is None or self.event_streams[basestation_id].event_stream_stop_event.is_set(): + return None + + while basestation_id in self.event_streams and self.event_streams[basestation_id].connected and self.event_streams[basestation_id].registered: + tid = event.get('transId', '') + if tid != transId: + if tid.startswith(self.TRANSID_PREFIX): + self.event_streams[basestation_id].queue.put(event) + + event = self.event_streams[basestation_id].Get(timeout=timeout) + if event is None or self.event_streams[basestation_id].event_stream_stop_event.is_set(): + return None + else: break + + return event + + def Ping(self, basestation): + basestation_id = basestation.get('deviceId') + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"subscriptions/"+self.user_id+"_web","publishResponse":False,"properties":{"devices":[basestation_id]}}) + + def SubscribeToMotionEvents(self, basestation, callback, timeout=120): + """ + Use this method to subscribe to motion events. You must provide a callback function which will get called once per motion event. + + The callback function should have the following signature: + def callback(self, event) + + This is an example of handling a specific event, in reality, you'd probably want to write a callback for HandleEvents() + that has a big switch statement in it to handle all the various events Arlo produces. + """ + def callbackwrapper(self, event): + if event.get('properties', {}).get('motionDetected'): + callback(self, event) + + self.HandleEvents(basestation, callbackwrapper, timeout) + + def HandleEvents(self, basestation, callback, timeout=120): + """ + Use this method to subscribe to the event stream and provide a callback that will be called for event event received. + This function will allow you to potentially write a callback that can handle all of the events received from the event stream. + """ + if not callable(callback): + raise Exception('The callback(self, event) should be a callable function.') + + basestation_id = basestation.get('deviceId') + + self.Subscribe(basestation) + if basestation_id in self.event_streams and self.event_streams[basestation_id].connected and self.event_streams[basestation_id].registered: + while basestation_id in self.event_streams and self.event_streams[basestation_id].connected: + event = self.event_streams[basestation_id].Get(timeout=timeout) + if event is None or self.event_streams[basestation_id].event_stream_stop_event.is_set(): + return None + + # If this event has is of resource type "subscriptions", then it's a ping reply event. + # For now, these types of events will be requeued, since they are generated in response to and expected as a reply by the Ping() method. + # HACK: Take a quick nap here to give the Ping() method's thread a chance to get the queued event. + if event.get('resource', '').startswith('subscriptions'): + self.event_streams[basestation_id].queue.put(event) + time.sleep(0.05) + else: + response = callback(self, event) + # NOTE: Not ideal, but this allows you to look for a specific event and break if you want to return it. + if response is not None: + return response + + def TriggerAndHandleEvent(self, basestation, trigger, callback, timeout=120): + """ + Use this method to subscribe to the event stream and provide a callback that will be called for event event received. + This function will allow you to potentially write a callback that can handle all of the events received from the event stream. + NOTE: Use this function if you need to run some code after subscribing to the eventstream, but before your callback to handle the events runs. + """ + if not callable(trigger): + raise Exception('The trigger(self, camera) should be a callable function.') + if not callable(callback): + raise Exception('The callback(self, event) should be a callable function.') + + self.Subscribe(basestation) + trigger(self) + + # NOTE: Calling HandleEvents() calls Subscribe() again, which basically turns into a no-op. Hackie I know, but it cleans up the code a bit. + return self.HandleEvents(basestation, callback, timeout) + + def GetBaseStationState(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"basestation","publishResponse":False}) + + def GetCameraState(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"cameras","publishResponse":False}) + + def GetRules(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"rules","publishResponse":False}) + + def GetSmartFeatures(self): + return self.request.get('https://my.arlo.com/hmsweb/users/subscription/smart/features') + + def GetSmartAlerts(self, camera): + return self.request.get('https://my.arlo.com/hmsweb/users/devices/'+camera.get('uniqueId')+'/smartalerts') + + def GetAutomationActivityZones(self, camera): + return self.request.get('https://my.arlo.com/hmsweb/users/devices/'+camera.get('uniqueId')+'/activityzones') + + def RestartBasestation(self, basestation): + return self.request.post('https://my.arlo.com/hmsweb/users/devices/restart', {"deviceId":basestation.get('deviceId')}) + + def SetAutomationActivityZones(self, camera, zone, coords, color): + """ + An activity zone is the area you draw in your video in the UI to tell Arlo what part of the scene to "watch". + This method takes 4 arguments. + camera: the camera you want to set an activity zone for. + name: "Zone 1" - the name of your activity zone. + coords: [{"x":0.37946943483275664,"y":0.3790983606557377},{"x":0.8685121107266436,"y":0.3790983606557377},{"x":0.8685121107266436,"y":1},{"x":0.37946943483275664,"y":1}] - these coordinates are the bonding box for the activity zone. + color: 45136 - the color for your bounding box. + """ + return self.request.post('https://my.arlo.com/hmsweb/users/devices/'+camera.get('uniqueId')+'/activityzones', {"name": zone,"coords": coords, "color": color}) + + def GetAutomationDefinitions(self): + return self.request.get('https://my.arlo.com/hmsweb/users/automation/definitions', {'uniqueIds':'all'}) + + def GetCalendar(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"schedule","publishResponse":False}) + + def DeleteMode(self, device, mode): + """ device can be any object that has parentId == deviceId. i.e., not a camera """ + parentId = device.get('parentId', None) + if device['deviceType'] == 'arlobridge': + return self.request.delete('https://my.arlo.com/hmsweb/users/locations/'+device.get('uniqueId')+'/modes/'+mode) + elif not parentId or device.get('deviceId') == parentId: + return self.NotifyAndGetResponse(basestation, {"action":"delete","resource":"modes/"+mode,"publishResponse":True}) + else: + raise Exception('Only parent device modes and schedules can be deleted.'); + + def GetModes(self, basestation): + """ DEPRECATED: This is the older API for getting the "mode". It still works, but GetModesV2 is the way the Arlo software does it these days. """ + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"modes","publishResponse":False}) + + def GetModesV2(self): + """ + This is the newer API for getting the "mode". This method also returns the schedules. + Set a non-schedule mode to be active: {"activeAutomations":[{"deviceId":"XXXXXXXXXXXXX","timestamp":1532015622105,"activeModes":["mode1"],"activeSchedules":[]}]} + Set a schedule to be active: {"activeAutomations":[{"deviceId":"XXXXXXXXXXXXX","timestamp":1532015790139,"activeModes":[],"activeSchedules":["schedule.1"]}]} + """ + return self.request.get('https://my.arlo.com/hmsweb/users/devices/automation/active') + + def CustomMode(self, device, mode, schedules=[]): + """ device can be any object that has parentId == deviceId. i.e., not a camera """ + if(device["deviceType"].startswith("arloq")): + return self.NotifyAndGetResponse(device, {"from":self.user_id+"_web", "to": device.get("parentId"), "action":"set","resource":"modes", "transId": self.genTransId(),"publishResponse":True,"properties":{"active":mode}}) + else: + return self.request.post('https://my.arlo.com/hmsweb/users/devices/automation/active', {'activeAutomations':[{'deviceId':device.get('deviceId'),'timestamp':self.to_timestamp(datetime.now()),'activeModes':[mode],'activeSchedules':schedules}]}) + + def Arm(self, device): + return self.CustomMode(device, "mode1") + + def Disarm(self, device): + return self.CustomMode(device, "mode0") + + def Calendar(self, basestation, active=True): + """ + DEPRECATED: This API appears to still do stuff, but I don't see it called in the web UI anymore when switching the mode to a schedule. + + NOTE: The Arlo API seems to disable calendar mode when switching to other modes, if it's enabled. + You should probably do the same, although, the UI reflects the switch from calendar mode to say armed mode without explicitly setting calendar mode to inactive. + """ + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"schedule","publishResponse":True,"properties":{"active":active}}) + + def SetSchedule(self, basestation, schedule): + """ + The following json is what was sent to the API when I edited my schedule. It contains all of the data necessary to configure a whole week. It's a little convoluted, but you can just play around with the scheduler in Chrome and watch the schema that gets sent. + + { + "schedule": [ + { + "duration": 600, + "startActions": { + "disableModes": [ + "mode0" + ], + "enableModes": [ + "mode1" + ] + }, + "days": [ + "Mo", + "Tu", + "We", + "Th", + "Fr", + "Sa", + "Su" + ], + "startTime": 0, + "type": "weeklyAction", + "endActions": { + "disableModes": [ + "mode1" + ], + "enableModes": [ + "mode0" + ] + } + }, + { + "duration": 360, + "startActions": { + "disableModes": [ + "mode0" + ], + "enableModes": [ + "mode2" + ] + }, + "days": [ + "Mo", + "Tu", + "We", + "Th", + "Fr", + "Sa", + "Su" + ], + "startTime": 1080, + "type": "weeklyAction", + "endActions": { + "disableModes": [ + "mode2" + ], + "enableModes": [ + "mode0" + ] + } + }, + { + "duration": 480, + "startActions": { + "disableModes": [ + "mode0" + ], + "enableModes": [ + "mode3" + ] + }, + "days": [ + "Tu" + ], + "startTime": 600, + "type": "weeklyAction", + "endActions": { + "disableModes": [ + "mode3" + ], + "enableModes": [ + "mode0" + ] + } + } + ], + "name": "", + "id": "schedule.1", + "enabled": true + } + """ + return self.request.post('https://my.arlo.com/hmsweb/users/locations/'+basestation.get('uniqueId')+'/schedules', ) + + def AdjustBrightness(self, basestation, camera, brightness=0): + """ + NOTE: Brightness is between -2 and 2 in increments of 1 (-2, -1, 0, 1, 2). + Setting it to an invalid value has no effect. + + Returns: + { + "action": "is", + "from": "XXXXXXXXXXXXX", + "properties": { + "brightness": -2 + }, + "resource": "cameras/XXXXXXXXXXXXX", + "to": "336-XXXXXXX_web", + "transId": "web!XXXXXXXX.389518!1514956240683" + } + """ + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+camera.get('deviceId'),"publishResponse":True,"properties":{"brightness":brightness}}) + + def ToggleCamera(self, basestation, camera, active=True): + """ + active: True - Camera is off. + active: False - Camera is on. + """ + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+camera.get('deviceId'),"publishResponse":True,"properties":{"privacyActive":active}}) + + def PushToTalk(self, camera): + return self.request.get('https://my.arlo.com/hmsweb/users/devices/'+camera.get('uniqueId')+'/pushtotalk') + + """ General alert toggles """ + def SetMotionAlertsOn(self, basestation, sensitivity=5): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"motionDetection":{"armed":True,"sensitivity":sensitivity,"zones":[]}}}) + + def SetMotionAlertsOff(self, basestation, sensitivity=5): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"motionDetection":{"armed":False,"sensitivity":sensitivity,"zones":[]}}}) + + def SetAudioAlertsOn(self, basestation, sensitivity=3): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"audioDetection":{"armed":True,"sensitivity":sensitivity}}}) + + def SetAudioAlertsOff(self, basestation, sensitivity=3): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"audioDetection":{"armed":False,"sensitivity":sensitivity}}}) + + def AlertNotificationMethods(self, basestation, action="disabled", email=False, push=False): + """ action : disabled OR recordSnapshot OR recordVideo """ + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"eventAction":{"actionType":action,"stopType":"timeout","timeout":15,"emailNotification":{"enabled":email,"emailList":["__OWNER_EMAIL__"]},"pushNotification":push}}}) + + """ Arlo Baby Audio Control """ + def GetAudioPlayback(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"audioPlayback","publishResponse":False}) + + def PlayTrack(self, basestation, track_id="2391d620-e491-4412-99f6-e9a40d6046ed", position=0): + """ Defaulting to 'hugh little baby', which is a supplied track. I hope the ID is the same for all. """ + return self.Notify(basestation, {"action":"playTrack","resource":"audioPlayback/player","properties":{"trackId":track_id,"position":position}}) + + def PauseTrack(self, basestation): + return self.Notify(basestation, {"action":"pause","resource":"audioPlayback/player"}) + + def UnPauseTrack(self, basestation): + return self.Notify(basestation, {"action":"play","resource":"audioPlayback/player"}) + + def SkipTrack(self, basestation): + return self.Notify(basestation, {"action":"nextTrack","resource":"audioPlayback/player"}) + + def SetSleepTimerOn(self, basestation, time=calendar.timegm(time.gmtime()) + 300, timediff=0): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"sleepTime":time,"sleepTimeRel":timediff}}}) + + def SetSleepTimerOff(self, basestation, time=0, timediff=300): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"sleepTime": time,"sleepTimeRel":timediff}}}) + + def SetLoopBackModeContinuous(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"loopbackMode":"continuous"}}}) + + def SetLoopBackModeSingleTrack(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"loopbackMode":"singleTrack"}}}) + + def SetShuffleOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"shuffleActive":True}}}) + + def SetShuffleOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"audioPlayback/config","publishResponse":True,"properties":{"config":{"shuffleActive":False}}}) + + def SetVolume(self, basestation, mute=False, volume=50): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"speaker":{"mute":mute,"volume":volume}}}) + + """ Baby Arlo Nightlight, (current state is in the arlo.GetCameraState(cameras[0]["properties"][0]["nightLight"]) """ + def SetNightLightOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"enabled":True}}}) + + def SetNightLightOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"enabled":False}}}) + + def SetNightLightBrightness(self, basestation, level=200): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"brightness":level}}}) + + def SetNightLightMode(self, basestation, mode="rainbow"): + """ mode: rainbow or rgb. """ + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"mode":mode}}}) + + def SetNightLightColor(self, basestation, red=255, green=255, blue=255): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"rgb":{"blue":blue,"green":green,"red":red}}}}) + + def SetNightLightTimerOn(self, basestation, time=calendar.timegm(time.gmtime()) + 300, timediff=0): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"sleepTime":time,"sleepTimeRel":timediff}}}) + + def SetNightLightTimerOff(self, basestation, time=0, timediff=300): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId'),"publishResponse":True,"properties":{"nightLight":{"sleepTime":time,"sleepTimeRel":timediff}}}) + + """ Baby Arlo Sensors """ + def GetCameraTempReading(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/history","publishResponse":False}) + + def GetSensorConfig(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"get","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":False}) + + def SetAirQualityAlertOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"alertsEnabled":True}}}) + + def SetAirQualityAlertOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"alertsEnabled":False}}}) + + def SetAirQualityAlertThresholdMin(self, basestation, number=400): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"minThreshold":number}}}) + + def SetAirQualityAlertThresholdMax(self, basestation, number=700): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"maxThreshold":number}}}) + + def SetAirQualityRecordingOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"recordingEnabled":True}}}) + + def SetAirQualityRecordingOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"airQuality":{"recordingEnabled":False}}}) + + def SetHumidityAlertOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"alertsEnabled":True}}}) + + def SetHumidityAlertOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"alertsEnabled":False}}}) + + def SetHumidityAlertThresholdMin(self, basestation, number=400): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"minThreshold":number}}}) + + def SetHumidityAlertThresholdMax(self, basestation, number=800): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"maxThreshold":number}}}) + + def SetHumidityRecordingOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"recordingEnabled":True}}}) + + def SetHumidityRecordingOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"humidity":{"recordingEnabled":False}}}) + + def SetTempAlertOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"alertsEnabled":True}}}) + + def SetTempAlertOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"alertsEnabled":False}}}) + + def SetTempAlertThresholdMin(self, basestation, number=200): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"minThreshold":number}}}) + + def SetTempAlertThresholdMax(self, basestation, number=240): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"maxThreshold":number}}}) + + def SetTempRecordingOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"recordingEnabled":True}}}) + + def SetTempRecordingOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"cameras/"+basestation.get('deviceId')+"/ambientSensors/config","publishResponse":True,"properties":{"temperature":{"recordingEnabled":False}}}) + + def SetTempUnit(self, uniqueId, unit="C"): + return self.request.post('https://my.arlo.com/hmsweb/users/devices/'+uniqueId+'/tempUnit', {"tempUnit":unit}) + + def SirenOn(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"siren","publishResponse":True,"properties":{"sirenState":"on","duration":300,"volume":8,"pattern":"alarm"}}) + + def SirenOff(self, basestation): + return self.NotifyAndGetResponse(basestation, {"action":"set","resource":"siren","publishResponse":True,"properties":{"sirenState":"off","duration":300,"volume":8,"pattern":"alarm"}}) + + def Reset(self): + return self.request.get('https://my.arlo.com/hmsweb/users/library/reset') + + def GetServiceLevelSettings(self): + return self.request.get('https://my.arlo.com/hmsweb/users/serviceLevel/settings') + + def GetServiceLevel(self): + return self.request.get('https://my.arlo.com/hmsweb/users/serviceLevel') + + def GetServiceLevelV2(self): + """ DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. """ + return self.request.get('https://my.arlo.com/hmsweb/users/serviceLevel/v2') + + def GetServiceLevelV3(self): + """ DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. """ + return self.request.get('https://my.arlo.com/hmsweb/users/serviceLevel/v3') + + def GetServiceLevelV4(self): + return self.request.get('https://my.arlo.com/hmsweb/users/serviceLevel/v4') + + def GetUpdateFeatures(self): + return self.request.get('https://my.arlo.com/hmsweb/users/devices/updateFeatures/feature') + + def GetPaymentBilling(self): + return self.request.get('https://my.arlo.com/hmsweb/users/payment/billing/'+self.user_id) + + def GetPaymentOffers(self): + """ DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. """ + return self.request.get('https://my.arlo.com/hmsweb/users/payment/offers') + + def GetPaymentOffersV2(self): + """ DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. """ + return self.request.get('https://my.arlo.com/hmsweb/users/payment/offers/v2') + + def GetPaymentOffersV3(self): + """ DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. """ + return self.request.get('https://my.arlo.com/hmsweb/users/payment/offers/v3') + + def GetPaymentOffersV4(self): + return self.request.get('https://my.arlo.com/hmsweb/users/payment/offers/v4') + + def SetOCProfile(self, firstName, lastName, country='United States', language='en', spam_me=0): + return self.request.post('https://my.arlo.com/hmsweb/users/ocprofile', {"firstName":"Jeffrey","lastName":"Walter","country":country,"language":language,"mailProgram":spam_me}) + + def GetOCProfile(self): + return self.request.get('https://my.arlo.com/hmsweb/users/ocprofile') + + def GetProfile(self): + return self.request.get('https://my.arlo.com/hmsweb/users/profile') + + def GetSession(self): + """ + Returns something like the following: + { + "userId": "XXX-XXXXXXX", + "email": "jeffreydwalter@gmail.com", + "token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "paymentId": "XXXXXXXX", + "accountStatus": "registered", + "serialNumber": "XXXXXXXXXXXXXX", + "countryCode": "US", + "tocUpdate": false, + "policyUpdate": false, + "validEmail": true, + "arlo": true, + "dateCreated": 1463975008658 + } + """ + return self.request.get('https://my.arlo.com/hmsweb/users/session') + + def GetFriends(self): + return self.request.get('https://my.arlo.com/hmsweb/users/friends') + + def GetLocations(self): + """ + This call returns the following: + { + "id":"XXX-XXXXXXX_20160823042047", + "name":"Home", + "ownerId":"XXX-XXXXXXX", + "longitude":X.XXXXXXXXXXXXXXXX, + "latitude":X.XXXXXXXXXXXXXXXX, + "address":"123 Middle Of Nowhere Bumbfuck, EG, 12345", + "homeMode":"schedule", + "awayMode":"mode1", + "geoEnabled":false, + "geoRadius":150.0, + "uniqueIds":[ + "XXX-XXXXXXX_XXXXXXXXXXXXX" + ], + "smartDevices":[ + "XXXXXXXXXX", + "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" + ], + "pushNotifyDevices":[ + "XXXXXXXXXX" + ] + } + """ + return self.request.get('https://my.arlo.com/hmsweb/users/locations') + + def GetEmergencyLocations(self): + return self.request.get('https://my.arlo.com/hmsweb/users/emergency/locations') + + def Geofencing(self, location_id, active=True): + """ + Get location_id is the id field from the return of GetLocations() + NOTE: The Arlo API seems to disable geofencing mode when switching to other modes, if it's enabled. + You should probably do the same, although, the UI reflects the switch from calendar mode to say armed mode without explicitly setting calendar mode to inactive. + """ + return self.request.put('https://my.arlo.com/hmsweb/users/locations/'+location_id, {'geoEnabled':active}) + + def GetDevices(self, device_type=None, filter_provisioned=None): + """ + This method returns an array that contains the basestation, cameras, etc. and their metadata. + If you pass in a valid device type, as a string or a list, this method will return an array of just those devices that match that type. An example would be ['basestation', 'camera'] + To filter provisioned or unprovisioned devices pass in a True/False value for filter_provisioned. By default both types are returned. + """ + devices = self.request.get('https://my.arlo.com/hmsweb/users/devices') + if device_type: + devices = [ device for device in devices if device['deviceType'] in device_type] + + if filter_provisioned is not None: + if filter_provisioned: + devices = [ device for device in devices if device.get("state") == 'provisioned'] + else: + devices = [ device for device in devices if device.get("state") != 'provisioned'] + + return devices + + def GetDeviceSupport(self): + """ + DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. + + This API looks like it's mainly used by the website, but I'm including it for completeness sake. + It returns something like the following: + { + "devices": [ + { + "deviceType": "arloq", + "urls": { + "troubleshoot": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_troubleshoot.html", + "plugin": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_plugin.html", + "connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_connection.html", + "connectionFailed": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_connection_fail.html", + "press_sync": "https://vzs3-prod-common.s3. amazonaws.com/static/html/en/pc_press_sync.html", + "resetDevice": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/reset_arloq.html", + "qr_how_to": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_qr_how_to.html" + } + }, + { + "deviceType": "basestation", + "urls": { + "troubleshoot": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_troubleshoot.html", + "connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_connection.html", + "sync": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_sync_camera.html" + } + }, + { + "deviceType": "arloqs", + "urls": { + "ethernetSetup": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/ethernet_setup.html", + "plugin": "https:// vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/aqp_plugin.html", + "connectionWiFi": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_in_progress_wifi.html", + "poeSetup": "https://vzs3-prod-common.s3. amazonaws.com/static/html/en/arloqs/poe_setup.html", + "connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_in_progress.html", + "connectionFailed": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_fail.html", + "press_sync": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/press_sync.html", + "connectionType": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_type.html", + "resetDevice": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/reset_device.html", + "qr_how_to": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/qr_how_to.html" + } + } + ] + } + """ + return self.request.get('https://my.arlo.com/hmsweb/devicesupport') + + def GetDeviceSupportv2(self): + """ + DEPRECATED: This API still works, but I don't see it being called in the web UI anymore. + + It returns something like the following: + { + "devices": [ + { + "deviceType": "arloq", + "modelId": [ + "VMC3040" + ], + "urls": { + "troubleshoot": "arloq/troubleshoot.html", + "plugin": "arloq/plugin.html", + "qrHowTo": "arloq/qrHowTo.html", + "connection": "arloq/connection.html", + "connectionInProgress": "arloq/connectionInProgress.html", + "connectionFailed": "arloq/connectionFailed.html", + "pressSync": "arloq/pressSync.html", + "resetDevice": "arloq/resetDevice.html" + } + }, + { + "deviceType": "basestation", + "modelId": [ + "VMB3010", + "VMB3010r2", + "VMB3500", + "VMB4000", + "VMB4500", + "VZB3010" + ], + "urls": { + "troubleshoot": "basestation/troubleshoot.html", + "plugin": "basestation/plugin.html", + "sync3": "basestation/sync3.html", + "troubleshootBS": "basestation/troubleshootBS.html", + "connection": "basestation/connection.html", + "connectionInProgress": "basestation/connectionInProgress.html", + "sync2": "basestation/sync2.html", + "connectionFailed": "basestation/connectionFailed.html", + "sync1": "basestation/sync1.html", + "resetDevice": "basestation/resetDevice.html", + "syncComplete": "basestation/syncComplete.html" + } + }, + { + "deviceType": "arlobaby", + "modelId": [ + "ABC1000" + ], + "urls": { + "bleSetupError": "arlobaby/bleSetupError.html", + "troubleshoot": "arlobaby/troubleshoot.html", + "homekitCodeInstruction": "arlobaby/homekitCodeInstruction.html", + "connectionInProgress": "arlobaby/connectionInProgress.html", + "connectionFailed": "arlobaby/connectionFailed.html", + "resetDevice": "arlobaby/resetDevice.html", + "plugin": "arlobaby/plugin.html", + "qrHowTo": "arlobaby/qrHowTo.html", + "warning": "arlobaby/warning.html", + "connection": "arlobaby/connection.html", + "pressSync": "arlobaby/pressSync.html", + "bleInactive": "arlobaby/bleInactive.html", + "pluginIOS": "arlobaby/pluginIOS.html", + "homekitSetup": "arlobaby/homekitSetup.html" + } + }, + { + "deviceType": "lteCamera", + "modelId": [ + "VML4030" + ], + "urls": { + "troubleshoot": "lteCamera/troubleshoot.html", + "resetHowTo": "lteCamera/resetHowTo.html", + "plugin": "lteCamera/plugin.html", + "qrHowTo": "lteCamera/qrHowTo.html", + "connectionInProgress": "lteCamera/connectionInProgress.html", + "connectionFailed": "lteCamera/connectionFailed.html", + "resetDevice": "lteCamera/resetHowTo.html", + "resetComplete": "lteCamera/resetComplete.html", + "syncComplete": "lteCamera/syncComplete.html" + } + }, + { + "deviceType": "arloqs", + "modelId": [ + "VMC3040S" + ], + "urls": { + "ethernetSetup": "arloqs/ethernetSetup.html", + "troubleshoot": "arloqs/troubleshoot.html", + "plugin": "arloqs/plugin.html", + "poeSetup": "arloqs/poeSetup.html", + "connectionInProgressWiFi": "arloqs/connectionInProgressWifi.html", + "qrHowTo": "arloqs/qrHowTo.html", + "connectionInProgress": "arloqs/connectionInProgress.html", + "connectionFailed": "arloqs/connectionFailed.html", + "pressSync": "arloqs/pressSync.html", + "connectionType": "arloqs/connectionType.html", + "resetDevice": "arloqs/resetDevice.html" + } + }, + { + "deviceType": "bridge", + "modelId": [ + "ABB1000" + ], + "urls": { + "troubleshoot": "bridge/troubleshoot.html", + "fwUpdateInProgress": "bridge/fwUpdateInProgress.html", + "qrHowToUnplug": "bridge/qrHowToUnplug.html", + "fwUpdateDone": "bridge/fwUpdateDone.html", + "fwUpdateAvailable": "bridge/fwUpdateAvailable.html", + "needHelp": "https://www.arlo.com/en-us/support/#support_arlo_light", + "wifiError": "bridge/wifiError.html", + "bleAndroid": "bridge/bleInactiveAND.html", + "bleIOS": "bridge/bleInactiveIOS.html", + "connectionInProgress": "bridge/connectionInProgress.html", + "connectionFailed": "bridge/connectionFailed.html", + "manualPair": "bridge/manualPairing.html", + "resetDevice": "bridge/resetDevice.html", + "lowPower": "bridge/lowPowerZoneSetup.html", + "fwUpdateFailed": "bridge/fwUpdateFailed.html", + "fwUpdateCheckFailed": "bridge/fwUpdateCheckFailed.html", + "plugin": "bridge/plugin.html", + "qrHowTo": "bridge/qrHowTo.html", + "pressSync": "bridge/pressSync.html", + "pluginNoLED": "bridge/pluginNoLED.html", + "fwUpdateCheck": "bridge/fwUpdateCheck.html" + } + }, + { + "deviceType": "lights", + "modelId": [ + "AL1101" + ], + "urls": { + "troubleshoot": "lights/troubleshoot.html", + "needHelp": "https://kb.netgear.com/000053159/Light-discovery-failed.html", + "bleInactiveAND": "lights/bleInactiveAND.html", + "connectionInProgress": "lights/connectionInProgress.html", + "connectionFailed": "lights/connectionFailed.html", + "addBattery": "lights/addBattery.html", + "tutorial1": "lights/tutorial1.html", + "plugin": "lights/plugin.html", + "tutorial2": "lights/tutorial2.html", + "tutorial3": "lights/tutorial3.html", + "configurationInProgress": "lights/configurationInProgress.html", + "qrHowTo": "lights/qrHowTo.html", + "pressSync": "lights/pressSync.html", + "bleInactiveIOS": "lights/bleInactiveIOS.html", + "syncComplete": "lights/syncComplete.html" + } + }, + { + "deviceType": "routerM1", + "modelId": [ + "MR1100" + ], + "urls": { + "troubleshoot": "routerM1/troubleshoot.html", + "help": "routerM1/help.html", + "pairingFailed": "routerM1/pairingFailed.html", + "needHelp": "https://acupdates.netgear.com/help/redirect.aspx?url=m1arlo-kbb", + "plugin": "routerM1/plugin.html", + "pairing": "routerM1/pairing.html", + "connectionInProgress": "routerM1/connectionInProgress.html", + "sync2": "routerM1/sync2.html", + "connectionFailed": "routerM1/connectionFailed.html", + "sync1": "routerM1/sync1.html", + "sync": "routerM1/sync.html", + "syncComplete": "routerM1/syncComplete.html" + } + } + ], + "selectionUrls": { + "addDevice": "addDeviceBsRuAqAqpLteAbcMrBgLt.html", + "selectBasestation": "selectBsMr.html", + "deviceSelection": "deviceBsAqAqpLteAbcMrLtSelection.html", + "selectLights": "selectBgLt.html" + }, + "baseUrl": "https://vzs3-prod-common.s3.amazonaws.com/static/v2/html/en/" + } + """ + return self.request.get('https://my.arlo.com/hmsweb/devicesupport/v2') + + def GetDeviceSupportV3(self): + """ + This is the latest version of the device support api. + It returns something like the following: + { + "data": { + "devices": { + "camera": { + "modelIds": [ + "VMC3010", + "VMC3030", + "VMC4030", + "VMC4030P", + "VMC5040", + "VZC3010", + "VZC3030" + ], + "connectionTypes": { + "WPS": true, + "BLE": true + }, + "kbArticles": { + "insertBatteries": "https://kb.arlo.com/980150/Safety-Rules-for-Arlo-Wire-Free-Camera-Batteries", + "syncBasestation": "https://kb.arlo.com/987/How-do-I-set-up-and-sync-my-Arlo-Wire-Free-cameras", + "sync": "https://kb.arlo.com/987/How-do-I-set-up-and-sync-my-Arlo-Wire-Free-camera", + "firmwareUpdate": "https://kb.arlo.com/4736/How-do-I-update-my-Arlo-firmware-manually" + } + }, + "arloq": { + "modelIds": [ + "VMC3040", + "VMC3040S" + ], + "kbArticles": { + "power": "https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", + "qrCode": "https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", + "power_android": "https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on-Android", + "qrCode_android": "https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on-Android" + } + }, + "basestation": { + "modelIds": [ + "VMB3010", + "VMB4000", + "VMB3010r2", + "VMB3500", + "VZB3010", + "VMB4500", + "VMB5000" + ], + "smartHubs": [ + "VMB5000" + ], + "kbArticles": { + "pluginNetworkCable": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", + "power": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", + "led": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", + "learnMore": "https://kb.arlo.com/000062124/How-do-I-record-4K-videos-to-a-microSD-card" + } + }, + "arlobaby": { + "modelIds": [ + "ABC1000" + ], + "kbArticles": { + "power": "https://kb.arlo.com/1282682/How-do-I-power-cycle-my-Arlo-Baby-camera", + "qrCode": "https://kb.arlo.com/1282700/How-do-I-set-up-my-Arlo-Baby-camera" + } + }, + "lteCamera":{ + "modelIds":[ + "VML4030" + ], + "kbArticles":{ + "servicePlan":"https://kb.arlo.com/1286865/What-Arlo-Mobile-service-plans-are-available", + "simActivation":"https://kb.arlo.com/1286865/What-Arlo-Mobile-service-plans-are-available", + "qrCode":"https://kb.arlo.com/1201822/How-do-I-set-up-my-Arlo-Go-camera" + } + }, + "bridge": { + "modelIds": [ + "ABB1000" + ], + "kbArticles": { + "power": "https://kb.arlo.com/000062047", + "sync": "https://kb.arlo.com/000062037", + "qrCode": "https://kb.arlo.com/000061886", + "factoryReset": "https://kb.arlo.com/000061837" + } + }, + "lights": { + "modelIds": [ + "AL1101" + ], + "kbArticles": { + "sync": "https://kb.arlo.com/000062005", + "insertBatteries": "https://kb.arlo.com/000061952", + "qrCode": "https://kb.arlo.com/000061886" + } + }, + "routerM1":{ + "modelIds":[ + "MR1100" + ], + "kbArticles":{ + "lookupFailed":"https://kb.arlo.com/1179130/Arlo-can-t-discover-my-base-station-during-installation-what-do-I-do" + } + }, + "chime": { + "modelIds": [ + "AC1001" + ], + "kbArticles": { + "ledNotBlinking":"https://kb.arlo.com/000061924", + "led":"https://kb.arlo.com/000061847", + "factoryReset":"https://kb.arlo.com/000061879", + "connectionFailed":"https://kb.arlo.com/000061880" + } + }, + "doorbell": { + "modelIds": [ + "AAD1001" + ], + "kbArticles": { + "led":"https://kb.arlo.com/000061847", + "factoryReset":"https://kb.arlo.com/000061842", + "pairCamera":"https://kb.arlo.com/000061897", + "existingChime":"https://kb.arlo.com/000061856", + "noWiring":"https://kb.arlo.com/000061859", + "connectionFailed":"https://kb.arlo.com/000061868", + "pairCameraFailed":"https://kb.arlo.com/000061893", + "testChimeFailed":"https://kb.arlo.com/000061944" + }, + "videos": { + "chimeType": "https://youtu.be/axytuF63VC0", + "wireDoorbell": "https://youtu.be/_5D2n3iPqW0", + "switchSetting": "https://youtu.be/BUmd4fik2RE" + }, + "arloVideos": { + "chimeType": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Chime.mp4", + "wireDoorbell": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Wired.mp4", + "switchSetting": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Switch.mp4" + } + } + }, + "arlosmart": { + "kbArticles": { + "e911": "https://www.arlo.com/en-us/landing/arlosmart/", + "callFriend": "https://www.arlo.com/en-us/landing/arlosmart/", + "4kAddOnPopup": "https://www.arlo.com/en-us/landing/arlosmart/", + "cloudRecording": "https://www.arlo.com/en-us/landing/arlosmart/", + "manageArloSmart": "https://kb.arlo.com/000062115", + "otherVideo": "https://kb.arlo.com/000062115", + "packageDetection": "https://kb.arlo.com/000062114", + "whereIsBasicSubscriptionGone": "https://kb.arlo.com/000062163" + } + } + }, + "success":true + } + """ + return self.request.get('https://my.arlo.com/hmsweb/devicesupport/v3') + + def GetDeviceCapabilities(self, device): + model = device.get('modelId').lower() + return self.request.get('https://my.arlo.com/resources/capabilities/'+model+'/'+model+'_'+device.get('interfaceVersion')+'.json', raw=True) + + def GetLibraryMetaData(self, from_date, to_date): + return self.request.post('https://my.arlo.com/hmsweb/users/library/metadata', {'dateFrom':from_date, 'dateTo':to_date}) + + def UpdateProfile(self, first_name, last_name): + return self.request.put('https://my.arlo.com/hmsweb/users/profile', {'firstName': first_name, 'lastName': last_name}) + + def UpdatePassword(self, password): + r = self.request.post('https://my.arlo.com/hmsweb/users/changePassword', {'currentPassword':self.password,'newPassword':password}) + self.password = password + return r + + def UpdateFriend(self, body): + """ + This is an example of the json you would pass in the body: + { + "firstName":"Some", + "lastName":"Body", + "devices":{ + "XXXXXXXXXXXXX":"Camera 1", + "XXXXXXXXXXXXX":"Camera 2 ", + "XXXXXXXXXXXXX":"Camera 3" + }, + "lastModified":1463977440911, + "adminUser":true, + "email":"user@example.com", + "id":"XXX-XXXXXXX" + } + """ + return self.request.put('https://my.arlo.com/hmsweb/users/friends', body) + + def RemoveFriend(self, email): + """ + Removes a person you've granted access to. + + email: email of user you want to revoke access from. + """ + return self.request.post('https://my.arlo.com/hmsweb/users/friends/remove', {"email":email}) + + def AddFriend(self, firstname, lastname, email, devices={}, admin=False): + """ + This API will send an email to a user and if they accept, will give them access to the devices you specify. + NOTE: XXX-XXXXXXX_XXXXXXXXXXXX is the uniqueId field in your device object. + + {adminUser:false,firstName:John,lastName:Doe,email:john.doe@example.com,devices:{XXX-XXXXXXX_XXXXXXXXXXXX:Camera1,XXX-XXXXXXX_XXXXXXXXXXXX:Camera2}} + """ + return self.request.post('https://my.arlo.com/hmsweb/users/friends', {"adminUser":admin,"firstName":firstname,"lastName":lastname,"email":email,"devices":devices}) + + def ResendFriendInvite(self, friend): + """ + This API will resend an invitation email to a user that you've AddFriend'd. You will need to get the friend object by calling GetFriend() because it includes a token that must be passed to this API. + friend: {"ownerId":"XXX-XXXXXXX","token":"really long string that you get from the GetFriends() API","firstName":"John","lastName":"Doe","devices":{"XXX-XXXXXXX_XXXXXXXXXXXX":"Camera1","XXX-XXXXXXX_XXXXXXXXXXXX":"Camera2"},"lastModified":1548470485419,"adminUser":false,"email":"john.doe@example.com"} + """ + return self.request.post('https://my.arlo.com/hmsweb/users/friends', friend) + + def UpdateDeviceName(self, device, name): + return self.request.put('https://my.arlo.com/hmsweb/users/devices/renameDevice', {'deviceId':device.get('deviceId'), 'deviceName':name, 'parentId':device.get('parentId')}) + + def UpdateDisplayOrder(self, body): + """ + This is an example of the json you would pass in the body to UpdateDisplayOrder() of your devices in the UI. + + XXXXXXXXXXXXX is the device id of each camera. You can get this from GetDevices(). + { + "devices":{ + "XXXXXXXXXXXXX":1, + "XXXXXXXXXXXXX":2, + "XXXXXXXXXXXXX":3 + } + } + """ + return self.request.post('https://my.arlo.com/hmsweb/users/devices/displayOrder', body) + + def GetLibrary(self, from_date, to_date): + """ + This call returns the following: + presignedContentUrl is a link to the actual video in Amazon AWS. + presignedThumbnailUrl is a link to the thumbnail .jpg of the actual video in Amazon AWS. + + [ + { + "mediaDurationSecond": 30, + "contentType": "video/mp4", + "name": "XXXXXXXXXXXXX", + "presignedContentUrl": "https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX.mp4?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "lastModified": 1472881430181, + "localCreatedDate": XXXXXXXXXXXXX, + "presignedThumbnailUrl": "https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX_thumb.jpg?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", + "reason": "motionRecord", + "deviceId": "XXXXXXXXXXXXX", + "createdBy": "XXXXXXXXXXXXX", + "createdDate": "20160903", + "timeZone": "America/Chicago", + "ownerId": "XXX-XXXXXXX", + "utcCreatedDate": XXXXXXXXXXXXX, + "currentState": "new", + "mediaDuration": "00:00:30" + } + ] + """ + return self.request.post('https://my.arlo.com/hmsweb/users/library', {'dateFrom':from_date, 'dateTo':to_date}) + + def DeleteRecording(self, recording): + """ + Delete a single video recording from Arlo. + All of the date info and device id you need to pass into this method are given in the results of the GetLibrary() call. + """ + return self.request.post('https://my.arlo.com/hmsweb/users/library/recycle', {'data':[{'createdDate':recording.get('createdDate'),'utcCreatedDate':recording.get('createdDate'),'deviceId':recording.get('deviceId')}]}) + + def BatchDeleteRecordings(self, recordings): + """ + Delete a batch of video recordings from Arlo. + + The GetLibrary() call response json can be passed directly to this method if you'd like to delete the same list of videos you queried for. + If you want to delete some other batch of videos, then you need to send an array of objects representing each video you want to delete. + + [ + { + "createdDate":"20160904", + "utcCreatedDate":1473010280395, + "deviceId":"XXXXXXXXXXXXX" + }, + { + "createdDate":"20160904", + "utcCreatedDate":1473010280395, + "deviceId":"XXXXXXXXXXXXX" + } + ] + """ + if recordings: + return self.request.post('https://my.arlo.com/hmsweb/users/library/recycle', {'data':recordings}) + + def GetRecording(self, url, chunk_size=4096): + """ Returns the whole video from the presignedContentUrl. """ + video = '' + r = requests.get(url, stream=True) + r.raise_for_status() + + for chunk in r.iter_content(chunk_size): + if chunk: video += chunk + return video + + def StreamRecording(self, url, chunk_size=4096): + """ + Returns a generator that is the chunked video stream from the presignedContentUrl. + + url: presignedContentUrl + """ + r = requests.get(url, stream=True) + r.raise_for_status() + for chunk in r.iter_content(chunk_size): + yield chunk + + def DownloadRecording(self, url, to): + """ + Writes a video to a given local file path. + + url: presignedContentUrl + to: path where the file should be written + """ + stream = self.StreamRecording(url) + with open(to, 'wb') as fd: + for chunk in stream: + fd.write(chunk) + fd.close() + + def DownloadSnapshot(self, url, to, chunk_size=4096): + """ + Writes a snapshot to a given local file path. + + url: presignedContentUrl or presignedFullFrameSnapshotUrl + to: path where the file should be written + """ + r = Request().get(url, stream=True) + with open(to, 'wb') as fd: + for chunk in r.iter_content(chunk_size): + fd.write(chunk) + fd.close() + + def StartStream(self, basestation, camera): + """ + This function returns the url of the rtsp video stream. + This stream needs to be called within 30 seconds or else it becomes invalid. + It can be streamed with: ffmpeg -re -i 'rtsps://' -acodec copy -vcodec copy test.mp4 + The request to /users/devices/startStream returns: { url:rtsp://:443/vzmodulelive?egressToken=b&userAgent=iOS&cameraId=} + """ + # nonlocal variable hack for Python 2.x. + class nl: + stream_url_dict = None + + def trigger(self): + nl.stream_url_dict = self.request.post('https://my.arlo.com/hmsweb/users/devices/startStream', {"to":camera.get('parentId'),"from":self.user_id+"_web","resource":"cameras/"+camera.get('deviceId'),"action":"set","responseUrl":"", "publishResponse":True,"transId":self.genTransId(),"properties":{"activityState":"startUserStream","cameraId":camera.get('deviceId')}}, headers={"xcloudId":camera.get('xCloudId')}) + + def callback(self, event): + if event.get("from") == basestation.get("deviceId") and event.get("resource") == "cameras/"+camera.get("deviceId") and event.get("properties", {}).get("activityState") == "userStreamActive": + return nl.stream_url_dict['url'].replace("rtsp://", "rtsps://") + + return None + + return self.TriggerAndHandleEvent(basestation, trigger, callback) + + def StopStream(self, basestation, camera): + + # nonlocal variable hack for Python 2.x. + class nl: + stream_url_dict = None + + def trigger(self): + self.request.post('https://my.arlo.com/hmsweb/users/devices/stopStream', {"to":camera.get('parentId'),"from":self.user_id+"_web","resource":"cameras/"+camera. get('deviceId'),"action":"set","responseUrl":"", "publishResponse":True,"transId":self.genTransId(),"properties":{"activityState":"stopUserStream","cameraId":camera.get('deviceId')}}, headers={"xcloudId": camera.get('xCloudId')}) + + def callback(self, event): + if event.get("from") == basestation.get("deviceId") and event.get("resource") == "cameras/"+camera.get("deviceId") and event.get("properties", {}).get("activityState") == "userStreamActive": + return nl.stream_url_dict['url'].replace("rtsp://", "rtsps://") + return None + + return self.TriggerAndHandleEvent(basestation, trigger, callback) + + def TriggerStreamSnapshot(self, basestation, camera): + """ + This function causes the camera to snapshot while recording. + NOTE: You MUST call StartStream() before calling this function. + If you call StartStream(), you have to start reading data from the stream, or streaming will be cancelled + and taking a snapshot may fail (since it requires the stream to be active). + + NOTE: You should not use this function is you just want a snapshot and aren't intending to stream. + Use TriggerFullFrameSnapshot() instead. + + NOTE: Use DownloadSnapshot() to download the actual image file. + """ + def trigger(self): + self.request.post('https://my.arlo.com/hmsweb/users/devices/takeSnapshot', {'xcloudId':camera.get('xCloudId'),'parentId':camera.get('parentId'),'deviceId':camera.get('deviceId'),'olsonTimeZone':camera.get('properties', {}).get('olsonTimeZone')}, headers={"xcloudId":camera.get('xCloudId')}) + + def callback(self, event): + if event.get("deviceId") == camera.get("deviceId") and event.get("resource") == "mediaUploadNotification": + presigned_content_url = event.get("presignedContentUrl") + if presigned_content_url is not None: + return presigned_content_url + + return None + + return self.TriggerAndHandleEvent(basestation, trigger, callback) + + def TriggerFullFrameSnapshot(self, basestation, camera): + """ + This function causes the camera to record a fullframe snapshot. + The presignedFullFrameSnapshotUrl url is returned. + Use DownloadSnapshot() to download the actual image file. + """ + def trigger(self): + self.request.post("https://my.arlo.com/hmsweb/users/devices/fullFrameSnapshot", {"to":camera.get("parentId"),"from":self.user_id+"_web","resource":"cameras/"+camera.get("deviceId"),"action":"set","publishResponse":True,"transId":self.genTransId(),"properties":{"activityState":"fullFrameSnapshot"}}, headers={"xcloudId":camera.get("xCloudId")}) + + def callback(self, event): + if event.get("from") == basestation.get("deviceId") and event.get("resource") == "cameras/"+camera.get("deviceId") and event.get("action") == "fullFrameSnapshotAvailable": + return event.get("properties", {}).get("presignedFullFrameSnapshotUrl") + return None + + return self.TriggerAndHandleEvent(basestation, trigger, callback) + + def StartRecording(self, basestation, camera): + """ + This function causes the camera to start recording. + You can get the timezone from GetDevices(). + """ + stream_url = self.StartStream(basestation, camera) + self.request.post('https://my.arlo.com/hmsweb/users/devices/startRecord', {'xcloudId':camera.get('xCloudId'),'parentId':camera.get('parentId'),'deviceId':camera.get('deviceId'),'olsonTimeZone':camera.get('properties', {}).get('olsonTimeZone')}, headers={"xcloudId":camera.get('xCloudId')}) + return stream_url + + def StopRecording(self, camera): + """ + This function causes the camera to stop recording. + You can get the timezone from GetDevices(). + """ + return self.request.post('https://my.arlo.com/hmsweb/users/devices/stopRecord', {'xcloudId':camera.get('xCloudId'),'parentId':camera.get('parentId'),'deviceId':camera.get('deviceId'),'olsonTimeZone':camera.get('properties', {}).get('olsonTimeZone')}, headers={"xcloudId":camera.get('xCloudId')}) + + def GetCvrPlaylist(self, camera, fromDate, toDate): + """ This function downloads a Cvr Playlist file for the period fromDate to toDate. """ + return self.request.get('https://my.arlo.com/hmsweb/users/devices/'+camera.get('deviceId')+'/playlist?fromDate='+fromDate+'&toDate='+toDate) diff --git a/RPI Code/Arlo/dev/html2text.py b/RPI Code/Arlo/dev/html2text.py new file mode 100644 index 0000000..1752890 --- /dev/null +++ b/RPI Code/Arlo/dev/html2text.py @@ -0,0 +1,914 @@ +#!/usr/bin/env python +"""html2text: Turn HTML into equivalent Markdown-structured text.""" +__version__ = "3.200.3" +__author__ = "Aaron Swartz (me@aaronsw.com)" +__copyright__ = "(C) 2004-2008 Aaron Swartz. GNU GPL 3." +__contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"] + +# TODO: +# Support decoded entities with unifiable. + +try: + True +except NameError: + setattr(__builtins__, 'True', 1) + setattr(__builtins__, 'False', 0) + +def has_key(x, y): + if hasattr(x, 'has_key'): return x.has_key(y) + else: return y in x + +try: + import htmlentitydefs + import urlparse + import HTMLParser +except ImportError: #Python3 + import html.entities as htmlentitydefs + import urllib.parse as urlparse + import html.parser as HTMLParser +try: #Python3 + import urllib.request as urllib +except: + import urllib +import optparse, re, sys, codecs, types + +try: from textwrap import wrap +except: pass + +# Use Unicode characters instead of their ascii psuedo-replacements +UNICODE_SNOB = 0 + +# Escape all special characters. Output is less readable, but avoids corner case formatting issues. +ESCAPE_SNOB = 0 + +# Put the links after each paragraph instead of at the end. +LINKS_EACH_PARAGRAPH = 0 + +# Wrap long lines at position. 0 for no wrapping. (Requires Python 2.3.) +BODY_WIDTH = 78 + +# Don't show internal links (href="#local-anchor") -- corresponding link targets +# won't be visible in the plain text file anyway. +SKIP_INTERNAL_LINKS = True + +# Use inline, rather than reference, formatting for images and links +INLINE_LINKS = True + +# Number of pixels Google indents nested lists +GOOGLE_LIST_INDENT = 36 + +IGNORE_ANCHORS = False +IGNORE_IMAGES = False +IGNORE_EMPHASIS = False + +### Entity Nonsense ### + +def name2cp(k): + if k == 'apos': return ord("'") + if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3 + return htmlentitydefs.name2codepoint[k] + else: + k = htmlentitydefs.entitydefs[k] + if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1 + return ord(codecs.latin_1_decode(k)[0]) + +unifiable = {'rsquo':"'", 'lsquo':"'", 'rdquo':'"', 'ldquo':'"', +'copy':'(C)', 'mdash':'--', 'nbsp':' ', 'rarr':'->', 'larr':'<-', 'middot':'*', +'ndash':'-', 'oelig':'oe', 'aelig':'ae', +'agrave':'a', 'aacute':'a', 'acirc':'a', 'atilde':'a', 'auml':'a', 'aring':'a', +'egrave':'e', 'eacute':'e', 'ecirc':'e', 'euml':'e', +'igrave':'i', 'iacute':'i', 'icirc':'i', 'iuml':'i', +'ograve':'o', 'oacute':'o', 'ocirc':'o', 'otilde':'o', 'ouml':'o', +'ugrave':'u', 'uacute':'u', 'ucirc':'u', 'uuml':'u', +'lrm':'', 'rlm':''} + +unifiable_n = {} + +for k in unifiable.keys(): + unifiable_n[name2cp(k)] = unifiable[k] + +### End Entity Nonsense ### + +def onlywhite(line): + """Return true if the line does only consist of whitespace characters.""" + for c in line: + if c is not ' ' and c is not ' ': + return c is ' ' + return line + +def hn(tag): + if tag[0] == 'h' and len(tag) == 2: + try: + n = int(tag[1]) + if n in range(1, 10): return n + except ValueError: return 0 + +def dumb_property_dict(style): + """returns a hash of css attributes""" + return dict([(x.strip(), y.strip()) for x, y in [z.split(':', 1) for z in style.split(';') if ':' in z]]); + +def dumb_css_parser(data): + """returns a hash of css selectors, each of which contains a hash of css attributes""" + # remove @import sentences + data += ';' + importIndex = data.find('@import') + while importIndex != -1: + data = data[0:importIndex] + data[data.find(';', importIndex) + 1:] + importIndex = data.find('@import') + + # parse the css. reverted from dictionary compehension in order to support older pythons + elements = [x.split('{') for x in data.split('}') if '{' in x.strip()] + try: + elements = dict([(a.strip(), dumb_property_dict(b)) for a, b in elements]) + except ValueError: + elements = {} # not that important + + return elements + +def element_style(attrs, style_def, parent_style): + """returns a hash of the 'final' style attributes of the element""" + style = parent_style.copy() + if 'class' in attrs: + for css_class in attrs['class'].split(): + css_style = style_def['.' + css_class] + style.update(css_style) + if 'style' in attrs: + immediate_style = dumb_property_dict(attrs['style']) + style.update(immediate_style) + return style + +def google_list_style(style): + """finds out whether this is an ordered or unordered list""" + if 'list-style-type' in style: + list_style = style['list-style-type'] + if list_style in ['disc', 'circle', 'square', 'none']: + return 'ul' + return 'ol' + +def google_has_height(style): + """check if the style of the element has the 'height' attribute explicitly defined""" + if 'height' in style: + return True + return False + +def google_text_emphasis(style): + """return a list of all emphasis modifiers of the element""" + emphasis = [] + if 'text-decoration' in style: + emphasis.append(style['text-decoration']) + if 'font-style' in style: + emphasis.append(style['font-style']) + if 'font-weight' in style: + emphasis.append(style['font-weight']) + return emphasis + +def google_fixed_width_font(style): + """check if the css of the current element defines a fixed width font""" + font_family = '' + if 'font-family' in style: + font_family = style['font-family'] + if 'Courier New' == font_family or 'Consolas' == font_family: + return True + return False + +def list_numbering_start(attrs): + """extract numbering from list element attributes""" + if 'start' in attrs: + return int(attrs['start']) - 1 + else: + return 0 + +class HTML2Text(HTMLParser.HTMLParser): + def __init__(self, out=None, baseurl=''): + HTMLParser.HTMLParser.__init__(self) + + # Config options + self.unicode_snob = UNICODE_SNOB + self.escape_snob = ESCAPE_SNOB + self.links_each_paragraph = LINKS_EACH_PARAGRAPH + self.body_width = BODY_WIDTH + self.skip_internal_links = SKIP_INTERNAL_LINKS + self.inline_links = INLINE_LINKS + self.google_list_indent = GOOGLE_LIST_INDENT + self.ignore_links = IGNORE_ANCHORS + self.ignore_images = IGNORE_IMAGES + self.ignore_emphasis = IGNORE_EMPHASIS + self.google_doc = False + self.ul_item_mark = '*' + self.emphasis_mark = '_' + self.strong_mark = '**' + + if out is None: + self.out = self.outtextf + else: + self.out = out + + self.outtextlist = [] # empty list to store output characters before they are "joined" + + try: + self.outtext = unicode() + except NameError: # Python3 + self.outtext = str() + + self.quiet = 0 + self.p_p = 0 # number of newline character to print before next output + self.outcount = 0 + self.start = 1 + self.space = 0 + self.a = [] + self.astack = [] + self.maybe_automatic_link = None + self.absolute_url_matcher = re.compile(r'^[a-zA-Z+]+://') + self.acount = 0 + self.list = [] + self.blockquote = 0 + self.pre = 0 + self.startpre = 0 + self.code = False + self.br_toggle = '' + self.lastWasNL = 0 + self.lastWasList = False + self.style = 0 + self.style_def = {} + self.tag_stack = [] + self.emphasis = 0 + self.drop_white_space = 0 + self.inheader = False + self.abbr_title = None # current abbreviation definition + self.abbr_data = None # last inner HTML (for abbr being defined) + self.abbr_list = {} # stack of abbreviations to write later + self.baseurl = baseurl + + try: del unifiable_n[name2cp('nbsp')] + except KeyError: pass + unifiable['nbsp'] = ' _place_holder;' + + + def feed(self, data): + data = data.replace("", "") + HTMLParser.HTMLParser.feed(self, data) + + def handle(self, data): + self.feed(data) + self.feed("") + return self.optwrap(self.close()) + + def outtextf(self, s): + self.outtextlist.append(s) + if s: self.lastWasNL = s[-1] == '\n' + + def close(self): + HTMLParser.HTMLParser.close(self) + + self.pbr() + self.o('', 0, 'end') + + self.outtext = self.outtext.join(self.outtextlist) + if self.unicode_snob: + nbsp = unichr(name2cp('nbsp')) + else: + nbsp = u' ' + self.outtext = self.outtext.replace(u' _place_holder;', nbsp) + + return self.outtext + + def handle_charref(self, c): + self.o(self.charref(c), 1) + + def handle_entityref(self, c): + self.o(self.entityref(c), 1) + + def handle_starttag(self, tag, attrs): + self.handle_tag(tag, attrs, 1) + + def handle_endtag(self, tag): + self.handle_tag(tag, None, 0) + + def previousIndex(self, attrs): + """ returns the index of certain set of attributes (of a link) in the + self.a list + + If the set of attributes is not found, returns None + """ + if not has_key(attrs, 'href'): return None + + i = -1 + for a in self.a: + i += 1 + match = 0 + + if has_key(a, 'href') and a['href'] == attrs['href']: + if has_key(a, 'title') or has_key(attrs, 'title'): + if (has_key(a, 'title') and has_key(attrs, 'title') and + a['title'] == attrs['title']): + match = True + else: + match = True + + if match: return i + + def drop_last(self, nLetters): + if not self.quiet: + self.outtext = self.outtext[:-nLetters] + + def handle_emphasis(self, start, tag_style, parent_style): + """handles various text emphases""" + tag_emphasis = google_text_emphasis(tag_style) + parent_emphasis = google_text_emphasis(parent_style) + + # handle Google's text emphasis + strikethrough = 'line-through' in tag_emphasis and self.hide_strikethrough + bold = 'bold' in tag_emphasis and not 'bold' in parent_emphasis + italic = 'italic' in tag_emphasis and not 'italic' in parent_emphasis + fixed = google_fixed_width_font(tag_style) and not \ + google_fixed_width_font(parent_style) and not self.pre + + if start: + # crossed-out text must be handled before other attributes + # in order not to output qualifiers unnecessarily + if bold or italic or fixed: + self.emphasis += 1 + if strikethrough: + self.quiet += 1 + if italic: + self.o(self.emphasis_mark) + self.drop_white_space += 1 + if bold: + self.o(self.strong_mark) + self.drop_white_space += 1 + if fixed: + self.o('`') + self.drop_white_space += 1 + self.code = True + else: + if bold or italic or fixed: + # there must not be whitespace before closing emphasis mark + self.emphasis -= 1 + self.space = 0 + self.outtext = self.outtext.rstrip() + if fixed: + if self.drop_white_space: + # empty emphasis, drop it + self.drop_last(1) + self.drop_white_space -= 1 + else: + self.o('`') + self.code = False + if bold: + if self.drop_white_space: + # empty emphasis, drop it + self.drop_last(2) + self.drop_white_space -= 1 + else: + self.o(self.strong_mark) + if italic: + if self.drop_white_space: + # empty emphasis, drop it + self.drop_last(1) + self.drop_white_space -= 1 + else: + self.o(self.emphasis_mark) + # space is only allowed after *all* emphasis marks + if (bold or italic) and not self.emphasis: + self.o(" ") + if strikethrough: + self.quiet -= 1 + + def handle_tag(self, tag, attrs, start): + #attrs = fixattrs(attrs) + if attrs is None: + attrs = {} + else: + attrs = dict(attrs) + + if self.google_doc: + # the attrs parameter is empty for a closing tag. in addition, we + # need the attributes of the parent nodes in order to get a + # complete style description for the current element. we assume + # that google docs export well formed html. + parent_style = {} + if start: + if self.tag_stack: + parent_style = self.tag_stack[-1][2] + tag_style = element_style(attrs, self.style_def, parent_style) + self.tag_stack.append((tag, attrs, tag_style)) + else: + dummy, attrs, tag_style = self.tag_stack.pop() + if self.tag_stack: + parent_style = self.tag_stack[-1][2] + + if hn(tag): + self.p() + if start: + self.inheader = True + self.o(hn(tag)*"#" + ' ') + else: + self.inheader = False + return # prevent redundant emphasis marks on headers + + if tag in ['p', 'div']: + if self.google_doc: + if start and google_has_height(tag_style): + self.p() + else: + self.soft_br() + else: + self.p() + + if tag == "br" and start: self.o(" \n") + + if tag == "hr" and start: + self.p() + self.o("* * *") + self.p() + + if tag in ["head", "style", 'script']: + if start: self.quiet += 1 + else: self.quiet -= 1 + + if tag == "style": + if start: self.style += 1 + else: self.style -= 1 + + if tag in ["body"]: + self.quiet = 0 # sites like 9rules.com never close + + if tag == "blockquote": + if start: + self.p(); self.o('> ', 0, 1); self.start = 1 + self.blockquote += 1 + else: + self.blockquote -= 1 + self.p() + + if tag in ['em', 'i', 'u'] and not self.ignore_emphasis: self.o(self.emphasis_mark) + if tag in ['strong', 'b'] and not self.ignore_emphasis: self.o(self.strong_mark) + if tag in ['del', 'strike', 's']: + if start: + self.o("<"+tag+">") + else: + self.o("") + + if self.google_doc: + if not self.inheader: + # handle some font attributes, but leave headers clean + self.handle_emphasis(start, tag_style, parent_style) + + if tag in ["code", "tt"] and not self.pre: self.o('`') #TODO: `` `this` `` + if tag == "abbr": + if start: + self.abbr_title = None + self.abbr_data = '' + if has_key(attrs, 'title'): + self.abbr_title = attrs['title'] + else: + if self.abbr_title != None: + self.abbr_list[self.abbr_data] = self.abbr_title + self.abbr_title = None + self.abbr_data = '' + + if tag == "a" and not self.ignore_links: + if start: + if has_key(attrs, 'href') and not (self.skip_internal_links and attrs['href'].startswith('#')): + self.astack.append(attrs) + self.maybe_automatic_link = attrs['href'] + else: + self.astack.append(None) + else: + if self.astack: + a = self.astack.pop() + if self.maybe_automatic_link: + self.maybe_automatic_link = None + elif a: + if self.inline_links: + self.o("](" + escape_md(a['href']) + ")") + else: + i = self.previousIndex(a) + if i is not None: + a = self.a[i] + else: + self.acount += 1 + a['count'] = self.acount + a['outcount'] = self.outcount + self.a.append(a) + self.o("][" + str(a['count']) + "]") + + if tag == "img" and start and not self.ignore_images: + if has_key(attrs, 'src'): + attrs['href'] = attrs['src'] + alt = attrs.get('alt', '') + self.o("![" + escape_md(alt) + "]") + + if self.inline_links: + self.o("(" + escape_md(attrs['href']) + ")") + else: + i = self.previousIndex(attrs) + if i is not None: + attrs = self.a[i] + else: + self.acount += 1 + attrs['count'] = self.acount + attrs['outcount'] = self.outcount + self.a.append(attrs) + self.o("[" + str(attrs['count']) + "]") + + if tag == 'dl' and start: self.p() + if tag == 'dt' and not start: self.pbr() + if tag == 'dd' and start: self.o(' ') + if tag == 'dd' and not start: self.pbr() + + if tag in ["ol", "ul"]: + # Google Docs create sub lists as top level lists + if (not self.list) and (not self.lastWasList): + self.p() + if start: + if self.google_doc: + list_style = google_list_style(tag_style) + else: + list_style = tag + numbering_start = list_numbering_start(attrs) + self.list.append({'name':list_style, 'num':numbering_start}) + else: + if self.list: self.list.pop() + self.lastWasList = True + else: + self.lastWasList = False + + if tag == 'li': + self.pbr() + if start: + if self.list: li = self.list[-1] + else: li = {'name':'ul', 'num':0} + if self.google_doc: + nest_count = self.google_nest_count(tag_style) + else: + nest_count = len(self.list) + self.o(" " * nest_count) #TODO: line up
  1. s > 9 correctly. + if li['name'] == "ul": self.o(self.ul_item_mark + " ") + elif li['name'] == "ol": + li['num'] += 1 + self.o(str(li['num'])+". ") + self.start = 1 + + if tag in ["table", "tr"] and start: self.p() + if tag == 'td': self.pbr() + + if tag == "pre": + if start: + self.startpre = 1 + self.pre = 1 + else: + self.pre = 0 + self.p() + + def pbr(self): + if self.p_p == 0: + self.p_p = 1 + + def p(self): + self.p_p = 2 + + def soft_br(self): + self.pbr() + self.br_toggle = ' ' + + def o(self, data, puredata=0, force=0): + if self.abbr_data is not None: + self.abbr_data += data + + if not self.quiet: + if self.google_doc: + # prevent white space immediately after 'begin emphasis' marks ('**' and '_') + lstripped_data = data.lstrip() + if self.drop_white_space and not (self.pre or self.code): + data = lstripped_data + if lstripped_data != '': + self.drop_white_space = 0 + + if puredata and not self.pre: + data = re.sub('\s+', ' ', data) + if data and data[0] == ' ': + self.space = 1 + data = data[1:] + if not data and not force: return + + if self.startpre: + #self.out(" :") #TODO: not output when already one there + if not data.startswith("\n"): #
    stuff...
    +                    data = "\n" + data
    +
    +            bq = (">" * self.blockquote)
    +            if not (force and data and data[0] == ">") and self.blockquote: bq += " "
    +
    +            if self.pre:
    +                if not self.list:
    +                    bq += "    "
    +                #else: list content is already partially indented
    +                for i in xrange(len(self.list)):
    +                    bq += "    "
    +                data = data.replace("\n", "\n"+bq)
    +
    +            if self.startpre:
    +                self.startpre = 0
    +                if self.list:
    +                    data = data.lstrip("\n") # use existing initial indentation
    +
    +            if self.start:
    +                self.space = 0
    +                self.p_p = 0
    +                self.start = 0
    +
    +            if force == 'end':
    +                # It's the end.
    +                self.p_p = 0
    +                self.out("\n")
    +                self.space = 0
    +
    +            if self.p_p:
    +                self.out((self.br_toggle+'\n'+bq)*self.p_p)
    +                self.space = 0
    +                self.br_toggle = ''
    +
    +            if self.space:
    +                if not self.lastWasNL: self.out(' ')
    +                self.space = 0
    +
    +            if self.a and ((self.p_p == 2 and self.links_each_paragraph) or force == "end"):
    +                if force == "end": self.out("\n")
    +
    +                newa = []
    +                for link in self.a:
    +                    if self.outcount > link['outcount']:
    +                        self.out("   ["+ str(link['count']) +"]: " + urlparse.urljoin(self.baseurl, link['href']))
    +                        if has_key(link, 'title'): self.out(" ("+link['title']+")")
    +                        self.out("\n")
    +                    else:
    +                        newa.append(link)
    +
    +                if self.a != newa: self.out("\n") # Don't need an extra line when nothing was done.
    +
    +                self.a = newa
    +
    +            if self.abbr_list and force == "end":
    +                for abbr, definition in self.abbr_list.items():
    +                    self.out("  *[" + abbr + "]: " + definition + "\n")
    +
    +            self.p_p = 0
    +            self.out(data)
    +            self.outcount += 1
    +
    +    def handle_data(self, data):
    +        if r'\/script>' in data: self.quiet -= 1
    +
    +        if self.style:
    +            self.style_def.update(dumb_css_parser(data))
    +
    +        if not self.maybe_automatic_link is None:
    +            href = self.maybe_automatic_link
    +            if href == data and self.absolute_url_matcher.match(href):
    +                self.o("<" + data + ">")
    +                return
    +            else:
    +                self.o("[")
    +                self.maybe_automatic_link = None
    +
    +        if not self.code and not self.pre:
    +            data = escape_md_section(data, snob=self.escape_snob)
    +        self.o(data, 1)
    +
    +    def unknown_decl(self, data): pass
    +
    +    def charref(self, name):
    +        if name[0] in ['x','X']:
    +            c = int(name[1:], 16)
    +        else:
    +            c = int(name)
    +
    +        if not self.unicode_snob and c in unifiable_n.keys():
    +            return unifiable_n[c]
    +        else:
    +            try:
    +                return unichr(c)
    +            except NameError: #Python3
    +                return chr(c)
    +
    +    def entityref(self, c):
    +        if not self.unicode_snob and c in unifiable.keys():
    +            return unifiable[c]
    +        else:
    +            try: name2cp(c)
    +            except KeyError: return "&" + c + ';'
    +            else:
    +                try:
    +                    return unichr(name2cp(c))
    +                except NameError: #Python3
    +                    return chr(name2cp(c))
    +
    +    def replaceEntities(self, s):
    +        s = s.group(1)
    +        if s[0] == "#":
    +            return self.charref(s[1:])
    +        else: return self.entityref(s)
    +
    +    r_unescape = re.compile(r"&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
    +    def unescape(self, s):
    +        return self.r_unescape.sub(self.replaceEntities, s)
    +
    +    def google_nest_count(self, style):
    +        """calculate the nesting count of google doc lists"""
    +        nest_count = 0
    +        if 'margin-left' in style:
    +            nest_count = int(style['margin-left'][:-2]) / self.google_list_indent
    +        return nest_count
    +
    +
    +    def optwrap(self, text):
    +        """Wrap all paragraphs in the provided text."""
    +        if not self.body_width:
    +            return text
    +
    +        assert wrap, "Requires Python 2.3."
    +        result = ''
    +        newlines = 0
    +        for para in text.split("\n"):
    +            if len(para) > 0:
    +                if not skipwrap(para):
    +                    result += "\n".join(wrap(para, self.body_width))
    +                    if para.endswith('  '):
    +                        result += "  \n"
    +                        newlines = 1
    +                    else:
    +                        result += "\n\n"
    +                        newlines = 2
    +                else:
    +                    if not onlywhite(para):
    +                        result += para + "\n"
    +                        newlines = 1
    +            else:
    +                if newlines < 2:
    +                    result += "\n"
    +                    newlines += 1
    +        return result
    +
    +ordered_list_matcher = re.compile(r'\d+\.\s')
    +unordered_list_matcher = re.compile(r'[-\*\+]\s')
    +md_chars_matcher = re.compile(r"([\\\[\]\(\)])")
    +md_chars_matcher_all = re.compile(r"([`\*_{}\[\]\(\)#!])")
    +md_dot_matcher = re.compile(r"""
    +    ^             # start of line
    +    (\s*\d+)      # optional whitespace and a number
    +    (\.)          # dot
    +    (?=\s)        # lookahead assert whitespace
    +    """, re.MULTILINE | re.VERBOSE)
    +md_plus_matcher = re.compile(r"""
    +    ^
    +    (\s*)
    +    (\+)
    +    (?=\s)
    +    """, flags=re.MULTILINE | re.VERBOSE)
    +md_dash_matcher = re.compile(r"""
    +    ^
    +    (\s*)
    +    (-)
    +    (?=\s|\-)     # followed by whitespace (bullet list, or spaced out hr)
    +                  # or another dash (header or hr)
    +    """, flags=re.MULTILINE | re.VERBOSE)
    +slash_chars = r'\`*_{}[]()#+-.!'
    +md_backslash_matcher = re.compile(r'''
    +    (\\)          # match one slash
    +    (?=[%s])      # followed by a char that requires escaping
    +    ''' % re.escape(slash_chars),
    +    flags=re.VERBOSE)
    +
    +def skipwrap(para):
    +    # If the text begins with four spaces or one tab, it's a code block; don't wrap
    +    if para[0:4] == '    ' or para[0] == '\t':
    +        return True
    +    # If the text begins with only two "--", possibly preceded by whitespace, that's
    +    # an emdash; so wrap.
    +    stripped = para.lstrip()
    +    if stripped[0:2] == "--" and len(stripped) > 2 and stripped[2] != "-":
    +        return False
    +    # I'm not sure what this is for; I thought it was to detect lists, but there's
    +    # a 
    -inside- case in one of the tests that also depends upon it. + if stripped[0:1] == '-' or stripped[0:1] == '*': + return True + # If the text begins with a single -, *, or +, followed by a space, or an integer, + # followed by a ., followed by a space (in either case optionally preceeded by + # whitespace), it's a list; don't wrap. + if ordered_list_matcher.match(stripped) or unordered_list_matcher.match(stripped): + return True + return False + +def wrapwrite(text): + text = text.encode('utf-8') + try: #Python3 + sys.stdout.buffer.write(text) + except AttributeError: + sys.stdout.write(text) + +def html2text(html, baseurl=''): + h = HTML2Text(baseurl=baseurl) + return h.handle(html) + +def unescape(s, unicode_snob=False): + h = HTML2Text() + h.unicode_snob = unicode_snob + return h.unescape(s) + +def escape_md(text): + """Escapes markdown-sensitive characters within other markdown constructs.""" + return md_chars_matcher.sub(r"\\\1", text) + +def escape_md_section(text, snob=False): + """Escapes markdown-sensitive characters across whole document sections.""" + text = md_backslash_matcher.sub(r"\\\1", text) + if snob: + text = md_chars_matcher_all.sub(r"\\\1", text) + text = md_dot_matcher.sub(r"\1\\\2", text) + text = md_plus_matcher.sub(r"\1\\\2", text) + text = md_dash_matcher.sub(r"\1\\\2", text) + return text + + +def main(): + baseurl = '' + + p = optparse.OptionParser('%prog [(filename|url) [encoding]]', + version='%prog ' + __version__) + p.add_option("--ignore-emphasis", dest="ignore_emphasis", action="store_true", + default=IGNORE_EMPHASIS, help="don't include any formatting for emphasis") + p.add_option("--ignore-links", dest="ignore_links", action="store_true", + default=IGNORE_ANCHORS, help="don't include any formatting for links") + p.add_option("--ignore-images", dest="ignore_images", action="store_true", + default=IGNORE_IMAGES, help="don't include any formatting for images") + p.add_option("-g", "--google-doc", action="store_true", dest="google_doc", + default=False, help="convert an html-exported Google Document") + p.add_option("-d", "--dash-unordered-list", action="store_true", dest="ul_style_dash", + default=False, help="use a dash rather than a star for unordered list items") + p.add_option("-e", "--asterisk-emphasis", action="store_true", dest="em_style_asterisk", + default=False, help="use an asterisk rather than an underscore for emphasized text") + p.add_option("-b", "--body-width", dest="body_width", action="store", type="int", + default=BODY_WIDTH, help="number of characters per output line, 0 for no wrap") + p.add_option("-i", "--google-list-indent", dest="list_indent", action="store", type="int", + default=GOOGLE_LIST_INDENT, help="number of pixels Google indents nested lists") + p.add_option("-s", "--hide-strikethrough", action="store_true", dest="hide_strikethrough", + default=False, help="hide strike-through text. only relevant when -g is specified as well") + p.add_option("--escape-all", action="store_true", dest="escape_snob", + default=False, help="Escape all special characters. Output is less readable, but avoids corner case formatting issues.") + (options, args) = p.parse_args() + + # process input + encoding = "utf-8" + if len(args) > 0: + file_ = args[0] + if len(args) == 2: + encoding = args[1] + if len(args) > 2: + p.error('Too many arguments') + + if file_.startswith('http://') or file_.startswith('https://'): + baseurl = file_ + j = urllib.urlopen(baseurl) + data = j.read() + if encoding is None: + try: + from feedparser import _getCharacterEncoding as enc + except ImportError: + enc = lambda x, y: ('utf-8', 1) + encoding = enc(j.headers, data)[0] + if encoding == 'us-ascii': + encoding = 'utf-8' + else: + data = open(file_, 'rb').read() + if encoding is None: + try: + from chardet import detect + except ImportError: + detect = lambda x: {'encoding': 'utf-8'} + encoding = detect(data)['encoding'] + else: + data = sys.stdin.read() + + data = data.decode(encoding) + h = HTML2Text(baseurl=baseurl) + # handle options + if options.ul_style_dash: h.ul_item_mark = '-' + if options.em_style_asterisk: + h.emphasis_mark = '*' + h.strong_mark = '__' + + h.body_width = options.body_width + h.list_indent = options.list_indent + h.ignore_emphasis = options.ignore_emphasis + h.ignore_links = options.ignore_links + h.ignore_images = options.ignore_images + h.google_doc = options.google_doc + h.hide_strikethrough = options.hide_strikethrough + h.escape_snob = options.escape_snob + + wrapwrite(h.handle(data)) + + +if __name__ == "__main__": + main() diff --git a/RPI Code/Arlo/dev/rev.py b/RPI Code/Arlo/dev/rev.py new file mode 100644 index 0000000..e887341 --- /dev/null +++ b/RPI Code/Arlo/dev/rev.py @@ -0,0 +1,23 @@ +import fileinput +import os +import re +import sys + +if(len(sys.argv) != 2 or not os.path.isfile(sys.argv[1])): + print("Usage: {0} ".format(os.path.basename(sys.argv[0]))) + sys.exit(1) + +pattern = re.compile("\s*version='([0-9.]+)',") +line = "" +maj = "" +min = "" +ver = "" + +for line in fileinput.FileInput(sys.argv[1], inplace=1): + m = pattern.match(line) + if m: + version = m.groups()[0] + maj, min, rev = version.split('.') + line = line.replace(version, "{0}.{1}.{2}".format(maj, min, int(rev)+1)) + + sys.stdout.write(line) diff --git a/RPI Code/Arlo/docs/README.md b/RPI Code/Arlo/docs/README.md new file mode 100644 index 0000000..c9d04b9 --- /dev/null +++ b/RPI Code/Arlo/docs/README.md @@ -0,0 +1,1160 @@ +# `arlo` module + +Copyright 2016 Jeffrey D. Walter + +Licensed under the Apache License, Version 2.0 (the "License"); you may not +use this file except in compliance with the License. You may obtain a copy of +the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS ISBASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations under +the License. + +## Classes + +` class Arlo ` + + + +### Class variables + +`var TRANSID_PREFIX` + + + +### Methods + +` def __init__(self, username, password) ` + + + +Initialize self. See help(type(self)) for accurate signature. + +` def AddFriend(self, firstname, lastname, email, devices={}, admin=False) ` + + + +This API will send an email to a user and if they accept, will give them +access to the devices you specify. NOTE: XXX-XXXXXXX_XXXXXXXXXXXX is the +uniqueId field in your device object. + +{adminUser:false,firstName:John,lastName:Doe,email:john.doe@example.com,device +s:{XXX-XXXXXXX_XXXXXXXXXXXX:Camera1,XXX-XXXXXXX_XXXXXXXXXXXX:Camera2}} + +` def AdjustBrightness(self, basestation, camera, brightness=0) ` + + + +NOTE: Brightness is between -2 and 2 in increments of 1 (-2, -1, 0, 1, 2). +Setting it to an invalid value has no effect. + +Returns: { "action": "is", "from": "XXXXXXXXXXXXX", "properties": { +"brightness": -2 }, "resource": "cameras/XXXXXXXXXXXXX", "to": +"336-XXXXXXX_web", "transId": "web!XXXXXXXX.389518!1514956240683" } + +` def AlertNotificationMethods(self, basestation, action='disabled', +email=False, push=False) ` + + + +**`action`** : `disabled` `OR` `recordSnapshot` `OR` `recordVideo` + +` def Arm(self, device) ` + + +` def BatchDeleteRecordings(self, recordings) ` + + + +Delete a batch of video recordings from Arlo. + +The GetLibrary() call response json can be passed directly to this method if +you'd like to delete the same list of videos you queried for. If you want to +delete some other batch of videos, then you need to send an array of objects +representing each video you want to delete. + +[ { "createdDate":"20160904", "utcCreatedDate":1473010280395, +"deviceId":"XXXXXXXXXXXXX" }, { "createdDate":"20160904", +"utcCreatedDate":1473010280395, "deviceId":"XXXXXXXXXXXXX" } ] + +` def Calendar(self, basestation, active=True) ` + + + +DEPRECATED: This API appears to still do stuff, but I don't see it called in +the web UI anymore when switching the mode to a schedule. + +NOTE: The Arlo API seems to disable calendar mode when switching to other +modes, if it's enabled. You should probably do the same, although, the UI +reflects the switch from calendar mode to say armed mode without explicitly +setting calendar mode to inactive. + +` def CustomMode(self, device, mode, schedules=[]) ` + + + +device can be any object that has parentId == deviceId. i.e., not a camera + +` def DeleteMode(self, device, mode) ` + + + +device can be any object that has parentId == deviceId. i.e., not a camera + +` def DeleteRecording(self, recording) ` + + + +Delete a single video recording from Arlo. All of the date info and device id +you need to pass into this method are given in the results of the GetLibrary() +call. + +` def Disarm(self, device) ` + + +` def DownloadRecording(self, url, to) ` + + + +Writes a video to a given local file path. + +**`url`** : `presignedContentUrl` + +**`to`** : `path` `where` `the` `file` `should` `be` `written` + +` def DownloadSnapshot(self, url, to, chunk_size=4096) ` + + + +Writes a snapshot to a given local file path. + +**`url`** : `presignedContentUrl` or `presignedFullFrameSnapshotUrl` + +**`to`** : `path` `where` `the` `file` `should` `be` `written` + +` def Geofencing(self, location_id, active=True) ` + + + +Get location_id is the id field from the return of GetLocations() NOTE: The +Arlo API seems to disable geofencing mode when switching to other modes, if +it's enabled. You should probably do the same, although, the UI reflects the +switch from calendar mode to say armed mode without explicitly setting +calendar mode to inactive. + +` def GetAudioPlayback(self, basestation) ` + + +` def GetAutomationActivityZones(self, camera) ` + + +` def GetAutomationDefinitions(self) ` + + +` def GetBaseStationState(self, basestation) ` + + +` def GetCalendar(self, basestation) ` + + +` def GetCameraState(self, basestation) ` + + +` def GetCameraTempReading(self, basestation) ` + + +` def GetCvrPlaylist(self, camera, fromDate, toDate) ` + + + +This function downloads a Cvr Playlist file for the period fromDate to toDate. + +` def GetDeviceCapabilities(self, device) ` + + +` def GetDeviceSupport(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +This API looks like it's mainly used by the website, but I'm including it for +completeness sake. It returns something like the following: { "devices": [ { +"deviceType": "arloq", "urls": { "troubleshoot": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/pc_troubleshoot.html", "plugin": +"https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_plugin.html", +"connection": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/pc_connection.html", +"connectionFailed": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/pc_connection_fail.html", "press_sync": +"https://vzs3-prod-common.s3. +amazonaws.com/static/html/en/pc_press_sync.html", "resetDevice": "https://vzs3 +-prod-common.s3.amazonaws.com/static/html/en/reset_arloq.html", "qr_how_to": +"https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_qr_how_to.html" } +}, { "deviceType": "basestation", "urls": { "troubleshoot": "https://vzs3 +-prod-common.s3.amazonaws.com/static/html/en/bs_troubleshoot.html", +"connection": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/bs_connection.html", "sync": +"https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_sync_camera.html" +} }, { "deviceType": "arloqs", "urls": { "ethernetSetup": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/ethernet_setup.html", "plugin": +"https:// vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/aqp_plugin.html", +"connectionWiFi": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/ar +loqs/connection_in_progress_wifi.html", "poeSetup": "https://vzs3-prod- +common.s3. amazonaws.com/static/html/en/arloqs/poe_setup.html", "connection": +"https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/connection_in_progress.html", +"connectionFailed": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/connection_fail.html", +"press_sync": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/press_sync.html", +"connectionType": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/connection_type.html", +"resetDevice": "https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/reset_device.html", "qr_how_to": +"https://vzs3-prod- +common.s3.amazonaws.com/static/html/en/arloqs/qr_how_to.html" } } ] } + +` def GetDeviceSupportV3(self) ` + + + +This is the latest version of the device support api. It returns something +like the following: { "data": { "devices": { "camera": { "modelIds": [ +"VMC3010", "VMC3030", "VMC4030", "VMC4030P", "VMC5040", "VZC3010", "VZC3030" +], "connectionTypes": { "WPS": true, "BLE": true }, "kbArticles": { +"insertBatteries": "https://kb.arlo.com/980150/Safety-Rules-for-Arlo-Wire- +Free-Camera-Batteries", "syncBasestation": "https://kb.arlo.com/987/How-do-I +-set-up-and-sync-my-Arlo-Wire-Free-cameras", "sync": "https://kb.arlo.com/987 +/How-do-I-set-up-and-sync-my-Arlo-Wire-Free-camera", "firmwareUpdate": +"https://kb.arlo.com/4736/How-do-I-update-my-Arlo-firmware-manually" } }, +"arloq": { "modelIds": [ "VMC3040", "VMC3040S" ], "kbArticles": { "power": +"https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", "qrCode": +"https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", "power_android": +"https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on-Android", +"qrCode_android": "https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on- +Android" } }, "basestation": { "modelIds": [ "VMB3010", "VMB4000", +"VMB3010r2", "VMB3500", "VZB3010", "VMB4500", "VMB5000" ], "smartHubs": [ +"VMB5000" ], "kbArticles": { "pluginNetworkCable": +"https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base- +station-to-the-Internet", "power": "https://kb.arlo.com/1179139/How-do-I +-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", "led": +"https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base- +station-to-the-Internet", "learnMore": "https://kb.arlo.com/000062124/How-do-I +-record-4K-videos-to-a-microSD-card" } }, "arlobaby": { "modelIds": [ +"ABC1000" ], "kbArticles": { "power": "https://kb.arlo.com/1282682/How-do-I +-power-cycle-my-Arlo-Baby-camera", "qrCode": "https://kb.arlo.com/1282700/How- +do-I-set-up-my-Arlo-Baby-camera" } }, "lteCamera":{ "modelIds":[ "VML4030" ], +"kbArticles":{ "servicePlan":"https://kb.arlo.com/1286865/What-Arlo-Mobile- +service-plans-are-available", "simActivation":"https://kb.arlo.com/1286865 +/What-Arlo-Mobile-service-plans-are-available", +"qrCode":"https://kb.arlo.com/1201822/How-do-I-set-up-my-Arlo-Go-camera" } }, +"bridge": { "modelIds": [ "ABB1000" ], "kbArticles": { "power": +"https://kb.arlo.com/000062047", "sync": "https://kb.arlo.com/000062037", +"qrCode": "https://kb.arlo.com/000061886", "factoryReset": +"https://kb.arlo.com/000061837" } }, "lights": { "modelIds": [ "AL1101" ], +"kbArticles": { "sync": "https://kb.arlo.com/000062005", "insertBatteries": +"https://kb.arlo.com/000061952", "qrCode": "https://kb.arlo.com/000061886" } +}, "routerM1":{ "modelIds":[ "MR1100" ], "kbArticles":{ +"lookupFailed":"https://kb.arlo.com/1179130/Arlo-can-t-discover-my-base- +station-during-installation-what-do-I-do" } }, "chime": { "modelIds": [ +"AC1001" ], "kbArticles": { "ledNotBlinking":"https://kb.arlo.com/000061924", +"led":"https://kb.arlo.com/000061847", +"factoryReset":"https://kb.arlo.com/000061879", +"connectionFailed":"https://kb.arlo.com/000061880" } }, "doorbell": { +"modelIds": [ "AAD1001" ], "kbArticles": { +"led":"https://kb.arlo.com/000061847", +"factoryReset":"https://kb.arlo.com/000061842", +"pairCamera":"https://kb.arlo.com/000061897", +"existingChime":"https://kb.arlo.com/000061856", +"noWiring":"https://kb.arlo.com/000061859", +"connectionFailed":"https://kb.arlo.com/000061868", +"pairCameraFailed":"https://kb.arlo.com/000061893", +"testChimeFailed":"https://kb.arlo.com/000061944" }, "videos": { "chimeType": +"https://youtu.be/axytuF63VC0", "wireDoorbell": +"https://youtu.be/_5D2n3iPqW0", "switchSetting": +"https://youtu.be/BUmd4fik2RE" }, "arloVideos": { "chimeType": "https://vzs3 +-prod- +common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Chime.mp4", +"wireDoorbell": "https://vzs3-prod- +common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Wired.mp4", +"switchSetting": "https://vzs3-prod- +common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Switch.mp4" } +} }, "arlosmart": { "kbArticles": { "e911": "https://www.arlo.com/en- +us/landing/arlosmart/", "callFriend": "https://www.arlo.com/en- +us/landing/arlosmart/", "4kAddOnPopup": "https://www.arlo.com/en- +us/landing/arlosmart/", "cloudRecording": "https://www.arlo.com/en- +us/landing/arlosmart/", "manageArloSmart": "https://kb.arlo.com/000062115", +"otherVideo": "https://kb.arlo.com/000062115", "packageDetection": +"https://kb.arlo.com/000062114", "whereIsBasicSubscriptionGone": +"https://kb.arlo.com/000062163" } } }, "success":true } + +` def GetDeviceSupportv2(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +It returns something like the following: { "devices": [ { "deviceType": +"arloq", "modelId": [ "VMC3040" ], "urls": { "troubleshoot": +"arloq/troubleshoot.html", "plugin": "arloq/plugin.html", "qrHowTo": +"arloq/qrHowTo.html", "connection": "arloq/connection.html", +"connectionInProgress": "arloq/connectionInProgress.html", "connectionFailed": +"arloq/connectionFailed.html", "pressSync": "arloq/pressSync.html", +"resetDevice": "arloq/resetDevice.html" } }, { "deviceType": "basestation", +"modelId": [ "VMB3010", "VMB3010r2", "VMB3500", "VMB4000", "VMB4500", +"VZB3010" ], "urls": { "troubleshoot": "basestation/troubleshoot.html", +"plugin": "basestation/plugin.html", "sync3": "basestation/sync3.html", +"troubleshootBS": "basestation/troubleshootBS.html", "connection": +"basestation/connection.html", "connectionInProgress": +"basestation/connectionInProgress.html", "sync2": "basestation/sync2.html", +"connectionFailed": "basestation/connectionFailed.html", "sync1": +"basestation/sync1.html", "resetDevice": "basestation/resetDevice.html", +"syncComplete": "basestation/syncComplete.html" } }, { "deviceType": +"arlobaby", "modelId": [ "ABC1000" ], "urls": { "bleSetupError": +"arlobaby/bleSetupError.html", "troubleshoot": "arlobaby/troubleshoot.html", +"homekitCodeInstruction": "arlobaby/homekitCodeInstruction.html", +"connectionInProgress": "arlobaby/connectionInProgress.html", +"connectionFailed": "arlobaby/connectionFailed.html", "resetDevice": +"arlobaby/resetDevice.html", "plugin": "arlobaby/plugin.html", "qrHowTo": +"arlobaby/qrHowTo.html", "warning": "arlobaby/warning.html", "connection": +"arlobaby/connection.html", "pressSync": "arlobaby/pressSync.html", +"bleInactive": "arlobaby/bleInactive.html", "pluginIOS": +"arlobaby/pluginIOS.html", "homekitSetup": "arlobaby/homekitSetup.html" } }, { +"deviceType": "lteCamera", "modelId": [ "VML4030" ], "urls": { "troubleshoot": +"lteCamera/troubleshoot.html", "resetHowTo": "lteCamera/resetHowTo.html", +"plugin": "lteCamera/plugin.html", "qrHowTo": "lteCamera/qrHowTo.html", +"connectionInProgress": "lteCamera/connectionInProgress.html", +"connectionFailed": "lteCamera/connectionFailed.html", "resetDevice": +"lteCamera/resetHowTo.html", "resetComplete": "lteCamera/resetComplete.html", +"syncComplete": "lteCamera/syncComplete.html" } }, { "deviceType": "arloqs", +"modelId": [ "VMC3040S" ], "urls": { "ethernetSetup": +"arloqs/ethernetSetup.html", "troubleshoot": "arloqs/troubleshoot.html", +"plugin": "arloqs/plugin.html", "poeSetup": "arloqs/poeSetup.html", +"connectionInProgressWiFi": "arloqs/connectionInProgressWifi.html", "qrHowTo": +"arloqs/qrHowTo.html", "connectionInProgress": +"arloqs/connectionInProgress.html", "connectionFailed": +"arloqs/connectionFailed.html", "pressSync": "arloqs/pressSync.html", +"connectionType": "arloqs/connectionType.html", "resetDevice": +"arloqs/resetDevice.html" } }, { "deviceType": "bridge", "modelId": [ +"ABB1000" ], "urls": { "troubleshoot": "bridge/troubleshoot.html", +"fwUpdateInProgress": "bridge/fwUpdateInProgress.html", "qrHowToUnplug": +"bridge/qrHowToUnplug.html", "fwUpdateDone": "bridge/fwUpdateDone.html", +"fwUpdateAvailable": "bridge/fwUpdateAvailable.html", "needHelp": +"https://www.arlo.com/en-us/support/#support_arlo_light", "wifiError": +"bridge/wifiError.html", "bleAndroid": "bridge/bleInactiveAND.html", "bleIOS": +"bridge/bleInactiveIOS.html", "connectionInProgress": +"bridge/connectionInProgress.html", "connectionFailed": +"bridge/connectionFailed.html", "manualPair": "bridge/manualPairing.html", +"resetDevice": "bridge/resetDevice.html", "lowPower": +"bridge/lowPowerZoneSetup.html", "fwUpdateFailed": +"bridge/fwUpdateFailed.html", "fwUpdateCheckFailed": +"bridge/fwUpdateCheckFailed.html", "plugin": "bridge/plugin.html", "qrHowTo": +"bridge/qrHowTo.html", "pressSync": "bridge/pressSync.html", "pluginNoLED": +"bridge/pluginNoLED.html", "fwUpdateCheck": "bridge/fwUpdateCheck.html" } }, { +"deviceType": "lights", "modelId": [ "AL1101" ], "urls": { "troubleshoot": +"lights/troubleshoot.html", "needHelp": "https://kb.netgear.com/000053159 +/Light-discovery-failed.html", "bleInactiveAND": "lights/bleInactiveAND.html", +"connectionInProgress": "lights/connectionInProgress.html", +"connectionFailed": "lights/connectionFailed.html", "addBattery": +"lights/addBattery.html", "tutorial1": "lights/tutorial1.html", "plugin": +"lights/plugin.html", "tutorial2": "lights/tutorial2.html", "tutorial3": +"lights/tutorial3.html", "configurationInProgress": +"lights/configurationInProgress.html", "qrHowTo": "lights/qrHowTo.html", +"pressSync": "lights/pressSync.html", "bleInactiveIOS": +"lights/bleInactiveIOS.html", "syncComplete": "lights/syncComplete.html" } }, +{ "deviceType": "routerM1", "modelId": [ "MR1100" ], "urls": { "troubleshoot": +"routerM1/troubleshoot.html", "help": "routerM1/help.html", "pairingFailed": +"routerM1/pairingFailed.html", "needHelp": +"https://acupdates.netgear.com/help/redirect.aspx?url=m1arlo-kbb", "plugin": +"routerM1/plugin.html", "pairing": "routerM1/pairing.html", +"connectionInProgress": "routerM1/connectionInProgress.html", "sync2": +"routerM1/sync2.html", "connectionFailed": "routerM1/connectionFailed.html", +"sync1": "routerM1/sync1.html", "sync": "routerM1/sync.html", "syncComplete": +"routerM1/syncComplete.html" } } ], "selectionUrls": { "addDevice": +"addDeviceBsRuAqAqpLteAbcMrBgLt.html", "selectBasestation": "selectBsMr.html", +"deviceSelection": "deviceBsAqAqpLteAbcMrLtSelection.html", "selectLights": +"selectBgLt.html" }, "baseUrl": "https://vzs3-prod- +common.s3.amazonaws.com/static/v2/html/en/" } + +` def GetDevices(self, device_type=None, filter_provisioned=None) ` + + + +This method returns an array that contains the basestation, cameras, etc. and +their metadata. If you pass in a valid device type, as a string or a list, +this method will return an array of just those devices that match that type. +An example would be ['basestation', 'camera'] To filter provisioned or +unprovisioned devices pass in a True/False value for filter_provisioned. By +default both types are returned. + +` def GetEmergencyLocations(self) ` + + +` def GetFriends(self) ` + + +` def GetLibrary(self, from_date, to_date) ` + + + +This call returns the following: presignedContentUrl is a link to the actual +video in Amazon AWS. presignedThumbnailUrl is a link to the thumbnail .jpg of +the actual video in Amazon AWS. + +[ { "mediaDurationSecond": 30, "contentType": "video/mp4", "name": +"XXXXXXXXXXXXX", "presignedContentUrl": +"https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX +/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX.mp4?AWSAccessKeyId=XXXXXXX +XXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XX", "lastModified": 1472881430181, "localCreatedDate": XXXXXXXXXXXXX, +"presignedThumbnailUrl": +"https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX +/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX_thumb.jpg?AWSAccessKeyId=X +XXXXXXXXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX +XXXXXXXX", "reason": "motionRecord", "deviceId": "XXXXXXXXXXXXX", "createdBy": +"XXXXXXXXXXXXX", "createdDate": "20160903", "timeZone": "America/Chicago", +"ownerId": "XXX-XXXXXXX", "utcCreatedDate": XXXXXXXXXXXXX, "currentState": +"new", "mediaDuration": "00:00:30" } ] + +` def GetLibraryMetaData(self, from_date, to_date) ` + + +` def GetLocations(self) ` + + + +This call returns the following: { "id":"XXX-XXXXXXX_20160823042047", +"name":"Home", "ownerId":"XXX-XXXXXXX", "longitude":X.XXXXXXXXXXXXXXXX, +"latitude":X.XXXXXXXXXXXXXXXX, "address":"123 Middle Of Nowhere Bumbfuck, EG, +12345", "homeMode":"schedule", "awayMode":"mode1", "geoEnabled":false, +"geoRadius":150.0, "uniqueIds":[ "XXX-XXXXXXX_XXXXXXXXXXXXX" ], +"smartDevices":[ "XXXXXXXXXX", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ], +"pushNotifyDevices":[ "XXXXXXXXXX" ] } + +` def GetModes(self, basestation) ` + + + +DEPRECATED: This is the older API for getting the "mode". It still works, but +GetModesV2 is the way the Arlo software does it these days. + +` def GetModesV2(self) ` + + + +This is the newer API for getting the "mode". This method also returns the +schedules. Set a non-schedule mode to be active: {"activeAutomations":[{"devic +eId":"XXXXXXXXXXXXX","timestamp":1532015622105,"activeModes":["mode1"],"active +Schedules":[]}]} Set a schedule to be active: {"activeAutomations":[{"deviceId +":"XXXXXXXXXXXXX","timestamp":1532015790139,"activeModes":[],"activeSchedules" +:["schedule.1"]}]} + +` def GetOCProfile(self) ` + + +` def GetPaymentBilling(self) ` + + +` def GetPaymentOffers(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +` def GetPaymentOffersV2(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +` def GetPaymentOffersV3(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +` def GetPaymentOffersV4(self) ` + + +` def GetProfile(self) ` + + +` def GetRecording(self, url, chunk_size=4096) ` + + + +Returns the whole video from the presignedContentUrl. + +` def GetRules(self, basestation) ` + + +` def GetSensorConfig(self, basestation) ` + + +` def GetServiceLevel(self) ` + + +` def GetServiceLevelSettings(self) ` + + +` def GetServiceLevelV2(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +` def GetServiceLevelV3(self) ` + + + +DEPRECATED: This API still works, but I don't see it being called in the web +UI anymore. + +` def GetServiceLevelV4(self) ` + + +` def GetSession(self) ` + + + +Returns something like the following: { "userId": "XXX-XXXXXXX", "email": +"jeffreydwalter@gmail.com", "token": +"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "paymentId": +"XXXXXXXX", "accountStatus": "registered", "serialNumber": "XXXXXXXXXXXXXX", +"countryCode": "US", "tocUpdate": false, "policyUpdate": false, "validEmail": +true, "arlo": true, "dateCreated": 1463975008658 } + +` def GetSmartAlerts(self, camera) ` + + +` def GetSmartFeatures(self) ` + + +` def GetUpdateFeatures(self) ` + + +` def HandleEvents(self, basestation, callback, timeout=120) ` + + + +Use this method to subscribe to the event stream and provide a callback that +will be called for event event received. This function will allow you to +potentially write a callback that can handle all of the events received from +the event stream. + +` def Login(self, username, password) ` + + + +This call returns the following: { "userId":"XXX-XXXXXXX", +"email":"user@example.com", "token":"2_5HicFJMXXXXX-S_7IuK2EqOUHXXXXXXXXXXX1CX +KWTThgU18Va_XXXXXX5S00hUafv3PV_if_Bl_rhiFsDHYwhxI3CxlVnR5f3q2XXXXXX- +Wnt9F7D82uN1f4cXXXXX-FMUsWF_6tMBqwn6DpzOaIB7ciJrnr2QJyKewbQouGM6", +"paymentId":"XXXXXXXX", "authenticated":1472961381, +"accountStatus":"registered", "serialNumber":"XXXXXXXXXXXXX", +"countryCode":"US", "tocUpdate":false, "policyUpdate":false, "validEmail":true +} + +` def Logout(self) ` + + +` def Notify(self, basestation, body) ` + + + +The following are examples of the json you would need to pass in the body of +the Notify() call to interact with Arlo: + +###### + +###### + +**`NOTE`** : `While` `you` `can` `call` `Notify`() `directly`, `responses` `from` `these` `notify` `calls` `are` `sent` `to` `the` `EventStream` (`see` `Subscribe`()), + + +and so it's better to use the Get/Set methods that are implemented using the +NotifyAndGetResponse() method. + +###### + +###### + +Set System Mode (Armed, Disarmed) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXX +XXX","action":"set","resource":"modes","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXX +XXXXX","publishResponse":true,"properties":{"active":"mode0"}} Set System Mode +(Calendar) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","re +source":"schedule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishRespo +nse":true,"properties":{"active":true}} Configure The Schedule (Calendar) - +{"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"sche +dule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"pr +operties":{"schedule":[{"modeId":"mode0","startTime":0},{"modeId":"mode2","sta +rtTime":28800000},{"modeId":"mode0","startTime":64800000},{"modeId":"mode0","s +tartTime":86400000},{"modeId":"mode2","startTime":115200000},{"modeId":"mode0" +,"startTime":151200000},{"modeId":"mode0","startTime":172800000},{"modeId":"mo +de2","startTime":201600000},{"modeId":"mode0","startTime":237600000},{"modeId" +:"mode0","startTime":259200000},{"modeId":"mode2","startTime":288000000},{"mod +eId":"mode0","startTime":324000000},{"modeId":"mode0","startTime":345600000},{ +"modeId":"mode2","startTime":374400000},{"modeId":"mode0","startTime":41040000 +0},{"modeId":"mode0","startTime":432000000},{"modeId":"mode0","startTime":5184 +00000}]} Create Mode - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action" +:"add","resource":"rules","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publi +shResponse":true,"properties":{"name":"Record video on Camera 1 if Camera 1 +detects motion","id":"ruleNew","triggers":[{"type":"pirMotionActive","deviceId +":"XXXXXXXXXXXXX","sensitivity":80}],"actions":[{"deviceId":"XXXXXXXXXXXXX","t +ype":"recordVideo","stopCondition":{"type":"timeout","timeout":15}},{"type":"s +endEmailAlert","recipients":["**OWNER_EMAIL**"]},{"type":"pushNotification"}]} +} {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"add","resource":"mo +des","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"pro +perties":{"name":"Test","rules":["rule3"]}} Delete Mode - {"from":"XXX-XXXXXXX +_web","to":"XXXXXXXXXXXXX","action":"delete","resource":"modes/mode3","transId +":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true} Camera Off - +{"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"came +ras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishRespo +nse":true,"properties":{"privacyActive":false}} Night Vision On - {"from +":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XX +XXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":t +rue,"properties":{"zoom":{"topleftx":0,"toplefty":0,"bottomrightx":1280,"botto +mrighty":720},"mirror":true,"flip":true,"nightVisionMode":1,"powerSaveMode":2} +} Motion Detection Test - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","acti +on":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXX +XXXXXXXXXXX","publishResponse":true,"properties":{"motionSetupModeEnabled":tru +e,"motionSetupModeSensitivity":80}} + +device_id = locations.data.uniqueIds + +System Properties: ("resource":"modes") active (string) - Mode Selection +(mode2 = All Motion On, mode1 = Armed, mode0 = Disarmed, etc.) + +System Properties: ("resource":"schedule") active (bool) - Mode Selection +(true = Calendar) + +Camera Properties: ("resource":"cameras/{id}") privacyActive (bool) - Camera +On/Off zoom (topleftx (int), toplefty (int), bottomrightx (int), bottomrighty +(int)) - Camera Zoom Level mirror (bool) - Mirror Image (left-to-right or +right-to-left) flip (bool) - Flip Image Vertically nightVisionMode (int) - +Night Mode Enabled/Disabled (1, 0) powerSaveMode (int) - PowerSaver Mode (3 = +Best Video, 2 = Optimized, 1 = Best Battery Life) motionSetupModeEnabled +(bool) - Motion Detection Setup Enabled/Disabled motionSetupModeSensitivity +(int 0-100) - Motion Detection Sensitivity + +` def NotifyAndGetResponse(self, basestation, body, timeout=120) ` + + +` def PauseTrack(self, basestation) ` + + +` def Ping(self, basestation) ` + + +` def PlayTrack(self, basestation, +track_id='2391d620-e491-4412-99f6-e9a40d6046ed', position=0) ` + + + +Defaulting to 'hugh little baby', which is a supplied track. I hope the ID is +the same for all. + +` def PushToTalk(self, camera) ` + + +` def RemoveFriend(self, email) ` + + + +Removes a person you've granted access to. + +email: email of user you want to revoke access from. + +` def ResendFriendInvite(self, friend) ` + + + +This API will resend an invitation email to a user that you've AddFriend'd. +You will need to get the friend object by calling GetFriend() because it +includes a token that must be passed to this API. + +**`friend`** : {`"ownerId"`:`"XXX`-`XXXXXXX"`,`"token"`:`"really` `long` `string` `that` `you` `get` `from` `the` `GetFriends`() `API"`,`"firstName"`:`"John"`,`"lastName"`:`"Doe"`,`"devices"`:{`"XXX`-`XXXXXXX_XXXXXXXXXXXX"`:`"Camera1"`,`"XXX`-`XXXXXXX_XXXXXXXXXXXX"`:`"Camera2"`},`"lastModified"`:`1548470485419`,`"adminUser"`:`false`,`"email"`:`"john.doe`@`example.com"`} + +` def Reset(self) ` + + +` def RestartBasestation(self, basestation) ` + + +` def SetAirQualityAlertOff(self, basestation) ` + + +` def SetAirQualityAlertOn(self, basestation) ` + + +` def SetAirQualityAlertThresholdMax(self, basestation, number=700) ` + + +` def SetAirQualityAlertThresholdMin(self, basestation, number=400) ` + + +` def SetAirQualityRecordingOff(self, basestation) ` + + +` def SetAirQualityRecordingOn(self, basestation) ` + + +` def SetAudioAlertsOff(self, basestation, sensitivity=3) ` + + +` def SetAudioAlertsOn(self, basestation, sensitivity=3) ` + + +` def SetAutomationActivityZones(self, camera, zone, coords, color) ` + + + +An activity zone is the area you draw in your video in the UI to tell Arlo +what part of the scene to "watch". This method takes 4 arguments. camera: the +camera you want to set an activity zone for. name: "Zone 1" - the name of your +activity zone. coords: [{"x":0.37946943483275664,"y":0.3790983606557377},{"x": +0.8685121107266436,"y":0.3790983606557377},{"x":0.8685121107266436,"y":1},{"x" +:0.37946943483275664,"y":1}] - these coordinates are the bonding box for the +activity zone. color: 45136 - the color for your bounding box. + +` def SetHumidityAlertOff(self, basestation) ` + + +` def SetHumidityAlertOn(self, basestation) ` + + +` def SetHumidityAlertThresholdMax(self, basestation, number=800) ` + + +` def SetHumidityAlertThresholdMin(self, basestation, number=400) ` + + +` def SetHumidityRecordingOff(self, basestation) ` + + +` def SetHumidityRecordingOn(self, basestation) ` + + +` def SetLoopBackModeContinuous(self, basestation) ` + + +` def SetLoopBackModeSingleTrack(self, basestation) ` + + +` def SetMotionAlertsOff(self, basestation, sensitivity=5) ` + + +` def SetMotionAlertsOn(self, basestation, sensitivity=5) ` + + +` def SetNightLightBrightness(self, basestation, level=200) ` + + +` def SetNightLightColor(self, basestation, red=255, green=255, blue=255) ` + + +` def SetNightLightMode(self, basestation, mode='rainbow') ` + + + +mode: rainbow or rgb. + +` def SetNightLightOff(self, basestation) ` + + +` def SetNightLightOn(self, basestation) ` + + +` def SetNightLightTimerOff(self, basestation, time=0, timediff=300) ` + + +` def SetNightLightTimerOn(self, basestation, time=1576435472, timediff=0) ` + + +` def SetOCProfile(self, firstName, lastName, country='United States', +language='en', spam_me=0) ` + + +` def SetSchedule(self, basestation, schedule) ` + + + +The following json is what was sent to the API when I edited my schedule. It +contains all of the data necessary to configure a whole week. It's a little +convoluted, but you can just play around with the scheduler in Chrome and +watch the schema that gets sent. + +{ "schedule": [ { "duration": 600, "startActions": { "disableModes": [ "mode0" +], "enableModes": [ "mode1" ] }, "days": [ "Mo", "Tu", "We", "Th", "Fr", "Sa", +"Su" ], "startTime": 0, "type": "weeklyAction", "endActions": { +"disableModes": [ "mode1" ], "enableModes": [ "mode0" ] } }, { "duration": +360, "startActions": { "disableModes": [ "mode0" ], "enableModes": [ "mode2" ] +}, "days": [ "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su" ], "startTime": 1080, +"type": "weeklyAction", "endActions": { "disableModes": [ "mode2" ], +"enableModes": [ "mode0" ] } }, { "duration": 480, "startActions": { +"disableModes": [ "mode0" ], "enableModes": [ "mode3" ] }, "days": [ "Tu" ], +"startTime": 600, "type": "weeklyAction", "endActions": { "disableModes": [ +"mode3" ], "enableModes": [ "mode0" ] } } ], "name": "", "id": "schedule.1", +"enabled": true } + +` def SetShuffleOff(self, basestation) ` + + +` def SetShuffleOn(self, basestation) ` + + +` def SetSleepTimerOff(self, basestation, time=0, timediff=300) ` + + +` def SetSleepTimerOn(self, basestation, time=1576435472, timediff=0) ` + + +` def SetTempAlertOff(self, basestation) ` + + +` def SetTempAlertOn(self, basestation) ` + + +` def SetTempAlertThresholdMax(self, basestation, number=240) ` + + +` def SetTempAlertThresholdMin(self, basestation, number=200) ` + + +` def SetTempRecordingOff(self, basestation) ` + + +` def SetTempRecordingOn(self, basestation) ` + + +` def SetTempUnit(self, uniqueId, unit='C') ` + + +` def SetVolume(self, basestation, mute=False, volume=50) ` + + +` def SirenOff(self, basestation) ` + + +` def SirenOn(self, basestation) ` + + +` def SkipTrack(self, basestation) ` + + +` def StartRecording(self, basestation, camera) ` + + + +This function causes the camera to start recording. You can get the timezone +from GetDevices(). + +` def StartStream(self, basestation, camera) ` + + + +This function returns the url of the rtsp video stream. This stream needs to +be called within 30 seconds or else it becomes invalid. It can be streamed +with: ffmpeg -re -i 'rtsps://' -acodec copy -vcodec copy test.mp4 The request +to /users/devices/startStream returns: { +url:rtsp://:443/vzmodulelive?egressToken=b&userAgent=iOS&cameraId=} + +` def StopRecording(self, camera) ` + + + +This function causes the camera to stop recording. You can get the timezone +from GetDevices(). + +` def StopStream(self, basestation, camera) ` + + +` def StreamRecording(self, url, chunk_size=4096) ` + + + +Returns a generator that is the chunked video stream from the +presignedContentUrl. + +**`url`** : `presignedContentUrl` + +` def Subscribe(self, basestation) ` + + + +Arlo uses the EventStream interface in the browser to do pub/sub style +messaging. Unfortunately, this appears to be the only way Arlo communicates +these messages. + +This function makes the initial GET request to /subscribe, which returns the +EventStream socket. Once we have that socket, the API requires a POST request +to /notify with the "subscriptionsresource. This call "registersthe device +(which should be the basestation) so that events will be sent to the +EventStream when subsequent calls to /notify are made. + +Since this interface is asynchronous, and this is a quick and dirty hack to +get this working, I'm using a thread to listen to the EventStream. This thread +puts events into a queue. Some polling is required (see +NotifyAndGetResponse()) because the event messages aren't guaranteed to be +delivered in any specific order, but I wanted to maintain a synchronous style +API. + +You generally shouldn't need to call Subscribe() directly, although I'm +leaving it "publicfor now. + +` def SubscribeToMotionEvents(self, basestation, callback, timeout=120) ` + + + +Use this method to subscribe to motion events. You must provide a callback +function which will get called once per motion event. + +The callback function should have the following signature: def callback(self, +event) + +This is an example of handling a specific event, in reality, you'd probably +want to write a callback for HandleEvents() that has a big switch statement in +it to handle all the various events Arlo produces. + +` def ToggleCamera(self, basestation, camera, active=True) ` + + + +active: True - Camera is off. active: False - Camera is on. + +` def TriggerAndHandleEvent(self, basestation, trigger, callback, timeout=120) +` + + + +Use this method to subscribe to the event stream and provide a callback that +will be called for event event received. This function will allow you to +potentially write a callback that can handle all of the events received from +the event stream. NOTE: Use this function if you need to run some code after +subscribing to the eventstream, but before your callback to handle the events +runs. + +` def TriggerFullFrameSnapshot(self, basestation, camera) ` + + + +This function causes the camera to record a fullframe snapshot. The +presignedFullFrameSnapshotUrl url is returned. Use DownloadSnapshot() to +download the actual image file. + +` def TriggerStreamSnapshot(self, basestation, camera) ` + + + +This function causes the camera to snapshot while recording. NOTE: You MUST +call StartStream() before calling this function. If you call StartStream(), +you have to start reading data from the stream, or streaming will be cancelled +and taking a snapshot may fail (since it requires the stream to be active). + +NOTE: You should not use this function is you just want a snapshot and aren't +intending to stream. Use TriggerFullFrameSnapshot() instead. + +NOTE: Use DownloadSnapshot() to download the actual image file. + +` def UnPauseTrack(self, basestation) ` + + +` def Unsubscribe(self, basestation) ` + + + +This method stops the EventStream subscription and removes it from the +event_stream collection. + +` def UpdateDeviceName(self, device, name) ` + + +` def UpdateDisplayOrder(self, body) ` + + + +This is an example of the json you would pass in the body to +UpdateDisplayOrder() of your devices in the UI. + +XXXXXXXXXXXXX is the device id of each camera. You can get this from +GetDevices(). { "devices":{ "XXXXXXXXXXXXX":1, "XXXXXXXXXXXXX":2, +"XXXXXXXXXXXXX":3 } } + +` def UpdateFriend(self, body) ` + + + +This is an example of the json you would pass in the body: { +"firstName":"Some", "lastName":"Body", "devices":{ "XXXXXXXXXXXXX":"Camera 1", +"XXXXXXXXXXXXX":"Camera 2 ", "XXXXXXXXXXXXX":"Camera 3" }, +"lastModified":1463977440911, "adminUser":true, "email":"user@example.com", +"id":"XXX-XXXXXXX" } + +` def UpdatePassword(self, password) ` + + +` def UpdateProfile(self, first_name, last_name) ` + + +` def genTransId(self, trans_type='web') ` + + +` def interrupt_handler(self, signum, frame) ` + + +` def to_timestamp(self, dt) ` + + + +# Index + + * ### Classes + + * #### `Arlo` + + * `AddFriend` + * `AdjustBrightness` + * `AlertNotificationMethods` + * `Arm` + * `BatchDeleteRecordings` + * `Calendar` + * `CustomMode` + * `DeleteMode` + * `DeleteRecording` + * `Disarm` + * `DownloadRecording` + * `DownloadSnapshot` + * `Geofencing` + * `GetAudioPlayback` + * `GetAutomationActivityZones` + * `GetAutomationDefinitions` + * `GetBaseStationState` + * `GetCalendar` + * `GetCameraState` + * `GetCameraTempReading` + * `GetCvrPlaylist` + * `GetDeviceCapabilities` + * `GetDeviceSupport` + * `GetDeviceSupportV3` + * `GetDeviceSupportv2` + * `GetDevices` + * `GetEmergencyLocations` + * `GetFriends` + * `GetLibrary` + * `GetLibraryMetaData` + * `GetLocations` + * `GetModes` + * `GetModesV2` + * `GetOCProfile` + * `GetPaymentBilling` + * `GetPaymentOffers` + * `GetPaymentOffersV2` + * `GetPaymentOffersV3` + * `GetPaymentOffersV4` + * `GetProfile` + * `GetRecording` + * `GetRules` + * `GetSensorConfig` + * `GetServiceLevel` + * `GetServiceLevelSettings` + * `GetServiceLevelV2` + * `GetServiceLevelV3` + * `GetServiceLevelV4` + * `GetSession` + * `GetSmartAlerts` + * `GetSmartFeatures` + * `GetUpdateFeatures` + * `HandleEvents` + * `Login` + * `Logout` + * `Notify` + * `NotifyAndGetResponse` + * `PauseTrack` + * `Ping` + * `PlayTrack` + * `PushToTalk` + * `RemoveFriend` + * `ResendFriendInvite` + * `Reset` + * `RestartBasestation` + * `SetAirQualityAlertOff` + * `SetAirQualityAlertOn` + * `SetAirQualityAlertThresholdMax` + * `SetAirQualityAlertThresholdMin` + * `SetAirQualityRecordingOff` + * `SetAirQualityRecordingOn` + * `SetAudioAlertsOff` + * `SetAudioAlertsOn` + * `SetAutomationActivityZones` + * `SetHumidityAlertOff` + * `SetHumidityAlertOn` + * `SetHumidityAlertThresholdMax` + * `SetHumidityAlertThresholdMin` + * `SetHumidityRecordingOff` + * `SetHumidityRecordingOn` + * `SetLoopBackModeContinuous` + * `SetLoopBackModeSingleTrack` + * `SetMotionAlertsOff` + * `SetMotionAlertsOn` + * `SetNightLightBrightness` + * `SetNightLightColor` + * `SetNightLightMode` + * `SetNightLightOff` + * `SetNightLightOn` + * `SetNightLightTimerOff` + * `SetNightLightTimerOn` + * `SetOCProfile` + * `SetSchedule` + * `SetShuffleOff` + * `SetShuffleOn` + * `SetSleepTimerOff` + * `SetSleepTimerOn` + * `SetTempAlertOff` + * `SetTempAlertOn` + * `SetTempAlertThresholdMax` + * `SetTempAlertThresholdMin` + * `SetTempRecordingOff` + * `SetTempRecordingOn` + * `SetTempUnit` + * `SetVolume` + * `SirenOff` + * `SirenOn` + * `SkipTrack` + * `StartRecording` + * `StartStream` + * `StopRecording` + * `StopStream` + * `StreamRecording` + * `Subscribe` + * `SubscribeToMotionEvents` + * `TRANSID_PREFIX` + * `ToggleCamera` + * `TriggerAndHandleEvent` + * `TriggerFullFrameSnapshot` + * `TriggerStreamSnapshot` + * `UnPauseTrack` + * `Unsubscribe` + * `UpdateDeviceName` + * `UpdateDisplayOrder` + * `UpdateFriend` + * `UpdatePassword` + * `UpdateProfile` + * `__init__` + * `genTransId` + * `interrupt_handler` + * `to_timestamp` + +Generated by [pdoc 0.5.1](https://pdoc3.github.io/pdoc). + diff --git a/RPI Code/Arlo/docs/arlo.html b/RPI Code/Arlo/docs/arlo.html new file mode 100644 index 0000000..77bf710 --- /dev/null +++ b/RPI Code/Arlo/docs/arlo.html @@ -0,0 +1,1690 @@ + + + + + + +arlo API documentation + + + + + + + + +
    +
    +
    +

    arlo module

    +
    +
    +

    Copyright 2016 Jeffrey D. Walter

    +

    Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at

    +

    http://www.apache.org/licenses/LICENSE-2.0

    +

    Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS ISBASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License.

    +
    +
    +
    +
    +
    +
    +
    +
    +

    Classes

    +
    +
    +class Arlo +
    +
    +
    +

    Class variables

    +
    +
    var TRANSID_PREFIX
    +
    +
    +
    +
    +

    Methods

    +
    +
    +def __init__(self, username, password) +
    +
    +

    Initialize self. +See help(type(self)) for accurate signature.

    +
    +
    +def AddFriend(self, firstname, lastname, email, devices={}, admin=False) +
    +
    +

    This API will send an email to a user and if they accept, will give them access to the devices you specify. +NOTE: XXX-XXXXXXX_XXXXXXXXXXXX is the uniqueId field in your device object.

    +

    {adminUser:false,firstName:John,lastName:Doe,email:john.doe@example.com,devices:{XXX-XXXXXXX_XXXXXXXXXXXX:Camera1,XXX-XXXXXXX_XXXXXXXXXXXX:Camera2}}

    +
    +
    +def AdjustBrightness(self, basestation, camera, brightness=0) +
    +
    +

    NOTE: Brightness is between -2 and 2 in increments of 1 (-2, -1, 0, 1, 2). +Setting it to an invalid value has no effect.

    +

    Returns: +{ +"action": "is", +"from": "XXXXXXXXXXXXX", +"properties": { +"brightness": -2 +}, +"resource": "cameras/XXXXXXXXXXXXX", +"to": "336-XXXXXXX_web", +"transId": "web!XXXXXXXX.389518!1514956240683" +}

    +
    +
    +def AlertNotificationMethods(self, basestation, action='disabled', email=False, push=False) +
    +
    +
    +
    action : disabled OR recordSnapshot OR recordVideo
    +
     
    +
    +
    +
    +def Arm(self, device) +
    +
    +
    +
    +
    +def BatchDeleteRecordings(self, recordings) +
    +
    +

    Delete a batch of video recordings from Arlo.

    +

    The GetLibrary() call response json can be passed directly to this method if you'd like to delete the same list of videos you queried for. +If you want to delete some other batch of videos, then you need to send an array of objects representing each video you want to delete.

    +

    [ +{ +"createdDate":"20160904", +"utcCreatedDate":1473010280395, +"deviceId":"XXXXXXXXXXXXX" +}, +{ +"createdDate":"20160904", +"utcCreatedDate":1473010280395, +"deviceId":"XXXXXXXXXXXXX" +} +]

    +
    +
    +def Calendar(self, basestation, active=True) +
    +
    +

    DEPRECATED: This API appears to still do stuff, but I don't see it called in the web UI anymore when switching the mode to a schedule.

    +

    NOTE: The Arlo API seems to disable calendar mode when switching to other modes, if it's enabled. +You should probably do the same, although, the UI reflects the switch from calendar mode to say armed mode without explicitly setting calendar mode to inactive.

    +
    +
    +def CustomMode(self, device, mode, schedules=[]) +
    +
    +

    device can be any object that has parentId == deviceId. i.e., not a camera

    +
    +
    +def DeleteMode(self, device, mode) +
    +
    +

    device can be any object that has parentId == deviceId. i.e., not a camera

    +
    +
    +def DeleteRecording(self, recording) +
    +
    +

    Delete a single video recording from Arlo. +All of the date info and device id you need to pass into this method are given in the results of the GetLibrary() call.

    +
    +
    +def Disarm(self, device) +
    +
    +
    +
    +
    +def DownloadRecording(self, url, to) +
    +
    +

    Writes a video to a given local file path.

    +
    +
    url : presignedContentUrl
    +
     
    +
    to : path where the file should be written
    +
     
    +
    +
    +
    +def DownloadSnapshot(self, url, to, chunk_size=4096) +
    +
    +

    Writes a snapshot to a given local file path.

    +
    +
    url : presignedContentUrl or presignedFullFrameSnapshotUrl
    +
     
    +
    to : path where the file should be written
    +
     
    +
    +
    +
    +def Geofencing(self, location_id, active=True) +
    +
    +

    Get location_id is the id field from the return of GetLocations() +NOTE: The Arlo API seems to disable geofencing mode when switching to other modes, if it's enabled. +You should probably do the same, although, the UI reflects the switch from calendar mode to say armed mode without explicitly setting calendar mode to inactive.

    +
    +
    +def GetAudioPlayback(self, basestation) +
    +
    +
    +
    +
    +def GetAutomationActivityZones(self, camera) +
    +
    +
    +
    +
    +def GetAutomationDefinitions(self) +
    +
    +
    +
    +
    +def GetBaseStationState(self, basestation) +
    +
    +
    +
    +
    +def GetCalendar(self, basestation) +
    +
    +
    +
    +
    +def GetCameraState(self, basestation) +
    +
    +
    +
    +
    +def GetCameraTempReading(self, basestation) +
    +
    +
    +
    +
    +def GetCvrPlaylist(self, camera, fromDate, toDate) +
    +
    +

    This function downloads a Cvr Playlist file for the period fromDate to toDate.

    +
    +
    +def GetDeviceCapabilities(self, device) +
    +
    +
    +
    +
    +def GetDeviceSupport(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +

    This API looks like it's mainly used by the website, but I'm including it for completeness sake. +It returns something like the following: +{ +"devices": [ +{ +"deviceType": "arloq", +"urls": { +"troubleshoot": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_troubleshoot.html", +"plugin": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_plugin.html", +"connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_connection.html", +"connectionFailed": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_connection_fail.html", +"press_sync": "https://vzs3-prod-common.s3. amazonaws.com/static/html/en/pc_press_sync.html", +"resetDevice": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/reset_arloq.html", +"qr_how_to": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/pc_qr_how_to.html" +} +}, +{ +"deviceType": "basestation", +"urls": { +"troubleshoot": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_troubleshoot.html", +"connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_connection.html", +"sync": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/bs_sync_camera.html" +} +}, +{ +"deviceType": "arloqs", +"urls": { +"ethernetSetup": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/ethernet_setup.html", +"plugin": "https:// +vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/aqp_plugin.html", +"connectionWiFi": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_in_progress_wifi.html", +"poeSetup": "https://vzs3-prod-common.s3. +amazonaws.com/static/html/en/arloqs/poe_setup.html", +"connection": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_in_progress.html", +"connectionFailed": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_fail.html", +"press_sync": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/press_sync.html", +"connectionType": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/connection_type.html", +"resetDevice": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/reset_device.html", +"qr_how_to": "https://vzs3-prod-common.s3.amazonaws.com/static/html/en/arloqs/qr_how_to.html" +} +} +] +}

    +
    +
    +def GetDeviceSupportV3(self) +
    +
    +

    This is the latest version of the device support api. +It returns something like the following: +{ +"data": { +"devices": { +"camera": { +"modelIds": [ +"VMC3010", +"VMC3030", +"VMC4030", +"VMC4030P", +"VMC5040", +"VZC3010", +"VZC3030" +], +"connectionTypes": { +"WPS": true, +"BLE": true +}, +"kbArticles": { +"insertBatteries": "https://kb.arlo.com/980150/Safety-Rules-for-Arlo-Wire-Free-Camera-Batteries", +"syncBasestation": "https://kb.arlo.com/987/How-do-I-set-up-and-sync-my-Arlo-Wire-Free-cameras", +"sync": "https://kb.arlo.com/987/How-do-I-set-up-and-sync-my-Arlo-Wire-Free-camera", +"firmwareUpdate": "https://kb.arlo.com/4736/How-do-I-update-my-Arlo-firmware-manually" +} +}, +"arloq": { +"modelIds": [ +"VMC3040", +"VMC3040S" +], +"kbArticles": { +"power": "https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", +"qrCode": "https://kb.arlo.com/1001944/How-do-I-set-up-Arlo-Q-on-iOS", +"power_android": "https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on-Android", +"qrCode_android": +"https://kb.arlo.com/1002006/How-do-I-set-up-Arlo-Q-on-Android" +} +}, +"basestation": { +"modelIds": [ +"VMB3010", +"VMB4000", +"VMB3010r2", +"VMB3500", +"VZB3010", +"VMB4500", +"VMB5000" +], +"smartHubs": [ +"VMB5000" +], +"kbArticles": { +"pluginNetworkCable": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", +"power": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", +"led": "https://kb.arlo.com/1179139/How-do-I-connect-my-Arlo-or-Arlo-Pro-base-station-to-the-Internet", +"learnMore": "https://kb.arlo.com/000062124/How-do-I-record-4K-videos-to-a-microSD-card" +} +}, +"arlobaby": { +"modelIds": [ +"ABC1000" +], +"kbArticles": { +"power": "https://kb.arlo.com/1282682/How-do-I-power-cycle-my-Arlo-Baby-camera", +"qrCode": "https://kb.arlo.com/1282700/How-do-I-set-up-my-Arlo-Baby-camera" +} +}, +"lteCamera":{ +"modelIds":[ +"VML4030" +], +"kbArticles":{ +"servicePlan":"https://kb.arlo.com/1286865/What-Arlo-Mobile-service-plans-are-available", +"simActivation":"https://kb.arlo.com/1286865/What-Arlo-Mobile-service-plans-are-available", +"qrCode":"https://kb.arlo.com/1201822/How-do-I-set-up-my-Arlo-Go-camera" +} +}, +"bridge": { +"modelIds": [ +"ABB1000" +], +"kbArticles": { +"power": "https://kb.arlo.com/000062047", +"sync": "https://kb.arlo.com/000062037", +"qrCode": "https://kb.arlo.com/000061886", +"factoryReset": "https://kb.arlo.com/000061837" +} +}, +"lights": { +"modelIds": [ +"AL1101" +], +"kbArticles": { +"sync": "https://kb.arlo.com/000062005", +"insertBatteries": "https://kb.arlo.com/000061952", +"qrCode": "https://kb.arlo.com/000061886" +} +}, +"routerM1":{ +"modelIds":[ +"MR1100" +], +"kbArticles":{ +"lookupFailed":"https://kb.arlo.com/1179130/Arlo-can-t-discover-my-base-station-during-installation-what-do-I-do" +} +}, +"chime": { +"modelIds": [ +"AC1001" +], +"kbArticles": { +"ledNotBlinking":"https://kb.arlo.com/000061924", +"led":"https://kb.arlo.com/000061847", +"factoryReset":"https://kb.arlo.com/000061879", +"connectionFailed":"https://kb.arlo.com/000061880" +} +}, +"doorbell": { +"modelIds": [ +"AAD1001" +], +"kbArticles": { +"led":"https://kb.arlo.com/000061847", +"factoryReset":"https://kb.arlo.com/000061842", +"pairCamera":"https://kb.arlo.com/000061897", +"existingChime":"https://kb.arlo.com/000061856", +"noWiring":"https://kb.arlo.com/000061859", +"connectionFailed":"https://kb.arlo.com/000061868", +"pairCameraFailed":"https://kb.arlo.com/000061893", +"testChimeFailed":"https://kb.arlo.com/000061944" +}, +"videos": { +"chimeType": "https://youtu.be/axytuF63VC0", +"wireDoorbell": "https://youtu.be/_5D2n3iPqW0", +"switchSetting": "https://youtu.be/BUmd4fik2RE" +}, +"arloVideos": { +"chimeType": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Chime.mp4", +"wireDoorbell": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Wired.mp4", +"switchSetting": "https://vzs3-prod-common.s3.amazonaws.com/static/devicesupport/Arlo_Audio_Doorbell_Switch.mp4" +} +} +}, +"arlosmart": { +"kbArticles": { +"e911": "https://www.arlo.com/en-us/landing/arlosmart/", +"callFriend": "https://www.arlo.com/en-us/landing/arlosmart/", +"4kAddOnPopup": "https://www.arlo.com/en-us/landing/arlosmart/", +"cloudRecording": "https://www.arlo.com/en-us/landing/arlosmart/", +"manageArloSmart": "https://kb.arlo.com/000062115", +"otherVideo": "https://kb.arlo.com/000062115", +"packageDetection": "https://kb.arlo.com/000062114", +"whereIsBasicSubscriptionGone": "https://kb.arlo.com/000062163" +} +} +}, +"success":true +}

    +
    +
    +def GetDeviceSupportv2(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +

    It returns something like the following: +{ +"devices": [ +{ +"deviceType": "arloq", +"modelId": [ +"VMC3040" +], +"urls": { +"troubleshoot": "arloq/troubleshoot.html", +"plugin": "arloq/plugin.html", +"qrHowTo": "arloq/qrHowTo.html", +"connection": "arloq/connection.html", +"connectionInProgress": "arloq/connectionInProgress.html", +"connectionFailed": "arloq/connectionFailed.html", +"pressSync": "arloq/pressSync.html", +"resetDevice": "arloq/resetDevice.html" +} +}, +{ +"deviceType": "basestation", +"modelId": [ +"VMB3010", +"VMB3010r2", +"VMB3500", +"VMB4000", +"VMB4500", +"VZB3010" +], +"urls": { +"troubleshoot": "basestation/troubleshoot.html", +"plugin": "basestation/plugin.html", +"sync3": "basestation/sync3.html", +"troubleshootBS": "basestation/troubleshootBS.html", +"connection": "basestation/connection.html", +"connectionInProgress": "basestation/connectionInProgress.html", +"sync2": "basestation/sync2.html", +"connectionFailed": "basestation/connectionFailed.html", +"sync1": "basestation/sync1.html", +"resetDevice": "basestation/resetDevice.html", +"syncComplete": "basestation/syncComplete.html" +} +}, +{ +"deviceType": "arlobaby", +"modelId": [ +"ABC1000" +], +"urls": { +"bleSetupError": "arlobaby/bleSetupError.html", +"troubleshoot": "arlobaby/troubleshoot.html", +"homekitCodeInstruction": "arlobaby/homekitCodeInstruction.html", +"connectionInProgress": "arlobaby/connectionInProgress.html", +"connectionFailed": "arlobaby/connectionFailed.html", +"resetDevice": "arlobaby/resetDevice.html", +"plugin": "arlobaby/plugin.html", +"qrHowTo": "arlobaby/qrHowTo.html", +"warning": "arlobaby/warning.html", +"connection": "arlobaby/connection.html", +"pressSync": "arlobaby/pressSync.html", +"bleInactive": "arlobaby/bleInactive.html", +"pluginIOS": "arlobaby/pluginIOS.html", +"homekitSetup": "arlobaby/homekitSetup.html" +} +}, +{ +"deviceType": "lteCamera", +"modelId": [ +"VML4030" +], +"urls": { +"troubleshoot": "lteCamera/troubleshoot.html", +"resetHowTo": "lteCamera/resetHowTo.html", +"plugin": "lteCamera/plugin.html", +"qrHowTo": "lteCamera/qrHowTo.html", +"connectionInProgress": "lteCamera/connectionInProgress.html", +"connectionFailed": "lteCamera/connectionFailed.html", +"resetDevice": "lteCamera/resetHowTo.html", +"resetComplete": "lteCamera/resetComplete.html", +"syncComplete": "lteCamera/syncComplete.html" +} +}, +{ +"deviceType": "arloqs", +"modelId": [ +"VMC3040S" +], +"urls": { +"ethernetSetup": "arloqs/ethernetSetup.html", +"troubleshoot": "arloqs/troubleshoot.html", +"plugin": "arloqs/plugin.html", +"poeSetup": "arloqs/poeSetup.html", +"connectionInProgressWiFi": "arloqs/connectionInProgressWifi.html", +"qrHowTo": "arloqs/qrHowTo.html", +"connectionInProgress": "arloqs/connectionInProgress.html", +"connectionFailed": "arloqs/connectionFailed.html", +"pressSync": "arloqs/pressSync.html", +"connectionType": "arloqs/connectionType.html", +"resetDevice": "arloqs/resetDevice.html" +} +}, +{ +"deviceType": "bridge", +"modelId": [ +"ABB1000" +], +"urls": { +"troubleshoot": "bridge/troubleshoot.html", +"fwUpdateInProgress": "bridge/fwUpdateInProgress.html", +"qrHowToUnplug": "bridge/qrHowToUnplug.html", +"fwUpdateDone": "bridge/fwUpdateDone.html", +"fwUpdateAvailable": "bridge/fwUpdateAvailable.html", +"needHelp": "https://www.arlo.com/en-us/support/#support_arlo_light", +"wifiError": "bridge/wifiError.html", +"bleAndroid": "bridge/bleInactiveAND.html", +"bleIOS": "bridge/bleInactiveIOS.html", +"connectionInProgress": "bridge/connectionInProgress.html", +"connectionFailed": "bridge/connectionFailed.html", +"manualPair": "bridge/manualPairing.html", +"resetDevice": "bridge/resetDevice.html", +"lowPower": "bridge/lowPowerZoneSetup.html", +"fwUpdateFailed": "bridge/fwUpdateFailed.html", +"fwUpdateCheckFailed": "bridge/fwUpdateCheckFailed.html", +"plugin": "bridge/plugin.html", +"qrHowTo": "bridge/qrHowTo.html", +"pressSync": "bridge/pressSync.html", +"pluginNoLED": "bridge/pluginNoLED.html", +"fwUpdateCheck": "bridge/fwUpdateCheck.html" +} +}, +{ +"deviceType": "lights", +"modelId": [ +"AL1101" +], +"urls": { +"troubleshoot": "lights/troubleshoot.html", +"needHelp": "https://kb.netgear.com/000053159/Light-discovery-failed.html", +"bleInactiveAND": "lights/bleInactiveAND.html", +"connectionInProgress": "lights/connectionInProgress.html", +"connectionFailed": "lights/connectionFailed.html", +"addBattery": "lights/addBattery.html", +"tutorial1": "lights/tutorial1.html", +"plugin": "lights/plugin.html", +"tutorial2": "lights/tutorial2.html", +"tutorial3": "lights/tutorial3.html", +"configurationInProgress": "lights/configurationInProgress.html", +"qrHowTo": "lights/qrHowTo.html", +"pressSync": "lights/pressSync.html", +"bleInactiveIOS": "lights/bleInactiveIOS.html", +"syncComplete": "lights/syncComplete.html" +} +}, +{ +"deviceType": "routerM1", +"modelId": [ +"MR1100" +], +"urls": { +"troubleshoot": "routerM1/troubleshoot.html", +"help": "routerM1/help.html", +"pairingFailed": "routerM1/pairingFailed.html", +"needHelp": "https://acupdates.netgear.com/help/redirect.aspx?url=m1arlo-kbb", +"plugin": "routerM1/plugin.html", +"pairing": "routerM1/pairing.html", +"connectionInProgress": "routerM1/connectionInProgress.html", +"sync2": "routerM1/sync2.html", +"connectionFailed": "routerM1/connectionFailed.html", +"sync1": "routerM1/sync1.html", +"sync": "routerM1/sync.html", +"syncComplete": "routerM1/syncComplete.html" +} +} +], +"selectionUrls": { +"addDevice": "addDeviceBsRuAqAqpLteAbcMrBgLt.html", +"selectBasestation": "selectBsMr.html", +"deviceSelection": "deviceBsAqAqpLteAbcMrLtSelection.html", +"selectLights": "selectBgLt.html" +}, +"baseUrl": "https://vzs3-prod-common.s3.amazonaws.com/static/v2/html/en/" +}

    +
    +
    +def GetDevices(self, device_type=None, filter_provisioned=None) +
    +
    +

    This method returns an array that contains the basestation, cameras, etc. and their metadata. +If you pass in a valid device type, as a string or a list, this method will return an array of just those devices that match that type. An example would be ['basestation', 'camera'] +To filter provisioned or unprovisioned devices pass in a True/False value for filter_provisioned. By default both types are returned.

    +
    +
    +def GetEmergencyLocations(self) +
    +
    +
    +
    +
    +def GetFriends(self) +
    +
    +
    +
    +
    +def GetLibrary(self, from_date, to_date) +
    +
    +

    This call returns the following: +presignedContentUrl is a link to the actual video in Amazon AWS. +presignedThumbnailUrl is a link to the thumbnail .jpg of the actual video in Amazon AWS.

    +

    [ +{ +"mediaDurationSecond": 30, +"contentType": "video/mp4", +"name": "XXXXXXXXXXXXX", +"presignedContentUrl": "https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX.mp4?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"lastModified": 1472881430181, +"localCreatedDate": XXXXXXXXXXXXX, +"presignedThumbnailUrl": "https://arlos3-prod-z2.s3.amazonaws.com/XXXXXXX_XXXX_XXXX_XXXX_XXXXXXXXXXXXX/XXX-XXXXXXX/XXXXXXXXXXXXX/recordings/XXXXXXXXXXXXX_thumb.jpg?AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Expires=1472968703&Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"reason": "motionRecord", +"deviceId": "XXXXXXXXXXXXX", +"createdBy": "XXXXXXXXXXXXX", +"createdDate": "20160903", +"timeZone": "America/Chicago", +"ownerId": "XXX-XXXXXXX", +"utcCreatedDate": XXXXXXXXXXXXX, +"currentState": "new", +"mediaDuration": "00:00:30" +} +]

    +
    +
    +def GetLibraryMetaData(self, from_date, to_date) +
    +
    +
    +
    +
    +def GetLocations(self) +
    +
    +

    This call returns the following: +{ +"id":"XXX-XXXXXXX_20160823042047", +"name":"Home", +"ownerId":"XXX-XXXXXXX", +"longitude":X.XXXXXXXXXXXXXXXX, +"latitude":X.XXXXXXXXXXXXXXXX, +"address":"123 Middle Of Nowhere Bumbfuck, EG, 12345", +"homeMode":"schedule", +"awayMode":"mode1", +"geoEnabled":false, +"geoRadius":150.0, +"uniqueIds":[ +"XXX-XXXXXXX_XXXXXXXXXXXXX" +], +"smartDevices":[ +"XXXXXXXXXX", +"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" +], +"pushNotifyDevices":[ +"XXXXXXXXXX" +] +}

    +
    +
    +def GetModes(self, basestation) +
    +
    +

    DEPRECATED: This is the older API for getting the "mode". It still works, but GetModesV2 is the way the Arlo software does it these days.

    +
    +
    +def GetModesV2(self) +
    +
    +

    This is the newer API for getting the "mode". This method also returns the schedules. +Set a non-schedule mode to be active: {"activeAutomations":[{"deviceId":"XXXXXXXXXXXXX","timestamp":1532015622105,"activeModes":["mode1"],"activeSchedules":[]}]} +Set a schedule to be active: {"activeAutomations":[{"deviceId":"XXXXXXXXXXXXX","timestamp":1532015790139,"activeModes":[],"activeSchedules":["schedule.1"]}]}

    +
    +
    +def GetOCProfile(self) +
    +
    +
    +
    +
    +def GetPaymentBilling(self) +
    +
    +
    +
    +
    +def GetPaymentOffers(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +
    +
    +def GetPaymentOffersV2(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +
    +
    +def GetPaymentOffersV3(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +
    +
    +def GetPaymentOffersV4(self) +
    +
    +
    +
    +
    +def GetProfile(self) +
    +
    +
    +
    +
    +def GetRecording(self, url, chunk_size=4096) +
    +
    +

    Returns the whole video from the presignedContentUrl.

    +
    +
    +def GetRules(self, basestation) +
    +
    +
    +
    +
    +def GetSensorConfig(self, basestation) +
    +
    +
    +
    +
    +def GetServiceLevel(self) +
    +
    +
    +
    +
    +def GetServiceLevelSettings(self) +
    +
    +
    +
    +
    +def GetServiceLevelV2(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +
    +
    +def GetServiceLevelV3(self) +
    +
    +

    DEPRECATED: This API still works, but I don't see it being called in the web UI anymore.

    +
    +
    +def GetServiceLevelV4(self) +
    +
    +
    +
    +
    +def GetSession(self) +
    +
    +

    Returns something like the following: +{ +"userId": "XXX-XXXXXXX", +"email": "jeffreydwalter@gmail.com", +"token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", +"paymentId": "XXXXXXXX", +"accountStatus": "registered", +"serialNumber": "XXXXXXXXXXXXXX", +"countryCode": "US", +"tocUpdate": false, +"policyUpdate": false, +"validEmail": true, +"arlo": true, +"dateCreated": 1463975008658 +}

    +
    +
    +def GetSmartAlerts(self, camera) +
    +
    +
    +
    +
    +def GetSmartFeatures(self) +
    +
    +
    +
    +
    +def GetUpdateFeatures(self) +
    +
    +
    +
    +
    +def HandleEvents(self, basestation, callback, timeout=120) +
    +
    +

    Use this method to subscribe to the event stream and provide a callback that will be called for event event received. +This function will allow you to potentially write a callback that can handle all of the events received from the event stream.

    +
    +
    +def Login(self, username, password) +
    +
    +

    This call returns the following: +{ +"userId":"XXX-XXXXXXX", +"email":"user@example.com", +"token":"2_5HicFJMXXXXX-S_7IuK2EqOUHXXXXXXXXXXX1CXKWTThgU18Va_XXXXXX5S00hUafv3PV_if_Bl_rhiFsDHYwhxI3CxlVnR5f3q2XXXXXX-Wnt9F7D82uN1f4cXXXXX-FMUsWF_6tMBqwn6DpzOaIB7ciJrnr2QJyKewbQouGM6", +"paymentId":"XXXXXXXX", +"authenticated":1472961381, +"accountStatus":"registered", +"serialNumber":"XXXXXXXXXXXXX", +"countryCode":"US", +"tocUpdate":false, +"policyUpdate":false, +"validEmail":true +}

    +
    +
    +def Logout(self) +
    +
    +
    +
    +
    +def Notify(self, basestation, body) +
    +
    +

    The following are examples of the json you would need to pass in the body of the Notify() call to interact with Arlo:

    +
    +
    +
    +
    NOTE : While you can call Notify() directly, responses from these notify calls are sent to the EventStream (see Subscribe()),
    +
     
    +
    +

    and so it's better to use the Get/Set methods that are implemented using the NotifyAndGetResponse() method.

    +
    +
    +

    Set System Mode (Armed, Disarmed) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"modes","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"active":"mode0"}} +Set System Mode (Calendar) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"schedule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"active":true}} +Configure The Schedule (Calendar) - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"schedule","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"schedule":[{"modeId":"mode0","startTime":0},{"modeId":"mode2","startTime":28800000},{"modeId":"mode0","startTime":64800000},{"modeId":"mode0","startTime":86400000},{"modeId":"mode2","startTime":115200000},{"modeId":"mode0","startTime":151200000},{"modeId":"mode0","startTime":172800000},{"modeId":"mode2","startTime":201600000},{"modeId":"mode0","startTime":237600000},{"modeId":"mode0","startTime":259200000},{"modeId":"mode2","startTime":288000000},{"modeId":"mode0","startTime":324000000},{"modeId":"mode0","startTime":345600000},{"modeId":"mode2","startTime":374400000},{"modeId":"mode0","startTime":410400000},{"modeId":"mode0","startTime":432000000},{"modeId":"mode0","startTime":518400000}]} +Create Mode - +{"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"add","resource":"rules","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"name":"Record video on Camera 1 if Camera 1 detects motion","id":"ruleNew","triggers":[{"type":"pirMotionActive","deviceId":"XXXXXXXXXXXXX","sensitivity":80}],"actions":[{"deviceId":"XXXXXXXXXXXXX","type":"recordVideo","stopCondition":{"type":"timeout","timeout":15}},{"type":"sendEmailAlert","recipients":["OWNER_EMAIL"]},{"type":"pushNotification"}]}} +{"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"add","resource":"modes","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"name":"Test","rules":["rule3"]}} +Delete Mode - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"delete","resource":"modes/mode3","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true} +Camera Off - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"privacyActive":false}} +Night Vision On - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"zoom":{"topleftx":0,"toplefty":0,"bottomrightx":1280,"bottomrighty":720},"mirror":true,"flip":true,"nightVisionMode":1,"powerSaveMode":2}} +Motion Detection Test - {"from":"XXX-XXXXXXX_web","to":"XXXXXXXXXXXXX","action":"set","resource":"cameras/XXXXXXXXXXXXX","transId":"web!XXXXXXXX.XXXXXXXXXXXXXXXXXXXX","publishResponse":true,"properties":{"motionSetupModeEnabled":true,"motionSetupModeSensitivity":80}}

    +

    device_id = locations.data.uniqueIds

    +

    System Properties: ("resource":"modes") +active (string) - Mode Selection (mode2 = All Motion On, mode1 = Armed, mode0 = Disarmed, etc.)

    +

    System Properties: ("resource":"schedule") +active (bool) - Mode Selection (true = Calendar)

    +

    Camera Properties: ("resource":"cameras/{id}") +privacyActive (bool) - Camera On/Off +zoom (topleftx (int), toplefty (int), bottomrightx (int), bottomrighty (int)) - Camera Zoom Level +mirror (bool) - Mirror Image (left-to-right or right-to-left) +flip (bool) - Flip Image Vertically +nightVisionMode (int) - Night Mode Enabled/Disabled (1, 0) +powerSaveMode (int) - PowerSaver Mode (3 = Best Video, 2 = Optimized, 1 = Best Battery Life) +motionSetupModeEnabled (bool) - Motion Detection Setup Enabled/Disabled +motionSetupModeSensitivity (int 0-100) - Motion Detection Sensitivity

    +
    +
    +def NotifyAndGetResponse(self, basestation, body, timeout=120) +
    +
    +
    +
    +
    +def PauseTrack(self, basestation) +
    +
    +
    +
    +
    +def Ping(self, basestation) +
    +
    +
    +
    +
    +def PlayTrack(self, basestation, track_id='2391d620-e491-4412-99f6-e9a40d6046ed', position=0) +
    +
    +

    Defaulting to 'hugh little baby', which is a supplied track. I hope the ID is the same for all.

    +
    +
    +def PushToTalk(self, camera) +
    +
    +
    +
    +
    +def RemoveFriend(self, email) +
    +
    +

    Removes a person you've granted access to.

    +

    email: email of user you want to revoke access from.

    +
    +
    +def ResendFriendInvite(self, friend) +
    +
    +
    +
    This API will resend an invitation email to a user that you've AddFriend'd. You will need to get the friend object by calling GetFriend() because it includes a token that must be passed to this API.
    +
    friend : {"ownerId":"XXX-XXXXXXX","token":"really long string that you get from the GetFriends() API","firstName":"John","lastName":"Doe","devices":{"XXX-XXXXXXX_XXXXXXXXXXXX":"Camera1","XXX-XXXXXXX_XXXXXXXXXXXX":"Camera2"},"lastModified":1548470485419,"adminUser":false,"email":"john.doe@example.com"}
    +
     
    +
    +
    +
    +def Reset(self) +
    +
    +
    +
    +
    +def RestartBasestation(self, basestation) +
    +
    +
    +
    +
    +def SetAirQualityAlertOff(self, basestation) +
    +
    +
    +
    +
    +def SetAirQualityAlertOn(self, basestation) +
    +
    +
    +
    +
    +def SetAirQualityAlertThresholdMax(self, basestation, number=700) +
    +
    +
    +
    +
    +def SetAirQualityAlertThresholdMin(self, basestation, number=400) +
    +
    +
    +
    +
    +def SetAirQualityRecordingOff(self, basestation) +
    +
    +
    +
    +
    +def SetAirQualityRecordingOn(self, basestation) +
    +
    +
    +
    +
    +def SetAudioAlertsOff(self, basestation, sensitivity=3) +
    +
    +
    +
    +
    +def SetAudioAlertsOn(self, basestation, sensitivity=3) +
    +
    +
    +
    +
    +def SetAutomationActivityZones(self, camera, zone, coords, color) +
    +
    +

    An activity zone is the area you draw in your video in the UI to tell Arlo what part of the scene to "watch". +This method takes 4 arguments. +camera: the camera you want to set an activity zone for. +name: "Zone 1" - the name of your activity zone. +coords: [{"x":0.37946943483275664,"y":0.3790983606557377},{"x":0.8685121107266436,"y":0.3790983606557377},{"x":0.8685121107266436,"y":1},{"x":0.37946943483275664,"y":1}] - these coordinates are the bonding box for the activity zone. +color: 45136 - the color for your bounding box.

    +
    +
    +def SetHumidityAlertOff(self, basestation) +
    +
    +
    +
    +
    +def SetHumidityAlertOn(self, basestation) +
    +
    +
    +
    +
    +def SetHumidityAlertThresholdMax(self, basestation, number=800) +
    +
    +
    +
    +
    +def SetHumidityAlertThresholdMin(self, basestation, number=400) +
    +
    +
    +
    +
    +def SetHumidityRecordingOff(self, basestation) +
    +
    +
    +
    +
    +def SetHumidityRecordingOn(self, basestation) +
    +
    +
    +
    +
    +def SetLoopBackModeContinuous(self, basestation) +
    +
    +
    +
    +
    +def SetLoopBackModeSingleTrack(self, basestation) +
    +
    +
    +
    +
    +def SetMotionAlertsOff(self, basestation, sensitivity=5) +
    +
    +
    +
    +
    +def SetMotionAlertsOn(self, basestation, sensitivity=5) +
    +
    +
    +
    +
    +def SetNightLightBrightness(self, basestation, level=200) +
    +
    +
    +
    +
    +def SetNightLightColor(self, basestation, red=255, green=255, blue=255) +
    +
    +
    +
    +
    +def SetNightLightMode(self, basestation, mode='rainbow') +
    +
    +

    mode: rainbow or rgb.

    +
    +
    +def SetNightLightOff(self, basestation) +
    +
    +
    +
    +
    +def SetNightLightOn(self, basestation) +
    +
    +
    +
    +
    +def SetNightLightTimerOff(self, basestation, time=0, timediff=300) +
    +
    +
    +
    +
    +def SetNightLightTimerOn(self, basestation, time=1576435472, timediff=0) +
    +
    +
    +
    +
    +def SetOCProfile(self, firstName, lastName, country='United States', language='en', spam_me=0) +
    +
    +
    +
    +
    +def SetSchedule(self, basestation, schedule) +
    +
    +

    The following json is what was sent to the API when I edited my schedule. It contains all of the data necessary to configure a whole week. It's a little convoluted, but you can just play around with the scheduler in Chrome and watch the schema that gets sent.

    +

    { +"schedule": [ +{ +"duration": 600, +"startActions": { +"disableModes": [ +"mode0" +], +"enableModes": [ +"mode1" +] +}, +"days": [ +"Mo", +"Tu", +"We", +"Th", +"Fr", +"Sa", +"Su" +], +"startTime": 0, +"type": "weeklyAction", +"endActions": { +"disableModes": [ +"mode1" +], +"enableModes": [ +"mode0" +] +} +}, +{ +"duration": 360, +"startActions": { +"disableModes": [ +"mode0" +], +"enableModes": [ +"mode2" +] +}, +"days": [ +"Mo", +"Tu", +"We", +"Th", +"Fr", +"Sa", +"Su" +], +"startTime": 1080, +"type": "weeklyAction", +"endActions": { +"disableModes": [ +"mode2" +], +"enableModes": [ +"mode0" +] +} +}, +{ +"duration": 480, +"startActions": { +"disableModes": [ +"mode0" +], +"enableModes": [ +"mode3" +] +}, +"days": [ +"Tu" +], +"startTime": 600, +"type": "weeklyAction", +"endActions": { +"disableModes": [ +"mode3" +], +"enableModes": [ +"mode0" +] +} +} +], +"name": "", +"id": "schedule.1", +"enabled": true +}

    +
    +
    +def SetShuffleOff(self, basestation) +
    +
    +
    +
    +
    +def SetShuffleOn(self, basestation) +
    +
    +
    +
    +
    +def SetSleepTimerOff(self, basestation, time=0, timediff=300) +
    +
    +
    +
    +
    +def SetSleepTimerOn(self, basestation, time=1576435472, timediff=0) +
    +
    +
    +
    +
    +def SetTempAlertOff(self, basestation) +
    +
    +
    +
    +
    +def SetTempAlertOn(self, basestation) +
    +
    +
    +
    +
    +def SetTempAlertThresholdMax(self, basestation, number=240) +
    +
    +
    +
    +
    +def SetTempAlertThresholdMin(self, basestation, number=200) +
    +
    +
    +
    +
    +def SetTempRecordingOff(self, basestation) +
    +
    +
    +
    +
    +def SetTempRecordingOn(self, basestation) +
    +
    +
    +
    +
    +def SetTempUnit(self, uniqueId, unit='C') +
    +
    +
    +
    +
    +def SetVolume(self, basestation, mute=False, volume=50) +
    +
    +
    +
    +
    +def SirenOff(self, basestation) +
    +
    +
    +
    +
    +def SirenOn(self, basestation) +
    +
    +
    +
    +
    +def SkipTrack(self, basestation) +
    +
    +
    +
    +
    +def StartRecording(self, basestation, camera) +
    +
    +

    This function causes the camera to start recording. +You can get the timezone from GetDevices().

    +
    +
    +def StartStream(self, basestation, camera) +
    +
    +

    This function returns the url of the rtsp video stream. +This stream needs to be called within 30 seconds or else it becomes invalid. +It can be streamed with: ffmpeg -re -i 'rtsps://' -acodec copy -vcodec copy test.mp4 +The request to /users/devices/startStream returns: { url:rtsp://:443/vzmodulelive?egressToken=b&userAgent=iOS&cameraId=}

    +
    +
    +def StopRecording(self, camera) +
    +
    +

    This function causes the camera to stop recording. +You can get the timezone from GetDevices().

    +
    +
    +def StopStream(self, basestation, camera) +
    +
    +
    +
    +
    +def StreamRecording(self, url, chunk_size=4096) +
    +
    +

    Returns a generator that is the chunked video stream from the presignedContentUrl.

    +
    +
    url : presignedContentUrl
    +
     
    +
    +
    +
    +def Subscribe(self, basestation) +
    +
    +

    Arlo uses the EventStream interface in the browser to do pub/sub style messaging. +Unfortunately, this appears to be the only way Arlo communicates these messages.

    +

    This function makes the initial GET request to /subscribe, which returns the EventStream socket. +Once we have that socket, the API requires a POST request to /notify with the "subscriptionsresource. +This call "registersthe device (which should be the basestation) so that events will be sent to the EventStream +when subsequent calls to /notify are made.

    +

    Since this interface is asynchronous, and this is a quick and dirty hack to get this working, I'm using a thread +to listen to the EventStream. This thread puts events into a queue. Some polling is required (see NotifyAndGetResponse()) because +the event messages aren't guaranteed to be delivered in any specific order, but I wanted to maintain a synchronous style API.

    +

    You generally shouldn't need to call Subscribe() directly, although I'm leaving it "publicfor now.

    +
    +
    +def SubscribeToMotionEvents(self, basestation, callback, timeout=120) +
    +
    +

    Use this method to subscribe to motion events. You must provide a callback function which will get called once per motion event.

    +

    The callback function should have the following signature: +def callback(self, event)

    +

    This is an example of handling a specific event, in reality, you'd probably want to write a callback for HandleEvents() +that has a big switch statement in it to handle all the various events Arlo produces.

    +
    +
    +def ToggleCamera(self, basestation, camera, active=True) +
    +
    +

    active: True - Camera is off. +active: False - Camera is on.

    +
    +
    +def TriggerAndHandleEvent(self, basestation, trigger, callback, timeout=120) +
    +
    +

    Use this method to subscribe to the event stream and provide a callback that will be called for event event received. +This function will allow you to potentially write a callback that can handle all of the events received from the event stream. +NOTE: Use this function if you need to run some code after subscribing to the eventstream, but before your callback to handle the events runs.

    +
    +
    +def TriggerFullFrameSnapshot(self, basestation, camera) +
    +
    +

    This function causes the camera to record a fullframe snapshot. +The presignedFullFrameSnapshotUrl url is returned. +Use DownloadSnapshot() to download the actual image file.

    +
    +
    +def TriggerStreamSnapshot(self, basestation, camera) +
    +
    +

    This function causes the camera to snapshot while recording. +NOTE: You MUST call StartStream() before calling this function. +If you call StartStream(), you have to start reading data from the stream, or streaming will be cancelled +and taking a snapshot may fail (since it requires the stream to be active).

    +

    NOTE: You should not use this function is you just want a snapshot and aren't intending to stream. +Use TriggerFullFrameSnapshot() instead.

    +

    NOTE: Use DownloadSnapshot() to download the actual image file.

    +
    +
    +def UnPauseTrack(self, basestation) +
    +
    +
    +
    +
    +def Unsubscribe(self, basestation) +
    +
    +

    This method stops the EventStream subscription and removes it from the event_stream collection.

    +
    +
    +def UpdateDeviceName(self, device, name) +
    +
    +
    +
    +
    +def UpdateDisplayOrder(self, body) +
    +
    +

    This is an example of the json you would pass in the body to UpdateDisplayOrder() of your devices in the UI.

    +

    XXXXXXXXXXXXX is the device id of each camera. You can get this from GetDevices(). +{ +"devices":{ +"XXXXXXXXXXXXX":1, +"XXXXXXXXXXXXX":2, +"XXXXXXXXXXXXX":3 +} +}

    +
    +
    +def UpdateFriend(self, body) +
    +
    +

    This is an example of the json you would pass in the body: +{ +"firstName":"Some", +"lastName":"Body", +"devices":{ +"XXXXXXXXXXXXX":"Camera 1", +"XXXXXXXXXXXXX":"Camera 2 ", +"XXXXXXXXXXXXX":"Camera 3" +}, +"lastModified":1463977440911, +"adminUser":true, +"email":"user@example.com", +"id":"XXX-XXXXXXX" +}

    +
    +
    +def UpdatePassword(self, password) +
    +
    +
    +
    +
    +def UpdateProfile(self, first_name, last_name) +
    +
    +
    +
    +
    +def genTransId(self, trans_type='web') +
    +
    +
    +
    +
    +def interrupt_handler(self, signum, frame) +
    +
    +
    +
    +
    +def to_timestamp(self, dt) +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + diff --git a/RPI Code/Arlo/eventstream.py b/RPI Code/Arlo/eventstream.py new file mode 100644 index 0000000..b23f990 --- /dev/null +++ b/RPI Code/Arlo/eventstream.py @@ -0,0 +1,111 @@ +## +# Copyright 2016 Jeffrey D. Walter +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## + +import monotonic +import sseclient +import threading +import sys + +if sys.version[0] == '2': + import Queue as queue +else: + import queue as queue + +# TODO: There's a lot more refactoring that could/should be done to abstract out the arlo-specific implementation details. + +class EventStream(object): + """This class provides a queue-based EventStream object.""" + def __init__(self, event_handler, heartbeat_handler, args): + self.connected = False + self.registered = False + self.queue = queue.Queue() + self.heartbeat_stop_event = threading.Event() + self.event_stream_stop_event = threading.Event() + self.arlo = args[0] + self.heartbeat_handler = heartbeat_handler + + try: + event_stream = sseclient.SSEClient('https://my.arlo.com/hmsweb/client/subscribe?token='+self.arlo.request.session.headers.get('Authorization'), session=self.arlo.request.session) + self.event_stream_thread = threading.Thread(name="EventStream", target=event_handler, args=(self.arlo, event_stream, self.event_stream_stop_event, )) + self.event_stream_thread.setDaemon(True) + print(self.arlo.request) + print(self.arlo) + except Exception as e: + raise Exception('Failed to subscribe to eventstream: {0}'.format(e)) + + def __del__(self): + self.Disconnect() + + def Get(self, block=True, timeout=None): + if sys.version[0] == '2' and block: + if timeout: + timeout += monotonic.monotonic() + # If timeout is None, then just pick some arbitrarily large # for the timeout value. + else: + timeout = 1000000 + monotonic.monotonic() + + while True: + try: + # Allow check for Ctrl-C every second + item = self.queue.get(timeout=min(1, timeout - monotonic.monotonic())) + self.queue.task_done() + return item + except queue.Empty: + if monotonic.monotonic() > timeout: + return None + else: + pass + else: + try: + item = self.queue.get(block=block, timeout=timeout) + self.queue.task_done() + return item + except queue.Empty as e: + return None + except Exception as e: + return None + + def Start(self): + self.event_stream_thread.start() + return self + + def Connect(self): + self.connected = True + + def Disconnect(self): + self.connected = False + self.Unregister() + + def Register(self): + self.heartbeat_thread = threading.Thread(name='HeartbeatThread', target=self.heartbeat_handler, args=(self.arlo, self.heartbeat_stop_event, )) + self.heartbeat_thread.setDaemon(True) + self.heartbeat_thread.start() + self.registered = True + + def Unregister(self): + self.registered = False + + if self.queue: + self.queue.put(None) + + self.event_stream_stop_event.set() + self.heartbeat_stop_event.set() + + if self.event_stream_thread != threading.current_thread(): + self.event_stream_thread.join() + + if self.heartbeat_thread != threading.current_thread(): + self.heartbeat_thread.join() diff --git a/RPI Code/Arlo/examples/arlo-adjustbrightness.py b/RPI Code/Arlo/examples/arlo-adjustbrightness.py new file mode 100644 index 0000000..837a170 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-adjustbrightness.py @@ -0,0 +1,36 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Set camera brightness to 0%. + #arlo.AdjustBrightness(basestations[0], cameras[0] -2) + + # Set camera brightness to 25%. + #arlo.AdjustBrightness(basestations[0], cameras[0], -1) + + # Set camera brightness to 50%. + arlo.AdjustBrightness(basestations[0], cameras[0], 0) + + # Set camera brightness to 75%. + #arlo.AdjustBrightness(basestations[0], cameras[0], 1) + + # Set camera brightness to 100%. + #arlo.AdjustBrightness(basestations[0], cameras[0], 2) + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-cvrdownload.py b/RPI Code/Arlo/examples/arlo-cvrdownload.py new file mode 100644 index 0000000..148c607 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-cvrdownload.py @@ -0,0 +1,88 @@ +import sys, os +sys.path.append('..') +import requests +from arlo import Arlo +from datetime import timedelta, date +import datetime +import json +import re + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +videopath = 'videos' +cameraNumber = 2 +datetimeFrom = datetime.datetime.strptime('2018-08-11 03:00:00', '%Y-%m-%d %H:%M:%S'); +datetimeTo = datetime.datetime.strptime('2018-08-11 04:00:00', '%Y-%m-%d %H:%M:%S'); + + +try: + print("Downloading cvr videos from " + datetimeFrom.strftime("%Y-%m-%d %H:%M:%S") + " to " + datetimeTo.strftime("%Y-%m-%d %H:%M:%S")) + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Get all of the recordings for a date range. + playlist = arlo.GetCvrPlaylist(cameras[cameraNumber], datetimeFrom.strftime("%Y%m%d"), datetimeTo.strftime("%Y%m%d")) + + # If no recordings are available exit + if not playlist['playlist']: + print("No playlist found for camera for the period " + datetimeFrom.strftime("%Y-%m-%d %H:%M:%S") + " and " + datetimeTo.strftime("%Y-%m-%d %H:%M:%S")) + arlo.Logout() + print('Logged out') + sys.exit() + + + # Check if videos folder already exists + if not os.path.exists(videopath): + os.makedirs(videopath) + + # debug to show the playlist json + # print(json.dumps(playlist, indent = 4)) + + # Iterate through each day in the cvr playlist. + for playlistPerDay in playlist['playlist']: + # Iterate through each m3u8 (playlist) file + for recordings in playlist['playlist'][playlistPerDay]: + m3u8 = requests.get(recordings['url']).text.split("\n") + # Iterate the m3u8 file and get all the streams + for m3u8Line in m3u8: + # debug to show the m3u8 file + # print m3u8Line + + # Split the url into parts used for filename (camera id and timestamp) + m = re.match("^http.+([A-Z0-9]{13})_[0-9]{13}_([0-9]{13})", m3u8Line) + if m: + cameraId = m.group(1) + videoTime = datetime.datetime.fromtimestamp(int(m.group(2)) // 1000) + + # If we are within desired range, then download + if videoTime > datetimeFrom and videoTime < datetimeTo: + # Get video as a chunked stream; this function returns a generator. + stream = arlo.StreamRecording(m3u8Line) + videofilename = cameraId + '-' + videoTime.strftime('%Y%m%d-%H%M%S') + '.mp4' + + # Skip files already downloaded + if os.path.isfile(videopath + '/' + videofilename): + print("Video " + videofilename + " already exists") + else: + print('Downloading video ' + videofilename) + with open(videopath + '/' + videofilename, 'wb') as f: + for chunk in stream: + f.write(chunk) + f.close() + + arlo.Logout() + print('Logged out') + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-download-bycamera.py b/RPI Code/Arlo/examples/arlo-download-bycamera.py new file mode 100644 index 0000000..330b5d5 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-download-bycamera.py @@ -0,0 +1,75 @@ +from arlo import Arlo + +from datetime import timedelta, date +import datetime +import sys, os +sys.path.append('..') +#import json + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +videopath = 'videos' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the cameras. + # This will return an array which includes all of the canera's associated metadata + # and includes Arlo Q devices, re: https://github.com/jeffreydwalter/arlo/wiki/FAQ#frequently-asked-questions + cameras = arlo.GetDevices('camera') + arloq = arlo.GetDevices('arloq') + arloqs = arlo.GetDevices('arloqs') + + cameras = cameras + arloq + arloqs + cameras_by_id = {} + + # setup a hash where each camera deviceId is assocaited with its name for lookup later + for camera in cameras: + cameras_by_id[camera['deviceId']] = camera['deviceName'] + + today = (date.today() - timedelta(days=0)).strftime("%Y%m%d") + seven_days_ago = (date.today() - timedelta(days=7)).strftime("%Y%m%d") + + # Get all of the recordings for a date range. + library = arlo.GetLibrary(seven_days_ago, today) + + # Check if videos folder already exists + if not os.path.exists(videopath): + os.makedirs(videopath) + + # Iterate through the recordings in the library. + for recording in library: + + # Set the extension based on the content type of the returned media + content_type = recording['contentType'] + extension = '.jpg' if content_type == 'image/jpg' else '.mp4' + + # Grab the camera name to use for the filename from the cameras_by_id hash above + camera_name = cameras_by_id[recording['deviceId']] + + videofilename = camera_name + ' - ' + datetime.datetime.fromtimestamp(int(recording['name']) // 1000).strftime('%Y-%m-%d %H-%M-%S') + extension + + # Download the video and write it to the given path. + arlo.DownloadRecording(recording['presignedContentUrl'], videopath + '/' + videofilename) + + print('Downloaded video ' + videofilename + ' from ' + recording['createdDate'] + '.') + + # Use the following line to print all the data we got for the recording. + #print(json.dumps(recording, indent = 4)) + + # Delete all of the videos you just downloaded from the Arlo library. + # Notice that you can pass the "library" object we got back from the GetLibrary() call. + #result = arlo.BatchDeleteRecordings(library) + + # If we made it here without an exception, then the videos were successfully deleted. + #print ('Batch deletion of videos completed successfully.') + + arlo.Logout() + print('Logged out') + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-download.py b/RPI Code/Arlo/examples/arlo-download.py new file mode 100644 index 0000000..b01a13b --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-download.py @@ -0,0 +1,59 @@ +from arlo import Arlo + +from datetime import timedelta, date +import datetime +import sys, os +sys.path.append('..') +#import json + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +videopath = 'videos' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + today = (date.today() - timedelta(days=0)).strftime("%Y%m%d") + seven_days_ago = (date.today() - timedelta(days=7)).strftime("%Y%m%d") + + # Get all of the recordings for a date range. + library = arlo.GetLibrary(seven_days_ago, today) + + # Check if videos folder already exists + if not os.path.exists(videopath): + os.makedirs(videopath) + + # Iterate through the recordings in the library. + for recording in library: + # Get video as a chunked stream; this function returns a generator. + stream = arlo.StreamRecording(recording['presignedContentUrl']) + videofilename = datetime.datetime.fromtimestamp( + int(recording['name']) // 1000).strftime( + '%Y-%m-%d %H-%M-%S') + ' ' + recording['uniqueId'] + '.mp4' + with open(videopath + '/' + videofilename, 'wb') as f: + for chunk in stream: + f.write(chunk) + f.close() + + print('Downloaded video ' + videofilename + ' from ' + + recording['createdDate'] + '.') + + # Use the following line to print all the data we got for the recording. + #print(json.dumps(recording, indent = 4)) + + # Delete all of the videos you just downloaded from the Arlo library. + # Notice that you can pass the "library" object we got back from the GetLibrary() call. + #result = arlo.BatchDeleteRecordings(library) + + # If we made it here without an exception, then the videos were successfully deleted. + #print ('Batch deletion of videos completed successfully.') + + arlo.Logout() + print('Logged out') + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-fullscreensnapshot.py b/RPI Code/Arlo/examples/arlo-fullscreensnapshot.py new file mode 100644 index 0000000..09f58a3 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-fullscreensnapshot.py @@ -0,0 +1,31 @@ +from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Tells the Arlo basestation to trigger a snapshot on the given camera. + # This snapshot is not instantaneous, so this method waits for the response and returns the url + # for the snapshot, which is stored on the Amazon AWS servers. + snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]) + + # This method requests the snapshot for the given url and writes the image data to the location specified. + # In this case, to the current directory as a file named "snapshot.jpg" + # Note: Snapshots are in .jpg format. + arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg') + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-motiondetect.py b/RPI Code/Arlo/examples/arlo-motiondetect.py new file mode 100644 index 0000000..48e2bd0 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-motiondetect.py @@ -0,0 +1,32 @@ +from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' + +try: + + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + cameras = arlo.GetDevices('camera') + # Define a callback function that will get called once for each motion event. + def callback(arlo, event): + # Here you will have access to self, basestation_id, xcloud_id, and the event schema. + print("motion event detected!") + print(event) + print(arlo) + #print("try to take snapshot") + #snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]) + #arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg') + + #print(basestations) + + # Subscribe to motion events. This method blocks until the event stream is closed. (You can close the event stream in the callback if you no longer want to listen for events.) + arlo.SubscribeToMotionEvents(basestations[0], callback) +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-motiondetect.py.save b/RPI Code/Arlo/examples/arlo-motiondetect.py.save new file mode 100644 index 0000000..06f082f --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-motiondetect.py.save @@ -0,0 +1,31 @@ +cameras = arlo.GetDevices('camera')from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' + +try: + + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Define a callback function that will get called once for each motion event. + def callback(arlo, event): + # Here you will have access to self, basestation_id, xcloud_id, and the event schema. + print("motion event detected!") + print(event) + print(arlo) + snapshot_url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]) + arlo.DownloadSnapshot(snapshot_url, 'snapshot.jpg') + + #print(basestations) + + # Subscribe to motion events. This method blocks until the event stream is closed. (You can close the event stream in the callback if you no longer want to listen for events.) + arlo.SubscribeToMotionEvents(basestations[0], callback) +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-setmode.py b/RPI Code/Arlo/examples/arlo-setmode.py new file mode 100644 index 0000000..47973c6 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-setmode.py @@ -0,0 +1,29 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Arm Arlo. + arlo.Arm(basestations[0]) + # Or + # Disarm Arlo. + # arlo.Disarm(basestations[0]) + # Or + # Change Mode to some custom mode you created. + # arlo.CustomMode(basestations[0], "mode3") # 'mode3' is the id of a custom mode you created. + # Or + # Change Mode to Schedule. + # arlo.CustomMode(basestations[0], mode=None, schedules=['schedules.1']) # 'schedules.1' is the id of my default schedule." + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-snapshot.py b/RPI Code/Arlo/examples/arlo-snapshot.py new file mode 100644 index 0000000..95f3374 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-snapshot.py @@ -0,0 +1,44 @@ +from arlo import Arlo + +USERNAME = 'fransolet.thomas@gmail.com' +PASSWORD = 'Coconuts09' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the cameras. + # This will return an array of cameras, including all of the cameras' associated metadata. + cameras = arlo.GetDevices('camera') + + # Trigger the snapshot. + url = arlo.TriggerFullFrameSnapshot(basestations[0], cameras[0]); + + # Download snapshot. + arlo.DownloadSnapshot(url, 'snapshot.jpg') + + # If you are already recording, or have a need to snapshot while recording, you can do so like this: + """ + # Starting recording with a camera. + arlo.StartRecording(basestations[0], cameras[0]); + + # Wait for 4 seconds while the camera records. (There are probably better ways to do this, but you get the idea.) + time.sleep(4) + + # Trigger the snapshot. + url = arlo.TriggerStreamSnapshot(basestations[0], cameras[0]); + + # Download snapshot. + arlo.DownloadSnapshot(url, 'snapshot.jpg') + + # Stop recording. + arlo.StopRecording(cameras[0]); + """ +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-streamingvideo.py b/RPI Code/Arlo/examples/arlo-streamingvideo.py new file mode 100644 index 0000000..8602b26 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-streamingvideo.py @@ -0,0 +1,39 @@ +from arlo import Arlo + +from subprocess import call + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + + # Instantiating the Arlo object automatically calls Login(), + # which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the cameras. + # This will return an array which includes all of the canera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Send the command to start the stream and return the stream url. + url = arlo.StartStream(basestations[0], cameras[0]) + + # Record the stream to a file named 'test.mp4'. + # **Requires ffmpeg 3.4 or greater.** + # For this example, I'm going to open ffmpeg. + # Crucially important is the '-t' flag, which specifies a recording time. (See the ffmpeg documentation.) + # This is just a crude example, but hopefully it will give you some ideas. + # You can use any number of libraries to do the actual streaming. OpenCV or VLC are both good choices. + # NOTE: This will print the output of ffmpeg to STDOUT/STDERR. If you don't want that, you will + # need to pass additional arguments to handle those streams. + + call(['ffmpeg', '-re', '-i', url, '-t', '10', '-acodec', 'copy', '-vcodec', 'copy', 'test.mp4']) + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlo-togglecamera.py b/RPI Code/Arlo/examples/arlo-togglecamera.py new file mode 100644 index 0000000..544e2b3 --- /dev/null +++ b/RPI Code/Arlo/examples/arlo-togglecamera.py @@ -0,0 +1,26 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestations. + # This will return an array of basestations, including all of the basestations' associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the cameras. + # This will return an array of cameras, including all of the cameras' associated metadata. + cameras = arlo.GetDevices('camera') + + # Turn camera on. + print(arlo.ToggleCamera(basestations[0], cameras[0], True)) + # Turn camera off. + #print(arlo.ToggleCamera(basestations[0], cameras[0], False)) + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlobaby-audiocontrol.py b/RPI Code/Arlo/examples/arlobaby-audiocontrol.py new file mode 100644 index 0000000..a6bd119 --- /dev/null +++ b/RPI Code/Arlo/examples/arlobaby-audiocontrol.py @@ -0,0 +1,39 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Get current state payload + arlo.GetAudioPlayback(cameras[0]) + + # Start playing + arlo.PlayTrack(cameras[0], track_id, position) + + # Pause the track + arlo.PauseTrack(cameras[0]) + + # Skip the track + arlo.SkipTrack(cameras[0]) + + # Set the sleep timer + arlo.SetSleepTimerOn(cameras[0]) + + # Set the playback mode ot continuous + arlo.SetLoopBackModeContinuous(cameras[0]) + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlobaby-nightlightcontrol.py b/RPI Code/Arlo/examples/arlobaby-nightlightcontrol.py new file mode 100644 index 0000000..8adda23 --- /dev/null +++ b/RPI Code/Arlo/examples/arlobaby-nightlightcontrol.py @@ -0,0 +1,34 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Get current state payload + state=arlo.GetCameraState(cameras[0]) + print(state["properties"][0]["nightLight"]) + + # night light on + arlo.SetNightLightOn(cameras[0]) + + # night light timer on + arlo.SetNightLightTimerOn(cameras[0], 500) + + # night light color mode + arlo.SetNightLightMode(cameras[0], mode={"blue":255,"green":255,"red":255 }) # or mode="rainbow" + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/examples/arlobaby-tempcontrol.py b/RPI Code/Arlo/examples/arlobaby-tempcontrol.py new file mode 100644 index 0000000..92ae76e --- /dev/null +++ b/RPI Code/Arlo/examples/arlobaby-tempcontrol.py @@ -0,0 +1,36 @@ +from arlo import Arlo + +USERNAME = 'user@example.com' +PASSWORD = 'supersecretpassword' + +try: + # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. + # Subsequent successful calls to login will update the oAuth token. + arlo = Arlo(USERNAME, PASSWORD) + # At this point you're logged into Arlo. + + # Get the list of devices and filter on device type to only get the basestation. + # This will return an array which includes all of the basestation's associated metadata. + basestations = arlo.GetDevices('basestation') + + # Get the list of devices and filter on device type to only get the camera. + # This will return an array which includes all of the camera's associated metadata. + cameras = arlo.GetDevices('camera') + + # Turn temperature alerts on + arlo.TempAlertOn(cameras[0]) + + # Alert min threshold (so if temp falls below this number it alerts) + arlo.SetTempAlertThresholdMin(cameras[0], 170) + + # Alert max threshold (so if temp go above this number it alerts) + arlo.SetTempAlertThresholdMax(cameras[0], 270) + + # record temperature history + arlo.TempRecordingOn(cameras[0]) + + # Set the temperature unit to Celcius + arlo.SetTempUnit(cameras[0]["uniqueId"], "C") + +except Exception as e: + print(e) diff --git a/RPI Code/Arlo/logo.png b/RPI Code/Arlo/logo.png new file mode 100644 index 0000000..d33a195 Binary files /dev/null and b/RPI Code/Arlo/logo.png differ diff --git a/RPI Code/Arlo/request.py b/RPI Code/Arlo/request.py new file mode 100644 index 0000000..f5e6b58 --- /dev/null +++ b/RPI Code/Arlo/request.py @@ -0,0 +1,55 @@ +## +# Copyright 2016 Jeffrey D. Walter +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## + +import requests +from requests.exceptions import HTTPError + +class Request(object): + """HTTP helper class""" + + def __init__(self): + self.session = requests.Session() + + def _request(self, url, method='GET', params={}, headers={}, stream=False, raw=False): + if method == 'GET': + r = self.session.get(url, params=params, headers=headers, stream=stream) + if stream is True: + return r + elif method == 'PUT': + r = self.session.put(url, json=params, headers=headers) + elif method == 'POST': + r = self.session.post(url, json=params, headers=headers) + + r.raise_for_status() + body = r.json() + + if raw: + return body + else: + if body['success'] == True: + if 'data' in body: + return body['data'] + else: + raise HTTPError('Request ({0} {1}) failed: {2}'.format(method, url, r.json()), response=r) + + def get(self, url, params={}, headers={}, stream=False, raw=False): + return self._request(url, 'GET', params, headers, stream, raw) + + def put(self, url, params={}, headers={}, raw=False): + return self._request(url, 'PUT', params, headers, raw) + + def post(self, url, params={}, headers={}, raw=False): + return self._request(url, 'POST', params, headers, raw) diff --git a/RPI Code/Arlo/requirements.txt b/RPI Code/Arlo/requirements.txt new file mode 100644 index 0000000..5723d63 --- /dev/null +++ b/RPI Code/Arlo/requirements.txt @@ -0,0 +1,15 @@ +# +# This file is autogenerated by pip-compile +# To update, run: +# +# pip-compile +# +certifi==2019.9.11 # via requests +chardet==3.0.4 # via requests +idna==2.8 # via requests +monotonic==1.5 +pysocks==1.7.1 +requests==2.22.0 +six==1.12.0 # via sseclient +sseclient==0.0.22 +urllib3==1.25.6 # via requests diff --git a/RPI Code/Arlo/setup.cfg b/RPI Code/Arlo/setup.cfg new file mode 100644 index 0000000..24378bc --- /dev/null +++ b/RPI Code/Arlo/setup.cfg @@ -0,0 +1,5 @@ +[bdist_wheel] +universal=1 + +[metadata] +description-file = README.md diff --git a/RPI Code/Arlo/setup.py b/RPI Code/Arlo/setup.py new file mode 100644 index 0000000..62aea52 --- /dev/null +++ b/RPI Code/Arlo/setup.py @@ -0,0 +1,44 @@ +# coding=utf-8 +"""Python Arlo setup script.""" +from setuptools import setup + +def readme(): + with open('README.md') as desc: + return desc.read() + +setup( + name='arlo', + py_modules=['arlo', 'request', 'eventstream'], + version='1.2.33', + description='Python Arlo is a library written in Python 2.7/3x ' + + 'which exposes the Netgear Arlo cameras via the apis that are consumed by their website.', + long_description=readme(), + long_description_content_type='text/markdown', + author='Jeffrey D. Walter', + author_email='jeffreydwalter@gmail.com', + url='https://github.com/jeffreydwalter/arlo', + license='Apache Software License', + include_package_data=True, + install_requires=['monotonic', 'requests', 'sseclient==0.0.22', 'PySocks'], + keywords=[ + 'arlo', + 'camera', + 'home automation', + 'netgear', + 'python', + ], + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Other Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Topic :: Software Development :: Libraries :: Python Modules' + ], +) diff --git a/RPI Code/Arlo/snapshot.jpg b/RPI Code/Arlo/snapshot.jpg new file mode 100644 index 0000000..fbaf1fe Binary files /dev/null and b/RPI Code/Arlo/snapshot.jpg differ diff --git a/RPI Code/Arlo/tests/__init__.py b/RPI Code/Arlo/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/RPI Code/Arlo/tests/context.py b/RPI Code/Arlo/tests/context.py new file mode 100644 index 0000000..7e6e5b6 --- /dev/null +++ b/RPI Code/Arlo/tests/context.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- + +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +import Arlo diff --git a/RPI Code/SmartGarden/allInOne.py b/RPI Code/SmartGarden/allInOne.py index ea5fe20..a6a6e1a 100644 --- a/RPI Code/SmartGarden/allInOne.py +++ b/RPI Code/SmartGarden/allInOne.py @@ -7,12 +7,12 @@ from ctypes import c_ubyte import paho.mqtt.client as mqtt import socket -broker="192.168.31.118" -#username="oilkfgjy" -#password="lEyZb90q49Rf" +broker="192.168.31.140" +username="mqtt" +password="mqtt" -mqttc = mqtt.Client("SmartGarden_PiZero") -#mqttc.username_pw_set(username, password) +mqttc = mqtt.Client("SmartGarden_PiZero1") +mqttc.username_pw_set(username, password) delayBetweenSending = 300