File size: 2,666 Bytes
69c3cbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2017, Temboo Inc.

#include <Process.h>

void setup() {
  // initialize the Bridge
  Bridge.begin();
  Serial.begin(9600);
  Process p;

  //intro message 
  Serial.println("**** Temboo Cloud Controls ****\n");
  
  // update the package list
  Serial.print("Updating package listings...");
  p.runShellCommand("opkg update");
  int returnCode = p.exitValue();
  if (returnCode == 0) {
    Serial.println("Success!");
  } else {
    Serial.println("Failed. Make sure your device is connected to the internet properly.");
    while(p.available()) {
      char c = p.read();
      Serial.print(c);
    }
    return;
  }
  Serial.println();
  // upgrade the Temboo package
  Serial.print("Updating Temboo...");
  p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/temboo_1.3.1-1_ar71xx.ipk --force-depends");
  returnCode = p.exitValue();
  if (returnCode == 0) {
    Serial.println("Success!");
  } else {
    Serial.println("Failed.");
    Serial.println("Error number: " +String(returnCode));
    while(p.available()) {
      char c = p.read();
      Serial.print(c);
    }
    return;
  }
  Serial.println();
  
  // install python openssl to allow for for ssl connections
  Serial.print("Installing python-openssl...");
  p.runShellCommand("opkg install python-openssl");
  returnCode = p.exitValue();
  if (returnCode == 0) {
    Serial.println("Success!");
  } else {
    Serial.println("Failed.");
    while(p.available()) {
      char c = p.read();
      Serial.print(c);
    }
    return;
  }
  Serial.println();

  // Installing twisted web to work with CoAP gateway
  Serial.print("Installing twisted-web...");
  p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/twisted-web_2.5.0-1_ar71xx.ipk --force-depends");
  returnCode = p.exitValue();
  if (returnCode == 0) {
    Serial.println("Success!");
  } else {
    Serial.println("Failed.");
    while(p.available()) {
      char c = p.read();
      Serial.print(c);
    }
    return;
  }
  Serial.println();

  // Configuring zope
  Serial.print("Configuring zope...");
  p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/zope-interface_2.5.0-1_ar71xx.ipk --force-depends");
  returnCode = p.exitValue();
  if (returnCode == 0) {
    p.runShellCommand("touch /usr/lib/python2.7/site-packages/zope/__init__.py");
    Serial.println("Success!");
  } else {
    Serial.println("Failed.");
    while(p.available()) {
      char c = p.read();
      Serial.print(c);
    }
    return;
  }
  
  Serial.println("Update Complete - your Yun is ready for Cloud Controls!");
}

void loop() {
  // do nothing
}