| ... | ... |
@@ -6,7 +6,7 @@ |
| 6 | 6 |
*/ |
| 7 | 7 |
{
|
| 8 | 8 |
// Declares the existence of the globals available in PebbleKit JS. |
| 9 |
- "globals": {"console": true, "Int8Array": true, "Pebble": true, "setTimeout": true, "localStorage": true, "Uint8Array": true, "require": true, "Uint8ClampedArray": true, "Int32Array": true, "exports": true, "Uint16Array": true, "module": true, "Float64Array": true, "Uint32Array": true, "XMLHttpRequest": true, "Int16Array": true, "setInterval": true, "WebSocket": true, "Float32Array": true, "navigator": true},
|
|
| 9 |
+ "globals": {"setInterval": true, "Float64Array": true, "Pebble": true, "Uint32Array": true, "WebSocket": true, "module": true, "exports": true, "require": true, "console": true, "XMLHttpRequest": true, "Int32Array": true, "setTimeout": true, "navigator": true, "Uint8Array": true, "Uint8ClampedArray": true, "Uint16Array": true, "Int8Array": true, "Int16Array": true, "localStorage": true, "Float32Array": true},
|
|
| 10 | 10 |
|
| 11 | 11 |
// Do not mess with standard JavaScript objects (Array, Date, etc) |
| 12 | 12 |
"freeze": true, |
| ... | ... |
@@ -4,12 +4,12 @@ |
| 4 | 4 |
"pebble-clay": "^1.0.0" |
| 5 | 5 |
}, |
| 6 | 6 |
"keywords": [], |
| 7 |
- "name": "cam-switch", |
|
| 7 |
+ "name": "dscam-h-s", |
|
| 8 | 8 |
"pebble": {
|
| 9 | 9 |
"capabilities": [ |
| 10 | 10 |
"configurable" |
| 11 | 11 |
], |
| 12 |
- "displayName": "SynoCam Home switch", |
|
| 12 |
+ "displayName": "DSCam Home-Switch", |
|
| 13 | 13 |
"enableMultiJS": true, |
| 14 | 14 |
"messageKeys": [ |
| 15 | 15 |
"status", |
| ... | ... |
@@ -56,5 +56,5 @@ |
| 56 | 56 |
"watchface": false |
| 57 | 57 |
} |
| 58 | 58 |
}, |
| 59 |
- "version": "1.0.0" |
|
| 59 |
+ "version": "1.1.0" |
|
| 60 | 60 |
} |
| ... | ... |
@@ -9,170 +9,178 @@ function get_status() {
|
| 9 | 9 |
var response; |
| 10 | 10 |
sid=""; |
| 11 | 11 |
console.log('---- authenticate');
|
| 12 |
- var username=localStorage.getItem('username');
|
|
| 13 |
- var password=localStorage.getItem('password');
|
|
| 14 |
- var server=localStorage.getItem('server');
|
|
| 15 |
- var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid"; |
|
| 16 |
- var xhr = new XMLHttpRequest(); |
|
| 17 |
- |
|
| 18 |
- xhr.open("GET", url,false);
|
|
| 19 |
- xhr.send(); |
|
| 20 |
- |
|
| 21 |
- if(xhr.status == 200) {
|
|
| 22 |
- response = JSON.parse(xhr.responseText); |
|
| 23 |
- if (response.success == true){
|
|
| 24 |
- sid = response.data.sid; |
|
| 25 |
- } |
|
| 26 |
- }else {
|
|
| 27 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 28 |
- } |
|
| 29 |
- |
|
| 30 |
- if (sid != ""){
|
|
| 31 |
- status = ""; |
|
| 32 |
- console.log('---- get_status');
|
|
| 33 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 34 |
- |
|
| 12 |
+ if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 13 |
+ var username=localStorage.getItem('username');
|
|
| 14 |
+ var password=localStorage.getItem('password');
|
|
| 15 |
+ var server=localStorage.getItem('server');
|
|
| 16 |
+ var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid"; |
|
| 17 |
+ var xhr = new XMLHttpRequest(); |
|
| 18 |
+ |
|
| 35 | 19 |
xhr.open("GET", url,false);
|
| 36 | 20 |
xhr.send(); |
| 37 |
- |
|
| 21 |
+ |
|
| 38 | 22 |
if(xhr.status == 200) {
|
| 39 | 23 |
response = JSON.parse(xhr.responseText); |
| 40 | 24 |
if (response.success == true){
|
| 41 |
- status=response.data.on; |
|
| 42 |
- var message; |
|
| 43 |
- switch (status) {
|
|
| 44 |
- case true: |
|
| 45 |
- message = "Your Home mode is ON"; |
|
| 46 |
- break; |
|
| 47 |
- case false: |
|
| 48 |
- message = "Your Home mode is OFF"; |
|
| 49 |
- break; |
|
| 50 |
- default: |
|
| 51 |
- message = "home mode is unknown !"; |
|
| 52 |
- } |
|
| 53 |
- // Build message |
|
| 54 |
- var dict = {
|
|
| 55 |
- 'status': message, |
|
| 56 |
- }; |
|
| 57 |
- |
|
| 58 |
- // Send the message |
|
| 59 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 60 |
- console.log('sent');
|
|
| 61 |
- }, function() {
|
|
| 62 |
- console.log('failed');
|
|
| 63 |
- }); |
|
| 25 |
+ sid = response.data.sid; |
|
| 64 | 26 |
} |
| 65 | 27 |
}else {
|
| 66 | 28 |
console.log('------Request returned error code ' + xhr.status.toString());
|
| 67 | 29 |
} |
| 68 |
- } |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 |
- |
|
| 72 |
-function switch_home(bool) {
|
|
| 73 |
- var response; |
|
| 74 |
- sid=""; |
|
| 75 |
- console.log('---- authenticate');
|
|
| 76 |
- var username=localStorage.getItem('username');
|
|
| 77 |
- var password=localStorage.getItem('password');
|
|
| 78 |
- var server=localStorage.getItem('server');
|
|
| 79 |
- var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid"; |
|
| 80 |
- var xhr = new XMLHttpRequest(); |
|
| 81 |
- |
|
| 82 |
- xhr.open("GET", url,false);
|
|
| 83 |
- xhr.send(); |
|
| 84 |
- |
|
| 85 |
- if(xhr.status == 200) {
|
|
| 86 |
- response = JSON.parse(xhr.responseText); |
|
| 87 |
- if (response.success == true){
|
|
| 88 |
- sid = response.data.sid; |
|
| 89 |
- console.log('------ sid = '+sid);
|
|
| 90 |
- } |
|
| 91 |
- }else {
|
|
| 92 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 93 |
- } |
|
| 94 |
- |
|
| 95 |
- if (sid != ""){
|
|
| 96 |
- status = ""; |
|
| 97 |
- console.log('---- get_status');
|
|
| 98 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 99 |
- |
|
| 100 |
- xhr.open("GET", url,false);
|
|
| 101 |
- xhr.send(); |
|
| 102 |
- |
|
| 103 |
- if(xhr.status == 200) {
|
|
| 104 |
- response = JSON.parse(xhr.responseText); |
|
| 105 |
- if (response.success == true){
|
|
| 106 |
- status=response.data.on; |
|
| 107 |
- console.log('------ status:'+status);
|
|
| 108 |
- var message; |
|
| 109 |
- var dict; |
|
| 110 |
- if ( status != bool){
|
|
| 111 |
- console.log('---- switching home mode to '+ bool);
|
|
| 112 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on="+bool+"&_sid="+sid; |
|
| 113 |
- |
|
| 114 |
- xhr.open("GET", url,false);
|
|
| 115 |
- xhr.send(); |
|
| 30 |
+ |
|
| 31 |
+ if (sid != ""){
|
|
| 32 |
+ status = ""; |
|
| 33 |
+ console.log('---- get_status');
|
|
| 34 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 116 | 35 |
|
| 117 |
- if(xhr.status == 200) {
|
|
| 118 |
- response = JSON.parse(xhr.responseText); |
|
| 119 |
- if (response.success == true){
|
|
| 120 |
- status=bool; |
|
| 121 |
- switch (status) {
|
|
| 122 |
- case true: |
|
| 123 |
- message = "You just set Home mode ON"; |
|
| 124 |
- break; |
|
| 125 |
- case false: |
|
| 126 |
- message = "You just set Home mode off"; |
|
| 127 |
- break; |
|
| 128 |
- default: |
|
| 129 |
- message = "something happened, try again !"; |
|
| 130 |
- } |
|
| 131 |
- // Build message |
|
| 132 |
- dict = {
|
|
| 133 |
- 'status': message, |
|
| 134 |
- }; |
|
| 135 |
- |
|
| 136 |
- // Send the message |
|
| 137 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 138 |
- console.log('sent');
|
|
| 139 |
- }, function() {
|
|
| 140 |
- console.log('failed');
|
|
| 141 |
- }); |
|
| 142 |
- } |
|
| 143 |
- }else {
|
|
| 144 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 145 |
- } |
|
| 146 |
- }else{
|
|
| 147 |
- console.log('---- nothign to do, status already '+status);
|
|
| 36 |
+ xhr.open("GET", url,false);
|
|
| 37 |
+ xhr.send(); |
|
| 38 |
+ |
|
| 39 |
+ if(xhr.status == 200) {
|
|
| 40 |
+ response = JSON.parse(xhr.responseText); |
|
| 41 |
+ if (response.success == true){
|
|
| 42 |
+ status=response.data.on; |
|
| 43 |
+ var message; |
|
| 148 | 44 |
switch (status) {
|
| 149 | 45 |
case true: |
| 150 |
- message = "Your Home Mode is already ON"; |
|
| 46 |
+ message = "Your Home mode is ON"; |
|
| 151 | 47 |
break; |
| 152 | 48 |
case false: |
| 153 |
- message = "Your Home Mode is already off"; |
|
| 49 |
+ message = "Your Home mode is OFF"; |
|
| 154 | 50 |
break; |
| 155 | 51 |
default: |
| 156 |
- message = "something happened, try again !"; |
|
| 157 |
- } |
|
| 52 |
+ message = "home mode is unknown !"; |
|
| 53 |
+ } |
|
| 158 | 54 |
// Build message |
| 159 |
- dict = {
|
|
| 55 |
+ var dict = {
|
|
| 160 | 56 |
'status': message, |
| 161 | 57 |
}; |
| 162 |
- |
|
| 58 |
+ |
|
| 163 | 59 |
// Send the message |
| 164 | 60 |
Pebble.sendAppMessage(dict, function(e) {
|
| 165 | 61 |
console.log('sent');
|
| 166 | 62 |
}, function() {
|
| 167 | 63 |
console.log('failed');
|
| 168 |
- }); |
|
| 64 |
+ }); |
|
| 169 | 65 |
} |
| 66 |
+ }else {
|
|
| 67 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 68 |
+ } |
|
| 69 |
+ } |
|
| 70 |
+ |
|
| 71 |
+ }else{
|
|
| 72 |
+ Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 73 |
+ } |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+ |
|
| 77 |
+function switch_home(bool) {
|
|
| 78 |
+ var response; |
|
| 79 |
+ sid=""; |
|
| 80 |
+ console.log('---- authenticate');
|
|
| 81 |
+ if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 82 |
+ var username=localStorage.getItem('username');
|
|
| 83 |
+ var password=localStorage.getItem('password');
|
|
| 84 |
+ var server=localStorage.getItem('server');
|
|
| 85 |
+ var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid"; |
|
| 86 |
+ var xhr = new XMLHttpRequest(); |
|
| 87 |
+ |
|
| 88 |
+ xhr.open("GET", url,false);
|
|
| 89 |
+ xhr.send(); |
|
| 90 |
+ |
|
| 91 |
+ if(xhr.status == 200) {
|
|
| 92 |
+ response = JSON.parse(xhr.responseText); |
|
| 93 |
+ if (response.success == true){
|
|
| 94 |
+ sid = response.data.sid; |
|
| 95 |
+ console.log('------ sid = '+sid);
|
|
| 170 | 96 |
} |
| 171 | 97 |
}else {
|
| 172 | 98 |
console.log('------Request returned error code ' + xhr.status.toString());
|
| 173 | 99 |
} |
| 100 |
+ |
|
| 101 |
+ if (sid != ""){
|
|
| 102 |
+ status = ""; |
|
| 103 |
+ console.log('---- get_status');
|
|
| 104 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 105 |
+ |
|
| 106 |
+ xhr.open("GET", url,false);
|
|
| 107 |
+ xhr.send(); |
|
| 108 |
+ |
|
| 109 |
+ if(xhr.status == 200) {
|
|
| 110 |
+ response = JSON.parse(xhr.responseText); |
|
| 111 |
+ if (response.success == true){
|
|
| 112 |
+ status=response.data.on; |
|
| 113 |
+ console.log('------ status:'+status);
|
|
| 114 |
+ var message; |
|
| 115 |
+ var dict; |
|
| 116 |
+ if ( status != bool){
|
|
| 117 |
+ console.log('---- switching home mode to '+ bool);
|
|
| 118 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on="+bool+"&_sid="+sid; |
|
| 119 |
+ |
|
| 120 |
+ xhr.open("GET", url,false);
|
|
| 121 |
+ xhr.send(); |
|
| 122 |
+ |
|
| 123 |
+ if(xhr.status == 200) {
|
|
| 124 |
+ response = JSON.parse(xhr.responseText); |
|
| 125 |
+ if (response.success == true){
|
|
| 126 |
+ status=bool; |
|
| 127 |
+ switch (status) {
|
|
| 128 |
+ case true: |
|
| 129 |
+ message = "You just set Home mode ON"; |
|
| 130 |
+ break; |
|
| 131 |
+ case false: |
|
| 132 |
+ message = "You just set Home mode off"; |
|
| 133 |
+ break; |
|
| 134 |
+ default: |
|
| 135 |
+ message = "something happened, try again !"; |
|
| 136 |
+ } |
|
| 137 |
+ // Build message |
|
| 138 |
+ dict = {
|
|
| 139 |
+ 'status': message, |
|
| 140 |
+ }; |
|
| 141 |
+ |
|
| 142 |
+ // Send the message |
|
| 143 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 144 |
+ console.log('sent');
|
|
| 145 |
+ }, function() {
|
|
| 146 |
+ console.log('failed');
|
|
| 147 |
+ }); |
|
| 148 |
+ } |
|
| 149 |
+ }else {
|
|
| 150 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 151 |
+ } |
|
| 152 |
+ }else{
|
|
| 153 |
+ console.log('---- nothign to do, status already '+status);
|
|
| 154 |
+ switch (status) {
|
|
| 155 |
+ case true: |
|
| 156 |
+ message = "Your Home Mode is already ON"; |
|
| 157 |
+ break; |
|
| 158 |
+ case false: |
|
| 159 |
+ message = "Your Home Mode is already off"; |
|
| 160 |
+ break; |
|
| 161 |
+ default: |
|
| 162 |
+ message = "something happened, try again !"; |
|
| 163 |
+ } |
|
| 164 |
+ // Build message |
|
| 165 |
+ dict = {
|
|
| 166 |
+ 'status': message, |
|
| 167 |
+ }; |
|
| 168 |
+ |
|
| 169 |
+ // Send the message |
|
| 170 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 171 |
+ console.log('sent');
|
|
| 172 |
+ }, function() {
|
|
| 173 |
+ console.log('failed');
|
|
| 174 |
+ }); |
|
| 175 |
+ } |
|
| 176 |
+ } |
|
| 177 |
+ }else {
|
|
| 178 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 179 |
+ } |
|
| 180 |
+ } |
|
| 181 |
+ }else{
|
|
| 182 |
+ Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 174 | 183 |
} |
| 175 |
- |
|
| 176 | 184 |
|
| 177 | 185 |
} |
| 178 | 186 |
|
| ... | ... |
@@ -196,37 +204,4 @@ Pebble.addEventListener('appmessage', function(e) {
|
| 196 | 204 |
console.log('Sorry.');
|
| 197 | 205 |
} |
| 198 | 206 |
|
| 199 |
-}); |
|
| 200 |
-/* |
|
| 201 |
-// Get Configuration page |
|
| 202 |
-Pebble.addEventListener('showConfiguration', function() {
|
|
| 203 |
- var username=localStorage.getItem('username');
|
|
| 204 |
- var password=localStorage.getItem('password');
|
|
| 205 |
- var server=localStorage.getItem('server');
|
|
| 206 |
- var url = 'https://jonget.fr/pebble/config_homeswitch.php?username='+username+'&password='+password+'&server='+server; |
|
| 207 |
- |
|
| 208 |
- Pebble.openURL(url); |
|
| 209 |
-}); |
|
| 210 |
- |
|
| 211 |
-Pebble.addEventListener('webviewclosed', function(e) {
|
|
| 212 |
- // Decode the user's preferences |
|
| 213 |
- var configData = JSON.parse(decodeURIComponent(e.response)); |
|
| 214 |
- localStorage.setItem('username',configData.username);
|
|
| 215 |
- localStorage.setItem('password',configData.password);
|
|
| 216 |
- localStorage.setItem('server',configData.server);
|
|
| 217 |
- console.log('---- new username stored : '+localStorage.getItem('username'));
|
|
| 218 |
- console.log('---- new password stored : '+localStorage.getItem('password'));
|
|
| 219 |
- console.log('---- new server stored : '+localStorage.getItem('server'));
|
|
| 220 |
- var dict = {
|
|
| 221 |
- 'username': configData.username, |
|
| 222 |
- 'password': configData.password, |
|
| 223 |
- 'server': configData.server |
|
| 224 |
- }; |
|
| 225 |
- |
|
| 226 |
- // Send the message |
|
| 227 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 228 |
- console.log('sent');
|
|
| 229 |
- }, function() {
|
|
| 230 |
- console.log('failed');
|
|
| 231 |
- }); |
|
| 232 |
-});*/ |
|
| 233 | 207 |
\ No newline at end of file |
| 208 |
+}); |
|
| 234 | 209 |
\ No newline at end of file |