| ... | ... |
@@ -1,62 +1,61 @@ |
| 1 | 1 |
{
|
| 2 |
- "author": "ljonget@gmail.com", |
|
| 3 |
- "dependencies": {
|
|
| 4 |
- "pebble-clay": "^1.0.0" |
|
| 5 |
- }, |
|
| 6 |
- "keywords": [], |
|
| 7 |
- "name": "dscam-h-s", |
|
| 8 |
- "pebble": {
|
|
| 9 |
- "capabilities": [ |
|
| 10 |
- "configurable" |
|
| 11 |
- ], |
|
| 12 |
- "displayName": "DSCam Home-Switch", |
|
| 13 |
- "enableMultiJS": true, |
|
| 14 |
- "messageKeys": [ |
|
| 15 |
- "auth", |
|
| 16 |
- "status", |
|
| 17 |
- "server", |
|
| 18 |
- "username", |
|
| 19 |
- "password", |
|
| 20 |
- "JSReady" |
|
| 21 |
- ], |
|
| 22 |
- "projectType": "native", |
|
| 23 |
- "resources": {
|
|
| 24 |
- "media": [ |
|
| 25 |
- {
|
|
| 26 |
- "file": "images/icon.png", |
|
| 27 |
- "menuIcon": true, |
|
| 28 |
- "name": "IMAGE_MENU_ICON", |
|
| 29 |
- "targetPlatforms": null, |
|
| 30 |
- "type": "bitmap" |
|
| 31 |
- }, |
|
| 32 |
- {
|
|
| 33 |
- "file": "images/q_mark.png", |
|
| 34 |
- "name": "Q_MARK", |
|
| 35 |
- "targetPlatforms": null, |
|
| 36 |
- "type": "bitmap" |
|
| 37 |
- }, |
|
| 38 |
- {
|
|
| 39 |
- "file": "images/home_off.png", |
|
| 40 |
- "name": "HOME_OFF", |
|
| 41 |
- "targetPlatforms": null, |
|
| 42 |
- "type": "bitmap" |
|
| 2 |
+ "author": "ljonget@gmail.com", |
|
| 3 |
+ "dependencies": {
|
|
| 4 |
+ "pebble-clay": "^1.0.1" |
|
| 5 |
+ }, |
|
| 6 |
+ "keywords": [], |
|
| 7 |
+ "name": "dscam-h-s", |
|
| 8 |
+ "pebble": {
|
|
| 9 |
+ "capabilities": [ |
|
| 10 |
+ "configurable" |
|
| 11 |
+ ], |
|
| 12 |
+ "displayName": "DSCam Home-Switch", |
|
| 13 |
+ "enableMultiJS": true, |
|
| 14 |
+ "messageKeys": [ |
|
| 15 |
+ "auth", |
|
| 16 |
+ "status", |
|
| 17 |
+ "server", |
|
| 18 |
+ "username", |
|
| 19 |
+ "password", |
|
| 20 |
+ "JSReady" |
|
| 21 |
+ ], |
|
| 22 |
+ "projectType": "native", |
|
| 23 |
+ "resources": {
|
|
| 24 |
+ "media": [{
|
|
| 25 |
+ "file": "images/icon.png", |
|
| 26 |
+ "menuIcon": true, |
|
| 27 |
+ "name": "IMAGE_MENU_ICON", |
|
| 28 |
+ "targetPlatforms": null, |
|
| 29 |
+ "type": "bitmap" |
|
| 30 |
+ }, |
|
| 31 |
+ {
|
|
| 32 |
+ "file": "images/q_mark.png", |
|
| 33 |
+ "name": "Q_MARK", |
|
| 34 |
+ "targetPlatforms": null, |
|
| 35 |
+ "type": "bitmap" |
|
| 36 |
+ }, |
|
| 37 |
+ {
|
|
| 38 |
+ "file": "images/home_off.png", |
|
| 39 |
+ "name": "HOME_OFF", |
|
| 40 |
+ "targetPlatforms": null, |
|
| 41 |
+ "type": "bitmap" |
|
| 42 |
+ }, |
|
| 43 |
+ {
|
|
| 44 |
+ "file": "images/home_on.png", |
|
| 45 |
+ "name": "HOME_ON", |
|
| 46 |
+ "targetPlatforms": null, |
|
| 47 |
+ "type": "bitmap" |
|
| 48 |
+ } |
|
| 49 |
+ ] |
|
| 43 | 50 |
}, |
| 44 |
- {
|
|
| 45 |
- "file": "images/home_on.png", |
|
| 46 |
- "name": "HOME_ON", |
|
| 47 |
- "targetPlatforms": null, |
|
| 48 |
- "type": "bitmap" |
|
| 51 |
+ "sdkVersion": "3", |
|
| 52 |
+ "targetPlatforms": [ |
|
| 53 |
+ "aplite" |
|
| 54 |
+ ], |
|
| 55 |
+ "uuid": "d701bcb8-1076-4adb-9e38-9c21566efc24", |
|
| 56 |
+ "watchapp": {
|
|
| 57 |
+ "watchface": false |
|
| 49 | 58 |
} |
| 50 |
- ] |
|
| 51 | 59 |
}, |
| 52 |
- "sdkVersion": "3", |
|
| 53 |
- "targetPlatforms": [ |
|
| 54 |
- "aplite" |
|
| 55 |
- ], |
|
| 56 |
- "uuid": "d701bcb8-1076-4adb-9e38-9c21566efc24", |
|
| 57 |
- "watchapp": {
|
|
| 58 |
- "watchface": false |
|
| 59 |
- } |
|
| 60 |
- }, |
|
| 61 |
- "version": "1.1.0" |
|
| 62 |
-} |
|
| 60 |
+ "version": "1.2.0" |
|
| 61 |
+} |
|
| 63 | 62 |
\ No newline at end of file |
| ... | ... |
@@ -1,7 +1,3 @@ |
| 1 |
-#include <pebble.h> |
|
| 2 |
- |
|
| 3 |
-// Persistent storage key |
|
| 4 |
-#define SETTINGS_KEY 1 |
|
| 5 | 1 |
|
| 6 | 2 |
|
| 7 | 3 |
// Largest expected inbox and outbox message sizes |
| ... | ... |
@@ -13,7 +9,7 @@ static char s_auth[40]; |
| 13 | 9 |
static char s_api[40]; |
| 14 | 10 |
static char s_username[40]; |
| 15 | 11 |
static char s_password[40]; |
| 16 |
-static char s_server[255]; |
|
| 12 |
+static char s_server[100]; |
|
| 17 | 13 |
static bool s_js_ready; |
| 18 | 14 |
|
| 19 | 15 |
static Window *s_window; |
| ... | ... |
@@ -32,26 +28,19 @@ static uint32_t size ; |
| 32 | 28 |
|
| 33 | 29 |
time_t current_time; |
| 34 | 30 |
|
| 31 |
+/* |
|
| 35 | 32 |
typedef enum {
|
| 36 | 33 |
status, |
| 37 | 34 |
username, |
| 38 | 35 |
password, |
| 39 | 36 |
server |
| 40 | 37 |
} AppKey; |
| 41 |
- |
|
| 38 |
+*/ |
|
| 42 | 39 |
|
| 43 | 40 |
static char * msg; |
| 44 | 41 |
|
| 45 |
- |
|
| 46 |
-// Define our settings struct |
|
| 47 |
-typedef struct Settings {
|
|
| 48 |
- char username; |
|
| 49 |
- char password; |
|
| 50 |
- char server; |
|
| 51 |
-} Settings; |
|
| 52 |
- |
|
| 53 | 42 |
// An instance of the struct |
| 54 |
-static Settings settings; |
|
| 43 |
+Settings settings; |
|
| 55 | 44 |
|
| 56 | 45 |
// Save the settings to persistent storage |
| 57 | 46 |
static void prv_save_settings() {
|
| ... | ... |
@@ -73,7 +62,7 @@ static GRect init_text_layer(Layer *parent_layer, TextLayer **text_layer, int16_ |
| 73 | 62 |
return frame; |
| 74 | 63 |
} |
| 75 | 64 |
|
| 76 |
-void init_statusbar_text_layer(Layer *parent, TextLayer **layer) {
|
|
| 65 |
+static void init_statusbar_text_layer(Layer *parent, TextLayer **layer) {
|
|
| 77 | 66 |
init_text_layer(parent, layer, 0, 16, 0, FONT_KEY_GOTHIC_18_BOLD); |
| 78 | 67 |
GRect sb_bounds = layer_get_bounds(text_layer_get_layer(*layer)); |
| 79 | 68 |
sb_bounds.origin.y -= 1; |
| ... | ... |
@@ -203,7 +192,7 @@ static void update_time() {
|
| 203 | 192 |
|
| 204 | 193 |
} |
| 205 | 194 |
|
| 206 |
-void comm_is_ready() {
|
|
| 195 |
+static void comm_is_ready() {
|
|
| 207 | 196 |
|
| 208 | 197 |
// Authenticate to get token from syno |
| 209 | 198 |
|
| ... | ... |
@@ -242,6 +231,7 @@ static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
|
| 242 | 231 |
update_time(); |
| 243 | 232 |
} |
| 244 | 233 |
|
| 234 |
+// Handle the response from AppMessage |
|
| 245 | 235 |
static void inbox_received_callback(DictionaryIterator *iter, void *context) {
|
| 246 | 236 |
// A new message has been successfully received |
| 247 | 237 |
APP_LOG(APP_LOG_LEVEL_DEBUG, "New message! "); |
| ... | ... |
@@ -299,7 +289,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
|
| 299 | 289 |
|
| 300 | 290 |
Tuple *server_t = dict_find(iter, MESSAGE_KEY_server); |
| 301 | 291 |
if(server_t) {
|
| 302 |
- strncpy(s_server, server_t->value->cstring, 255); |
|
| 292 |
+ strncpy(s_server, server_t->value->cstring, 99); |
|
| 303 | 293 |
prv_save_settings(); |
| 304 | 294 |
APP_LOG(APP_LOG_LEVEL_DEBUG, "new server in settings... %s",s_server); |
| 305 | 295 |
} |
| ... | ... |
@@ -1,53 +1,47 @@ |
| 1 |
-module.exports = [ |
|
| 2 |
- {
|
|
| 3 |
- "type": "heading", |
|
| 4 |
- "defaultValue": "DSCam Home Swtich Configuration" |
|
| 5 |
- }, |
|
| 6 |
- {
|
|
| 7 |
- "type": "text", |
|
| 8 |
- "defaultValue": "Set your Synology account and server." |
|
| 9 |
- }, |
|
| 10 |
- {
|
|
| 11 |
- "type": "section", |
|
| 12 |
- "items": |
|
| 13 |
- [ |
|
| 14 |
- {
|
|
| 1 |
+module.exports = [{
|
|
| 15 | 2 |
"type": "heading", |
| 16 |
- "defaultValue": "Your synology account" |
|
| 17 |
- }, |
|
| 18 |
- {
|
|
| 19 |
- "type": "input", |
|
| 20 |
- "messageKey": "username", |
|
| 21 |
- "label": "Your DSM Username", |
|
| 22 |
- "attributes" : |
|
| 23 |
- {
|
|
| 24 |
- "maxlength":40 |
|
| 25 |
- } |
|
| 26 |
- }, |
|
| 27 |
- {
|
|
| 28 |
- "type": "input", |
|
| 29 |
- "messageKey": "password", |
|
| 30 |
- "label": "Your DSM Password", |
|
| 31 |
- "attributes" : |
|
| 32 |
- {
|
|
| 33 |
- "type": "password", |
|
| 34 |
- "maxlength":40 |
|
| 35 |
- } |
|
| 36 |
- }, |
|
| 37 |
- {
|
|
| 38 |
- "type": "input", |
|
| 39 |
- "messageKey": "server", |
|
| 40 |
- "label": "Your DSM Server", |
|
| 41 |
- "attributes" : |
|
| 42 |
- {
|
|
| 43 |
- "type": "url", |
|
| 44 |
- "maxlength":255 |
|
| 45 |
- } |
|
| 46 |
- } |
|
| 47 |
- ] |
|
| 48 |
- }, |
|
| 49 |
- {
|
|
| 50 |
- "type": "submit", |
|
| 51 |
- "defaultValue": "Save Settings" |
|
| 52 |
- } |
|
| 53 |
-]; |
|
| 3 |
+ "defaultValue": "DSCam Home Swtich Configuration" |
|
| 4 |
+ }, |
|
| 5 |
+ {
|
|
| 6 |
+ "type": "text", |
|
| 7 |
+ "defaultValue": "Set your Synology account and server." |
|
| 8 |
+ }, |
|
| 9 |
+ {
|
|
| 10 |
+ "type": "section", |
|
| 11 |
+ "items": [{
|
|
| 12 |
+ "type": "heading", |
|
| 13 |
+ "defaultValue": "Your synology account" |
|
| 14 |
+ }, |
|
| 15 |
+ {
|
|
| 16 |
+ "type": "input", |
|
| 17 |
+ "messageKey": "username", |
|
| 18 |
+ "label": "Your DSM Username", |
|
| 19 |
+ "attributes": {
|
|
| 20 |
+ "maxlength": 40 |
|
| 21 |
+ } |
|
| 22 |
+ }, |
|
| 23 |
+ {
|
|
| 24 |
+ "type": "input", |
|
| 25 |
+ "messageKey": "password", |
|
| 26 |
+ "label": "Your DSM Password", |
|
| 27 |
+ "attributes": {
|
|
| 28 |
+ "type": "password", |
|
| 29 |
+ "maxlength": 40 |
|
| 30 |
+ } |
|
| 31 |
+ }, |
|
| 32 |
+ {
|
|
| 33 |
+ "type": "input", |
|
| 34 |
+ "messageKey": "server", |
|
| 35 |
+ "label": "Your DSM Server", |
|
| 36 |
+ "attributes": {
|
|
| 37 |
+ "type": "url", |
|
| 38 |
+ "maxlength": 100 |
|
| 39 |
+ } |
|
| 40 |
+ } |
|
| 41 |
+ ] |
|
| 42 |
+ }, |
|
| 43 |
+ {
|
|
| 44 |
+ "type": "submit", |
|
| 45 |
+ "defaultValue": "Save Settings" |
|
| 46 |
+ } |
|
| 47 |
+]; |
|
| 54 | 48 |
\ No newline at end of file |
| ... | ... |
@@ -2,248 +2,214 @@ var Clay = require('pebble-clay');
|
| 2 | 2 |
var clayConfig = require('./config');
|
| 3 | 3 |
var clay = new Clay(clayConfig); |
| 4 | 4 |
|
| 5 |
-var messageKeys = require('message_keys');
|
|
| 6 |
- |
|
| 7 | 5 |
var sid; |
| 8 | 6 |
var status; |
| 9 | 7 |
|
| 10 | 8 |
function authenticate() {
|
| 11 |
- var response; |
|
| 12 |
- sid=""; |
|
| 13 |
- console.log('---- authenticate');
|
|
| 14 |
- console.log('-- '+localStorage.getItem('username'));
|
|
| 15 |
- console.log('-- '+localStorage.getItem('password'));
|
|
| 16 |
- console.log('-- '+localStorage.getItem('server'));
|
|
| 17 |
- if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 18 |
- var username=localStorage.getItem('username');
|
|
| 19 |
- var password=localStorage.getItem('password');
|
|
| 20 |
- var server=localStorage.getItem('server');
|
|
| 21 |
- var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account="+username+"&passwd="+password+"&session=SurveillanceStation&format=sid"; |
|
| 22 |
- var xhr = new XMLHttpRequest(); |
|
| 23 |
- |
|
| 24 |
- xhr.open("GET", url,false);
|
|
| 25 |
- xhr.send(); |
|
| 9 |
+ var response; |
|
| 10 |
+ sid = ""; |
|
| 11 |
+ console.log('---- authenticate');
|
|
| 12 |
+ console.log('-- ' + localStorage.getItem('username'));
|
|
| 13 |
+ console.log('-- ' + localStorage.getItem('password'));
|
|
| 14 |
+ console.log('-- ' + localStorage.getItem('server'));
|
|
| 15 |
+ if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server')) {
|
|
| 16 |
+ var username = localStorage.getItem('username');
|
|
| 17 |
+ var password = localStorage.getItem('password');
|
|
| 18 |
+ var server = localStorage.getItem('server');
|
|
| 19 |
+ var url = server + "/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=2&account=" + username + "&passwd=" + password + "&session=SurveillanceStation&format=sid"; |
|
| 20 |
+ var xhr = new XMLHttpRequest(); |
|
| 26 | 21 |
|
| 27 |
- if(xhr.status == 200) {
|
|
| 28 |
- response = JSON.parse(xhr.responseText); |
|
| 29 |
- if (response.success == true){
|
|
| 30 |
- sid = response.data.sid; |
|
| 31 |
- } |
|
| 32 |
- }else {
|
|
| 33 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 34 |
- } |
|
| 35 |
- |
|
| 36 |
- if (sid != ""){
|
|
| 37 |
- auth = ""; |
|
| 38 |
- message = "Welcome to Syno Cam Switch ! ready & authenticated"; |
|
| 39 |
- |
|
| 40 |
- // Build message |
|
| 41 |
- var dict = {
|
|
| 42 |
- 'auth': message, |
|
| 43 |
- }; |
|
| 44 |
- |
|
| 45 |
- // Send the message |
|
| 46 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 47 |
- console.log('sent');
|
|
| 48 |
- }, function() {
|
|
| 49 |
- console.log('failed');
|
|
| 50 |
- }); |
|
| 51 |
- |
|
| 22 |
+ xhr.open("GET", url, false);
|
|
| 23 |
+ xhr.send(); |
|
| 24 |
+ |
|
| 25 |
+ if (xhr.status == 200) {
|
|
| 26 |
+ response = JSON.parse(xhr.responseText); |
|
| 27 |
+ if (response.success == true) {
|
|
| 28 |
+ sid = response.data.sid; |
|
| 29 |
+ } |
|
| 30 |
+ } else {
|
|
| 31 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ if (sid != "") {
|
|
| 35 |
+ auth = ""; |
|
| 36 |
+ message = "Welcome to Syno Cam Switch ! ready & authenticated"; |
|
| 37 |
+ |
|
| 38 |
+ // Build message |
|
| 39 |
+ var dict = {
|
|
| 40 |
+ 'auth': message, |
|
| 41 |
+ }; |
|
| 42 |
+ |
|
| 43 |
+ // Send the message |
|
| 44 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 45 |
+ console.log('sent');
|
|
| 46 |
+ }, function() {
|
|
| 47 |
+ console.log('failed');
|
|
| 48 |
+ }); |
|
| 49 |
+ |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ } else {
|
|
| 53 |
+ Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 52 | 54 |
} |
| 53 |
- |
|
| 54 |
- }else{
|
|
| 55 |
- Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 56 |
- } |
|
| 57 | 55 |
} |
| 58 | 56 |
|
| 59 | 57 |
function get_status() {
|
| 60 |
- var response; |
|
| 61 |
- |
|
| 62 |
- if (sid != ""){
|
|
| 63 |
- status = ""; |
|
| 64 |
- console.log('---- get_status');
|
|
| 65 |
- if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 66 |
- var username=localStorage.getItem('username');
|
|
| 67 |
- var password=localStorage.getItem('password');
|
|
| 68 |
- var server=localStorage.getItem('server');
|
|
| 69 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 70 |
- var xhr = new XMLHttpRequest(); |
|
| 58 |
+ var response; |
|
| 59 |
+ |
|
| 60 |
+ if (sid != "") {
|
|
| 61 |
+ status = ""; |
|
| 62 |
+ console.log('---- get_status');
|
|
| 63 |
+ if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server')) {
|
|
| 64 |
+ var username = localStorage.getItem('username');
|
|
| 65 |
+ var password = localStorage.getItem('password');
|
|
| 66 |
+ var server = localStorage.getItem('server');
|
|
| 67 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid=" + sid; |
|
| 68 |
+ var xhr = new XMLHttpRequest(); |
|
| 69 |
+ |
|
| 70 |
+ xhr.open("GET", url, false);
|
|
| 71 |
+ xhr.send(); |
|
| 71 | 72 |
|
| 72 |
- xhr.open("GET", url,false);
|
|
| 73 |
- xhr.send(); |
|
| 73 |
+ if (xhr.status == 200) {
|
|
| 74 |
+ response = JSON.parse(xhr.responseText); |
|
| 75 |
+ if (response.success == true) {
|
|
| 76 |
+ status = response.data.on; |
|
| 77 |
+ var message; |
|
| 78 |
+ switch (status) {
|
|
| 79 |
+ case true: |
|
| 80 |
+ message = "Your Home mode is ON"; |
|
| 81 |
+ break; |
|
| 82 |
+ case false: |
|
| 83 |
+ message = "Your Home mode is OFF"; |
|
| 84 |
+ break; |
|
| 85 |
+ default: |
|
| 86 |
+ message = "home mode is unknown !"; |
|
| 87 |
+ } |
|
| 88 |
+ // Build message |
|
| 89 |
+ var dict = {
|
|
| 90 |
+ 'status': message, |
|
| 91 |
+ }; |
|
| 74 | 92 |
|
| 75 |
- if(xhr.status == 200) {
|
|
| 76 |
- response = JSON.parse(xhr.responseText); |
|
| 77 |
- if (response.success == true){
|
|
| 78 |
- status=response.data.on; |
|
| 79 |
- var message; |
|
| 80 |
- switch (status) {
|
|
| 81 |
- case true: |
|
| 82 |
- message = "Your Home mode is ON"; |
|
| 83 |
- break; |
|
| 84 |
- case false: |
|
| 85 |
- message = "Your Home mode is OFF"; |
|
| 86 |
- break; |
|
| 87 |
- default: |
|
| 88 |
- message = "home mode is unknown !"; |
|
| 89 |
- } |
|
| 90 |
- // Build message |
|
| 91 |
- var dict = {
|
|
| 92 |
- 'status': message, |
|
| 93 |
- }; |
|
| 94 |
- |
|
| 95 |
- // Send the message |
|
| 96 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 97 |
- console.log('sent');
|
|
| 98 |
- }, function() {
|
|
| 99 |
- console.log('failed');
|
|
| 100 |
- }); |
|
| 93 |
+ // Send the message |
|
| 94 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 95 |
+ console.log('sent');
|
|
| 96 |
+ }, function() {
|
|
| 97 |
+ console.log('failed');
|
|
| 98 |
+ }); |
|
| 99 |
+ } |
|
| 100 |
+ } else {
|
|
| 101 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 102 |
+ } |
|
| 103 |
+ } else {
|
|
| 104 |
+ Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 101 | 105 |
} |
| 102 |
- }else {
|
|
| 103 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 104 |
- } |
|
| 105 |
- }else{
|
|
| 106 |
- Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 107 | 106 |
} |
| 108 |
- } |
|
| 109 |
- |
|
| 107 |
+ |
|
| 110 | 108 |
} |
| 111 | 109 |
|
| 112 | 110 |
|
| 113 | 111 |
function switch_home(bool) {
|
| 114 |
- var response; |
|
| 115 |
- console.log('---- authenticate');
|
|
| 116 |
- if (sid != ""){
|
|
| 117 |
- status = ""; |
|
| 118 |
- console.log('---- get_status');
|
|
| 119 |
- if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server') ){
|
|
| 120 |
- var username=localStorage.getItem('username');
|
|
| 121 |
- var password=localStorage.getItem('password');
|
|
| 122 |
- var server=localStorage.getItem('server');
|
|
| 123 |
- var xhr = new XMLHttpRequest(); |
|
| 124 |
- |
|
| 125 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid="+sid; |
|
| 126 |
- |
|
| 127 |
- xhr.open("GET", url,false);
|
|
| 128 |
- xhr.send(); |
|
| 129 |
- |
|
| 130 |
- if(xhr.status == 200) {
|
|
| 131 |
- response = JSON.parse(xhr.responseText); |
|
| 132 |
- if (response.success == true){
|
|
| 133 |
- status=response.data.on; |
|
| 134 |
- console.log('------ status:'+status);
|
|
| 135 |
- var message; |
|
| 136 |
- var dict; |
|
| 137 |
- if ( status != bool){
|
|
| 138 |
- console.log('---- switching home mode to '+ bool);
|
|
| 139 |
- url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on="+bool+"&_sid="+sid; |
|
| 140 |
- |
|
| 141 |
- xhr.open("GET", url,false);
|
|
| 112 |
+ var response; |
|
| 113 |
+ console.log('---- authenticate');
|
|
| 114 |
+ if (sid != "") {
|
|
| 115 |
+ status = ""; |
|
| 116 |
+ console.log('---- get_status');
|
|
| 117 |
+ if (localStorage.getItem('username') && localStorage.getItem('password') && localStorage.getItem('server')) {
|
|
| 118 |
+ var username = localStorage.getItem('username');
|
|
| 119 |
+ var password = localStorage.getItem('password');
|
|
| 120 |
+ var server = localStorage.getItem('server');
|
|
| 121 |
+ var xhr = new XMLHttpRequest(); |
|
| 122 |
+ |
|
| 123 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=GetInfo&_sid=" + sid; |
|
| 124 |
+ |
|
| 125 |
+ xhr.open("GET", url, false);
|
|
| 142 | 126 |
xhr.send(); |
| 143 |
- |
|
| 144 |
- if(xhr.status == 200) {
|
|
| 145 |
- response = JSON.parse(xhr.responseText); |
|
| 146 |
- if (response.success == true){
|
|
| 147 |
- status=bool; |
|
| 148 |
- switch (status) {
|
|
| 149 |
- case true: |
|
| 150 |
- message = "You just set Home mode ON"; |
|
| 151 |
- break; |
|
| 152 |
- case false: |
|
| 153 |
- message = "You just set Home mode OFF"; |
|
| 154 |
- break; |
|
| 155 |
- default: |
|
| 156 |
- message = "something happened, try again !"; |
|
| 157 |
- } |
|
| 158 |
- // Build message |
|
| 159 |
- dict = {
|
|
| 160 |
- 'status': message, |
|
| 161 |
- }; |
|
| 162 |
- |
|
| 163 |
- // Send the message |
|
| 164 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 165 |
- console.log('sent');
|
|
| 166 |
- }, function() {
|
|
| 167 |
- console.log('failed');
|
|
| 168 |
- }); |
|
| 169 |
- } |
|
| 170 |
- }else {
|
|
| 171 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 127 |
+ |
|
| 128 |
+ if (xhr.status == 200) {
|
|
| 129 |
+ response = JSON.parse(xhr.responseText); |
|
| 130 |
+ if (response.success == true) {
|
|
| 131 |
+ status = response.data.on; |
|
| 132 |
+ console.log('------ status:' + status);
|
|
| 133 |
+ var message; |
|
| 134 |
+ var dict; |
|
| 135 |
+ if (status != bool) {
|
|
| 136 |
+ console.log('---- switching home mode to ' + bool);
|
|
| 137 |
+ url = server + "/webapi/entry.cgi?api=SYNO.SurveillanceStation.HomeMode&version=1&method=Switch&on=" + bool + "&_sid=" + sid; |
|
| 138 |
+ |
|
| 139 |
+ xhr.open("GET", url, false);
|
|
| 140 |
+ xhr.send(); |
|
| 141 |
+ |
|
| 142 |
+ if (xhr.status == 200) {
|
|
| 143 |
+ response = JSON.parse(xhr.responseText); |
|
| 144 |
+ if (response.success == true) {
|
|
| 145 |
+ status = bool; |
|
| 146 |
+ switch (status) {
|
|
| 147 |
+ case true: |
|
| 148 |
+ message = "You just set Home mode ON"; |
|
| 149 |
+ break; |
|
| 150 |
+ case false: |
|
| 151 |
+ message = "You just set Home mode OFF"; |
|
| 152 |
+ break; |
|
| 153 |
+ default: |
|
| 154 |
+ message = "something happened, try again !"; |
|
| 155 |
+ } |
|
| 156 |
+ // Build message |
|
| 157 |
+ dict = {
|
|
| 158 |
+ 'status': message, |
|
| 159 |
+ }; |
|
| 160 |
+ |
|
| 161 |
+ // Send the message |
|
| 162 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 163 |
+ console.log('sent');
|
|
| 164 |
+ }, function() {
|
|
| 165 |
+ console.log('failed');
|
|
| 166 |
+ }); |
|
| 167 |
+ } |
|
| 168 |
+ } else {
|
|
| 169 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 170 |
+ } |
|
| 171 |
+ } else {
|
|
| 172 |
+ console.log('---- nothign to do, status already ' + status);
|
|
| 173 |
+ switch (status) {
|
|
| 174 |
+ case true: |
|
| 175 |
+ message = "Your Home Mode is already ON"; |
|
| 176 |
+ break; |
|
| 177 |
+ case false: |
|
| 178 |
+ message = "Your Home Mode is already OFF"; |
|
| 179 |
+ break; |
|
| 180 |
+ default: |
|
| 181 |
+ message = "something happened, try again !"; |
|
| 182 |
+ } |
|
| 183 |
+ // Build message |
|
| 184 |
+ dict = {
|
|
| 185 |
+ 'status': message, |
|
| 186 |
+ }; |
|
| 187 |
+ |
|
| 188 |
+ // Send the message |
|
| 189 |
+ Pebble.sendAppMessage(dict, function(e) {
|
|
| 190 |
+ console.log('sent');
|
|
| 191 |
+ }, function() {
|
|
| 192 |
+ console.log('failed');
|
|
| 193 |
+ }); |
|
| 194 |
+ } |
|
| 195 |
+ } |
|
| 196 |
+ } else {
|
|
| 197 |
+ console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 172 | 198 |
} |
| 173 |
- }else{
|
|
| 174 |
- console.log('---- nothign to do, status already '+status);
|
|
| 175 |
- switch (status) {
|
|
| 176 |
- case true: |
|
| 177 |
- message = "Your Home Mode is already ON"; |
|
| 178 |
- break; |
|
| 179 |
- case false: |
|
| 180 |
- message = "Your Home Mode is already OFF"; |
|
| 181 |
- break; |
|
| 182 |
- default: |
|
| 183 |
- message = "something happened, try again !"; |
|
| 184 |
- } |
|
| 185 |
- // Build message |
|
| 186 |
- dict = {
|
|
| 187 |
- 'status': message, |
|
| 188 |
- }; |
|
| 189 |
- |
|
| 190 |
- // Send the message |
|
| 191 |
- Pebble.sendAppMessage(dict, function(e) {
|
|
| 192 |
- console.log('sent');
|
|
| 193 |
- }, function() {
|
|
| 194 |
- console.log('failed');
|
|
| 195 |
- }); |
|
| 196 |
- } |
|
| 199 |
+ } else {
|
|
| 200 |
+ Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 197 | 201 |
} |
| 198 |
- }else {
|
|
| 199 |
- console.log('------Request returned error code ' + xhr.status.toString());
|
|
| 200 |
- } |
|
| 201 |
- }else{
|
|
| 202 |
- Pebble.showSimpleNotificationOnPebble("DSCam H-S", "You need to set your Synology account and server.");
|
|
| 203 | 202 |
} |
| 204 |
- } |
|
| 205 | 203 |
|
| 206 | 204 |
} |
| 207 | 205 |
|
| 208 | 206 |
// Get JS readiness events |
| 209 |
-Pebble.addEventListener('ready',function(e){
|
|
| 210 |
- console.log('PebbleKit JS is ready');
|
|
| 211 |
- // Update Watch on this |
|
| 212 |
- Pebble.sendAppMessage({'JSReady':1});
|
|
| 207 |
+Pebble.addEventListener('ready', function(e) {
|
|
| 208 |
+ console.log('PebbleKit JS is ready');
|
|
| 209 |
+ // Update Watch on this |
|
| 210 |
+ Pebble.sendAppMessage({ 'JSReady': 1 });
|
|
| 213 | 211 |
}); |
| 214 |
- |
|
| 215 | 212 |
/* |
| 216 |
-Pebble.addEventListener('webviewclosed', function(e) {
|
|
| 217 |
- if (e && !e.response) {
|
|
| 218 |
- return; |
|
| 219 |
- } |
|
| 220 |
- |
|
| 221 |
- // Get the keys and values from each config item |
|
| 222 |
- var dict = clay.getSettings(e.response); |
|
| 223 |
- // console.log("server is "+dict[messageKeys.server]);
|
|
| 224 |
- |
|
| 225 |
- // Send settings values to watch side |
|
| 226 |
- Pebble.sendAppMessage({'server':dict[messageKeys.server]}, function(e) {
|
|
| 227 |
- console.log('Sent server config to Pebble');
|
|
| 228 |
- }, function(e) {
|
|
| 229 |
- console.log('Failed to send server config!');
|
|
| 230 |
- console.log(JSON.stringify(e)); |
|
| 231 |
- }); |
|
| 232 |
- Pebble.sendAppMessage({'username':dict[messageKeys.username]}, function(e) {
|
|
| 233 |
- console.log('Sent username config to Pebble');
|
|
| 234 |
- }, function(e) {
|
|
| 235 |
- console.log('Failed to send username config!');
|
|
| 236 |
- console.log(JSON.stringify(e)); |
|
| 237 |
- }); |
|
| 238 |
- Pebble.sendAppMessage({'password':dict[messageKeys.password]}, function(e) {
|
|
| 239 |
- console.log('Sent password config to Pebble');
|
|
| 240 |
- }, function(e) {
|
|
| 241 |
- console.log('Failed to send password config!');
|
|
| 242 |
- console.log(JSON.stringify(e)); |
|
| 243 |
- }); |
|
| 244 |
-}); |
|
| 245 |
-*/ |
|
| 246 |
- |
|
| 247 | 213 |
// Get AppMessage events |
| 248 | 214 |
Pebble.addEventListener('appmessage', function(e) {
|
| 249 | 215 |
// Get the dictionary from the message |
| ... | ... |
@@ -267,3 +233,4 @@ Pebble.addEventListener('appmessage', function(e) {
|
| 267 | 233 |
} |
| 268 | 234 |
|
| 269 | 235 |
}); |
| 236 |
+*/ |
|
| 270 | 237 |
\ No newline at end of file |