@@ -27,9 +27,9 @@ public class ParticleBridge {
27
27
public static final int MAX_DEVICES = 6 ;
28
28
29
29
//Login details
30
- public static final String EMAIL = "sunbaoshi1975@gmail .com" ;
31
- public static final String PASSWORD = "1qazxsw2 " ;
32
- public static final String DEVICE_ID = "2d0027001647343432313031 " ;
30
+ public static final String EMAIL = "umar.bhutta@hotmail .com" ;
31
+ public static final String PASSWORD = "ballislife2016 " ;
32
+ public static final String DEVICE_ID = "30003e001547343339383037 " ;
33
33
34
34
//Particle vars
35
35
public static ParticleDevice currDevice ;
@@ -46,6 +46,7 @@ public class ParticleBridge {
46
46
//ring values
47
47
public static final int RING_ALL = 0 ;
48
48
public static final int RING_1 = 1 ;
49
+
49
50
public static final int RING_2 = 2 ;
50
51
public static final int RING_3 = 3 ;
51
52
//ring text
@@ -181,7 +182,7 @@ public static int JSONConfigScenario(final int brightness, final int cw, final i
181
182
new Thread () {
182
183
@ Override
183
184
public void run () {
184
- int scenarioId = ScenarioFragment .name .size () + 1 ;
185
+ int scenarioId = ScenarioFragment .name .size ();
185
186
boolean x [] = {false , false , false };
186
187
187
188
//construct first part of string input, and store it in arraylist (of size 1)
@@ -216,7 +217,7 @@ public void run() {
216
217
if (x [1 ]) {
217
218
//construct last part of string input, store in arraylist
218
219
//json = "\"ring3\":[" + STATE_ON + "," + cw + "," + ww + "," + r + "," + g + "," + b + "],\"brightness\":" + brightness + ",\"filter\":" + DEFAULT_FILTER_ID + "}";
219
- json = "{'x2':' \" ring3\" :[" + STATE_ON + "," + cw + "," + ww + "," + r + "," + g + "," + b + "],\" brightness\" :" + brightness + ",\" filter\" :" + DEFAULT_FILTER_ID + "}' }" ;
220
+ json = "\" ring3\" :[" + STATE_ON + "," + cw + "," + ww + "," + r + "," + g + "," + b + "],\" brightness\" :" + brightness + ",\" filter\" :" + DEFAULT_FILTER_ID + "}" ;
220
221
message .add (json );
221
222
//send in last part of string
222
223
try {
@@ -232,13 +233,16 @@ public void run() {
232
233
return resultCode ;
233
234
}
234
235
235
- public static int JSONConfigSchedule (final boolean isRepeat , final String weekdays , final int hour , final int minute ) {
236
+ public static int JSONConfigAlarm (final int nodeId , final boolean isRepeat , final String weekdays , final int hour , final int minute , final String scenarioName ) {
237
+ final int [] doneSending = {0 };
236
238
new Thread () {
237
239
@ Override
238
240
public void run () {
241
+ boolean x [] = {false , false , false , false };
242
+
243
+ //SCHEDULE
239
244
int scheduleId = ScheduleFragment .name .size ();
240
245
int repeat = isRepeat ? 1 : 0 ;
241
- boolean x [] = {false , false };
242
246
243
247
//construct first part of string input, and store it in arraylist (of size 1)
244
248
String json = "{'x0': '{\" op\" :1,\" fl\" :0,\" run\" :0,\" uid\" :\" a" + scheduleId + "\" ,\" isRepeat\" :" + repeat + ", '}" ;
@@ -256,67 +260,108 @@ public void run() {
256
260
257
261
if (x [0 ]) {
258
262
//construct second part of string input, store in arraylist
259
- json = "{ \" weekdays\" :\" " + weekdays + " \ " ,\" hour\" :" + hour + ",\" min\" :" + minute + ",\" alarm_id\" :" + DEFAULT_ALARM_ID + "}" ;
263
+ json = "\" weekdays\" :" + "2" + ",\" hour\" :" + hour + ",\" min\" :" + minute + ",\" alarm_id\" :" + DEFAULT_ALARM_ID + "}" ;
260
264
message .add (json );
261
265
//send in second part of string
262
266
try {
263
267
Log .e (TAG , "JSONConfigSchedule " + message .get (0 ));
264
268
resultCode = currDevice .callFunction ("JSONConfig" , message );
265
269
x [1 ] = true ;
270
+ doneSending [0 ] = 5 ;
266
271
} catch (ParticleCloudException | ParticleDevice .FunctionDoesNotExistException | IOException e ) {
267
272
e .printStackTrace ();
268
273
}
269
274
message .clear ();
270
- }
271
- }
272
- }.start ();
273
- return 1 ;
274
- }
275
275
276
- public static int JSONConfigRule (final int nodeId , final String scenarioName ) {
277
- new Thread () {
278
- @ Override
279
- public void run () {
280
- int rule_schedule_notif_Id = ScheduleFragment .name .size () + 1 ;
281
- int scenarioId = 1 ;
282
- for (int i = 0 ; i < ScenarioFragment .name .size (); i ++) {
283
- if (scenarioName == ScenarioFragment .name .get (i )) {
284
- scenarioId = i + 1 ;
285
- }
286
- }
287
- boolean x [] = {false , false };
288
276
289
- //construct first part of string input, and store it in arraylist (of size 1)
290
- String json = "{'x0': '{\" op\" :1,\" fl\" :0,\" run\" :0,\" uid\" :\" r" + rule_schedule_notif_Id + "\" ,\" node_id\" :" + nodeId + ", '}" ;
291
- ArrayList <String > message = new ArrayList <>();
292
- message .add (json );
293
- //send in first part of string
294
- try {
295
- Log .e (TAG , "JSONConfigRule" + message .get (0 ));
296
- resultCode = currDevice .callFunction ("JSONConfig" , message );
297
- x [0 ] = true ;
298
- } catch (ParticleCloudException | ParticleDevice .FunctionDoesNotExistException | IOException e ) {
299
- e .printStackTrace ();
300
- }
301
- message .clear ();
302
277
303
- if (x [0 ]) {
304
- //construct second part of string input, store in arraylist
305
- json = "{'x1': '\" SCT_uid\" :\" a" + rule_schedule_notif_Id + "\" ,\" SNT_uid\" :\" s" + scenarioId + "\" ,\" notif_uid\" :\" n" + rule_schedule_notif_Id + "\" } '}" ;
306
- message .add (json );
307
- //send in second part of string
278
+ //RULE
279
+ int rule_schedule_notif_Id = ScheduleFragment .name .size () - 1 ;
280
+ int scenarioId = 1 ;
281
+ for (int i = 0 ; i < ScenarioFragment .name .size (); i ++) {
282
+ if (scenarioName == ScenarioFragment .name .get (i )) {
283
+ scenarioId = i ;
284
+ }
285
+ }
286
+
287
+ //construct first part of string input, and store it in arraylist (of size 1)
288
+ String json2 = "{'x0': '{\" op\" :1,\" fl\" :0,\" run\" :0,\" uid\" :\" r" + rule_schedule_notif_Id + "\" ,\" node_id\" :" + nodeId + ", '}" ;
289
+ ArrayList <String > message2 = new ArrayList <>();
290
+ message2 .add (json2 );
291
+ //send in first part of string
308
292
try {
309
- Log .i (TAG , "JSONConfigRule" + message .get (0 ));
310
- resultCode = currDevice .callFunction ("JSONConfig" , message );
311
- x [1 ] = true ;
293
+ Log .e (TAG , "JSONConfigRule " + message2 .get (0 ));
294
+ resultCode = currDevice .callFunction ("JSONConfig" , message2 );
295
+ x [2 ] = true ;
312
296
} catch (ParticleCloudException | ParticleDevice .FunctionDoesNotExistException | IOException e ) {
313
297
e .printStackTrace ();
314
298
}
315
- message .clear ();
299
+ message2 .clear ();
300
+
301
+ if (x [2 ]) {
302
+ //construct second part of string input, store in arraylist
303
+ json2 = "\" SCT_uid\" :" + rule_schedule_notif_Id + ",\" SNT_uid\" :" + scenarioId + ",\" notif_uid\" :" + rule_schedule_notif_Id + "}" ;
304
+ message2 .add (json2 );
305
+ //send in second part of string
306
+ try {
307
+ Log .i (TAG , "JSONConfigRule " + message2 .get (0 ));
308
+ resultCode = currDevice .callFunction ("JSONConfig" , message2 );
309
+ x [3 ] = true ;
310
+ } catch (ParticleCloudException | ParticleDevice .FunctionDoesNotExistException | IOException e ) {
311
+ e .printStackTrace ();
312
+ }
313
+ message2 .clear ();
314
+ }
316
315
}
317
316
}
318
317
}.start ();
319
318
return resultCode ;
320
319
}
321
320
321
+ // public static int JSONConfigRule(final int nodeId, final String scenarioName) {
322
+ // new Thread() {
323
+ // @Override
324
+ // public void run() {
325
+ // int rule_schedule_notif_Id = ScheduleFragment.name.size() + 1;
326
+ // int scenarioId = 1;
327
+ // for (int i = 0; i < ScenarioFragment.name.size(); i++) {
328
+ // if (scenarioName == ScenarioFragment.name.get(i)) {
329
+ // scenarioId = i + 1;
330
+ // }
331
+ // }
332
+ // boolean x[] = {false, false};
333
+ //
334
+ // //construct first part of string input, and store it in arraylist (of size 1)
335
+ // String json = "{'x0': '{\"op\":1,\"fl\":0,\"run\":0,\"uid\":\"r" + rule_schedule_notif_Id + "\",\"node_id\":" + nodeId + ", '}";
336
+ // ArrayList<String> message = new ArrayList<>();
337
+ // message.add(json);
338
+ // //send in first part of string
339
+ // try {
340
+ // Log.e(TAG, "JSONConfigRule" + message.get(0));
341
+ // resultCode = currDevice.callFunction("JSONConfig", message);
342
+ // x[0] = true;
343
+ // } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
344
+ // e.printStackTrace();
345
+ // }
346
+ // message.clear();
347
+ //
348
+ // if (x[0]) {
349
+ // //construct second part of string input, store in arraylist
350
+ // json = "\"SCT_uid\":\"a" + rule_schedule_notif_Id + "\",\"SNT_uid\":\"s" + scenarioId + "\",\"notif_uid\":\"n" + rule_schedule_notif_Id + "\"}";
351
+ // message.add(json);
352
+ // //send in second part of string
353
+ // try {
354
+ // Log.i(TAG, "JSONConfigRule" + message.get(0));
355
+ // resultCode = currDevice.callFunction("JSONConfig", message);
356
+ // x[1] = true;
357
+ // } catch (ParticleCloudException | ParticleDevice.FunctionDoesNotExistException | IOException e) {
358
+ // e.printStackTrace();
359
+ // }
360
+ // message.clear();
361
+ // }
362
+ // }
363
+ // }.start();
364
+ // return resultCode;
365
+ // }
366
+
322
367
}
0 commit comments