forked from cradlepoint/sdk-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRouter_Application_Development_Guide.html
930 lines (839 loc) · 33.1 KB
/
Router_Application_Development_Guide.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
<!DOCTYPE html>
<html>
<head>
<title>Router_Application_Development_Guide</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) */
/* Author: Nicolas Hery - http://nicolashery.com */
/* Version: b13fe65ca28d2e568c6ed5d7f06581183df8f2ff */
/* Source: https://github.com/nicolahery/markdownpad-github */
/* RESET
=============================================================================*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
}
/* BODY
=============================================================================*/
body {
font-family: Helvetica, arial, freesans, clean, sans-serif;
font-size: 14px;
line-height: 1.6;
color: #333;
background-color: #fff;
padding: 20px;
max-width: 960px;
margin: 0 auto;
}
body>*:first-child {
margin-top: 0 !important;
}
body>*:last-child {
margin-bottom: 0 !important;
}
/* BLOCKS
=============================================================================*/
p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}
/* HEADERS
=============================================================================*/
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}
h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
h1 {
font-size: 28px;
color: #000;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777;
font-size: 14px;
}
body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}
/* LINKS
=============================================================================*/
a {
color: #4183C4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* LISTS
=============================================================================*/
ul, ol {
padding-left: 30px;
}
ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}
dl {
padding: 0;
}
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}
dl dt:first-child {
padding: 0;
}
dl dt>:first-child {
margin-top: 0px;
}
dl dt>:last-child {
margin-bottom: 0px;
}
dl dd {
margin: 0 0 15px;
padding: 0 15px;
}
dl dd>:first-child {
margin-top: 0px;
}
dl dd>:last-child {
margin-bottom: 0px;
}
/* CODE
=============================================================================*/
pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}
code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}
pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
pre code, pre tt {
background-color: transparent;
border: none;
}
kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}
/* QUOTES
=============================================================================*/
blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
blockquote>:first-child {
margin-top: 0px;
}
blockquote>:last-child {
margin-bottom: 0px;
}
/* HORIZONTAL RULES
=============================================================================*/
hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}
/* TABLES
=============================================================================*/
table th {
font-weight: bold;
}
table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}
table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
/* IMAGES
=============================================================================*/
img {
max-width: 100%
}
</style>
</head>
<body>
<h1><strong>Cradlepoint Router Application Development</strong></h1>
<hr />
<h2>Quick Links</h2>
<h4><a href="#overview">Overview</a></h4>
<h4><a href="#community">Developer Community</a></h4>
<h4><a href="#knowledge">Cradlepoint Knowledge Base</a></h4>
<h4><a href="#environment">Router Python Environment</a></h4>
<h4><a href="#setup">Computer Setup Instructions</a></h4>
<h4><a href="#devmode">Router Development Mode</a></h4>
<h4><a href="#structure">Application Directory Structure</a></h4>
<h4><a href="#anatomy">Application Package Anatomy</a></h4>
<h4><a href="#sdk">SDK Instructions Overview</a></h4>
<h4><a href="#syslog">Router Syslog for Debugging</a></h4>
<h4><a href="#ncm">NCM Application Deployment</a></h4>
<h4><a href="#sample">Sample Application Walk Through</a></h4>
<p><a name="overview"></a></p>
<h2>Overview</h2>
<p>Cradlepoint’s Router Application Framework provides the ability to add intelligence in the router. Applications written in Python can be securely downloaded to the router via <a href="https://cradlepoint.com/ecm">Network Cloud Manager</a> (NCM). This allows for extended router features, FOG Computing, and IoT management.</p>
<p>At a high level, the Cradlepoint Router Apps/SDK is a mechanism to package a collection of files – including executable files – in an archive, which can be transferred securely via NCM, hidden within a Cradlepoint router, and executed as an extension to normal firmware.</p>
<h3>What is Supported?</h3>
<p>For the scope of this document, Router Apps are limited to the non-privileged Python scripts. Supported functionality:</p>
<ul>
<li>Standard TCP/UDP/SSL socket servers function on ports higher than 1024.</li>
<li>Standard TCP/UDP/SSL socket client to other devices (or the router as 127.0.0.1/localhost).</li>
<li>Access to serial ports via PySerial module, including native and USB-serial ports.</li>
<li>Ability to PING external devices.</li>
<li>UI Extensibility (i.e. Hot Spot splash page or other UI WEB pages)</li>
<li>Access to the Router API (aka: status and control tree data).</li>
<li>USB Memory device file access (USB Memory device support varies based on router).</li>
</ul>
<h3>What is not Supported?</h3>
<ul>
<li>Any form of natively compiled or kernel linked code.</li>
<li>Any function requiring privileged (or root) permissions.</li>
<li>Access to shared resources (for example: no ability to issue custom AT commands to cell modems).</li>
<li>Modifications of routing or security behavior.</li>
</ul>
<h3>Supported Routers</h3>
<p>The supported set of routers is:</p>
<ul>
<li>AER – 1600/1650, 2100, 3100/3150</li>
<li>COR – IBR1100/1150, IBR900/IBR950, IBR600B/IBR650B, IBR350</li>
<li>ARC - CBA850</li>
</ul>
<p>New routers products will support Python applications unless they are a special low-function, low-cost model.</p>
<h3>Application Development</h3>
<p>During development, an application can be directly installed into a 'DEV Mode' router. This makes it easier to debug and work through the development process. Once the application has been fully debugged and is ready for deployment, it can be installed via NCM at the group level.</p>
<h3>SDK Toolset</h3>
<p>Cradlepoint has a simplified SDK, written in python, which builds and creates an app package. The SDK, along with sample applications is located <a href="https://github.com/cradlepoint/sdk-samples/releases">here</a>. </p>
<p>For app development, the SDK is used to install, start, stop, uninstall, and check status of the application in a locally connected development router. The application package is the same for local debugging or for uploading to the NCM for production deployment. Application development can be done on Linux, OS X, and Windows operating systems with the same SDK.</p>
<p>This document is specifically written for SDN version 2.0 and above.</p>
<p><a name="community"></a> </p>
<h2>Developer Community</h2>
<p>Cradlepoint has a <a href="https://dev.cradlepoint.com">Developer Community Portal</a> to leverage knowledge, share, and collaborate with other developers. This forum is also actively monitored by Cradlepoint to answer questions.</p>
<p><a name="knowledge"></a></p>
<h2>Cradlepoint Knowledge Base</h2>
<p>The existing <a href="http://knowledgebase.cradlepoint.com">Cradlepoint Knowledge Base</a> also has many articles related to router applications and the SDK.</p>
<p><a name="environment"></a> </p>
<h2>Router Python Environment</h2>
<p>Application are written in python. However, the router only contains a subset of a typical python installation on a computer. The list of python modules in the router are listed here: <a href="https://dev.cradlepoint.com/s/article/ka1380000000EXWAA2/sdk-fw-6-1-0-modules">Router FW 6.1.0 Modules.</a> New python files can be added to you application but they must also adhere to this list.</p>
<p><a name="setup"></a></p>
<h2>Computer Setup Instructions</h2>
<p>The SDK and sample apps can be downloaded from <a href="https://github.com/cradlepoint/sdk-samples">https://github.com/cradlepoint/sdk-samples</a>. Below are the setup instruction for:</p>
<ul>
<li><a href="#Linux">Linux</a></li>
<li><a href="#Mac">OS X</a></li>
<li><a href="#Windows">Windows</a></li>
</ul>
<p><a name="Linux"></a></p>
<h3>Linux</h3>
<ol>
<li>
<p>Install python 3.5.1 from <a href="http://www.python.org">python.org</a>.</p>
</li>
<li>
<p>Add Linux development libraries.</p>
<pre><code>sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
sudo apt-get install sshpass
</code></pre>
</li>
<li>
<p>Install python libraries. </p>
<pre><code>sudo apt-get install python3-pip
pip3 install requests
pip3 install pyopenssl
pip3 install requests
pip3 install cryptography
</code></pre>
</li>
<li>
<p>Useful tools</p>
<p>PyCharm (community version is free): <a href="https://www.jetbrains.com/pycharm/download/#section=linux">https://www.jetbrains.com/pycharm/download/#section=linux</a>.</p>
</li>
</ol>
<p><a name="Mac"></a></p>
<h3>Mac OS X</h3>
<ol>
<li>
<p>Install python 3.5.1 from <a href="http://www.python.org">python.org</a>.</p>
</li>
<li>
<p>Install HomeBrew for package updates. </p>
<pre><code>/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
</code></pre>
</li>
<li>
<p>Install openssl.</p>
<pre><code>brew install openssl
</code></pre>
</li>
<li>
<p>Install python libraries. </p>
<pre><code>pip3 install requests
pip3 install pyopenssl
pip3 install requests
pip3 install cryptography
</code></pre>
</li>
<li>
<p>Useful tools</p>
<p>PyCharm (community version is free): <a href="https://www.jetbrains.com/pycharm/download/#section=macOS">https://www.jetbrains.com/pycharm/download/#section=macOS</a>.</p>
</li>
</ol>
<p><a name="Windows"></a></p>
<h3>Windows</h3>
<ol>
<li>Install python 3.5.1 from <a href="https://www.python.org/downloads/release/python-351/">https://www.python.org/downloads/release/python-351/</a>.</li>
<li>
The SDK requires some OpenSSL tools to generate digital signatures.
<ul>
<li>For 64bit OS: <a href="https://slproweb.com/download/Win64OpenSSL_Light-1_1_0f.exe">https://slproweb.com/download/Win64OpenSSL_Light-1_1_0f.exe</a></li>
<li>For 32bit OS: <a href="https://slproweb.com/download/Win32OpenSSL_Light-1_1_0f.exe">https://slproweb.com/download/Win32OpenSSL_Light-1_1_0f.exe</a></li>
</ul>
</li>
<li>
<p>Open a terminal window and use the following commands to install python libraries.</p>
<pre><code>python -m pip install -U pip
python -m pip install -U pyserial
python -m pip install -U requests
python -m pip install -U pyopenssl
</code></pre>
</li>
<li>
Useful tools
<ol>
<li>Putty: <a href="http://www.putty.org/">http://www.putty.org/</a></li>
<li>PyCharm (community version is free): <a href="https://www.jetbrains.com/pycharm/download/#section=windows">https://www.jetbrains.com/pycharm/download/#section=windows</a>.</li>
<li>7-zip: <a href="http://www.7-zip.org/">http://www.7-zip.org/</a></li>
<li>MarkdownPad: <a href="http://markdownpad.com/">http://markdownpad.com/</a></li>
</ol>
</li>
</ol>
<p><a name="structure"></a></p>
<h2>SDK/Apps Directory Structure</h2>
<p>Below is the directory structure for for the SDK and sample applications. The <strong>BOLD</strong> items are modified or created by the developer. The other files are used by the SDK or are referenced by the other files.</p>
<ul>
<li>
Router_Apps (directory)
<ul>
<li>
app_name (directory)
<ul>
<li><strong>package.ini</strong> - App initialization items.</li>
<li><strong>app_name.py</strong> - The app python code. There can be multiple py files based on the app design.</li>
<li>cs.py - This is included with every sample app and should be in your app. It contains a CSClient class which is a wrapper for the TCP interface to the router config store (i.e. the router trees). </li>
<li><strong>install.sh</strong> - Runs on app installation. (update with app name) </li>
<li><strong>start.sh</strong> - Script that starts an app (i.e. cppython app_name.py start).</li>
<li><strong>stop.sh</strong> - Script that stops an app (i.e. cppython app_name.py stop).</li>
</ul>
</li>
<li>
config (directory)
<ul>
<li><strong>settings.mk</strong> - Build system config settings (i.e. Router MAC, IP, Username, Password, etc.).</li>
</ul>
</li>
<li>
common
<ul>
<li>cs.py - This is included with every sample app and can be copied into your app directory. It contains a CSClient class which is a wrapper for the TCP. </li>
</ul>
</li>
<li>
tools (directory)
<ul>
<li>
bin (directory)
<ul>
<li>package_application.py - Used by SDK.</li>
<li>validate_application.py - Used by SDK.</li>
<li>pscp.exe - An executable use on Windows by the SDK.</li>
</ul>
</li>
</ul>
</li>
<li><strong>sdk_setting.ini</strong> - Used by the SDK and contains the settings for building the app and connecting to the local router.</li>
<li>Router_Application_Development_Guide.md </li>
<li>Router_APIs_for_Applications.md </li>
<li>Makefile_README.md </li>
</ul>
</li>
</ul>
<p>Based on the sdk_setting.ini file, the SDK will build all files located in the <em>app_name</em> directory into a <em>tar.gz</em> package that can then been installed into the router. This installation is either directly into the router (if in DEV mode) or via NCM for grouped routers.</p>
<p><a name="anatomy"></a></p>
<h2>Application Package Anatomy</h2>
<p>A router application package, which is a <em>tar.gz</em> archive, consists of a set of files that includes the python executable, start/stop scripts, initialization files, along with manifest and signature files. This package of files is built by the SDK base on the sdk_settings.ini. Some of these files, like the manifest and signature files, are created by the Make tool. Others are created by the application developer. Below are the example contents for a tar.gz archive created for a router application.</p>
<ul>
<li>
app_name (directory)
<ul>
<li>
METADATA (directory)
<ul>
<li>MANIFEST.json - Contains a file list along with hash signatures and other app the package initialization data.</li>
<li>SIGNATURE.DS - A signature file for the app package.</li>
</ul>
</li>
<li>app_name.py - The application python executable file.</li>
<li>cs.py - Another python file used by the app. There could be multiple python files depending on the application design.</li>
<li>package.ini - The package initialization data.</li>
<li>install.sh - The script run during installation.</li>
<li>start.sh - The script run when the app is started.</li>
<li>stop.sh - The script run when the app is stopped</li>
</ul>
</li>
</ul>
<h3>package.ini</h3>
<p>This initialization file contains information and about the application and items that affect installation and execution. This information will stored in /status/system/sdk within the router config store for installed apps.</p>
<p>For example:</p>
<pre><code>[hello_world]
uuid=7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c
vendor=Cradlepoint
notes=Hello World Demo Application
firmware_major=6
firmware_minor=1
restart=false
reboot=true
version_major=1
version_minor=6
auto_start=true
</code></pre>
<ul>
<li>
<p><strong>[hello_world]</strong> </p>
<p>This must contain the name of the application. In this example, hello_world is the application name.</p>
</li>
<li>
<p><strong>uuid</strong>
</p>
<p>Every app must contain a universally unique identifier (UUID).</p>
</li>
<li>
<p><strong>vendor</strong></p>
<p>This is the vendor name for the app.</p>
</li>
<li>
<p><strong>notes</strong></p>
<p>Add notes to describe the app or anything else.</p>
</li>
<li>
<p>**firmware_major and firmware_minor **</p>
<p>This is the required router firmware version for the app. <strong><em>Not implemented at this time.</em></strong></p>
</li>
<li>
<p><strong>restart</strong>
If set to 'true', then the application will be restarted if it dies or is not running. If false, the router will not attempt to restart the application.</p>
</li>
<li>
<p><strong>reboot</strong>
If set to 'true', the router will restart the application following a router reboot. Otherwise, it will not be restarted.</p>
</li>
<li>
<p><strong>version_major and version_minor</strong></p>
<p>This contains the app version. This must be incremented for any new production app used installed via NCM. It will not re-install the same version that already exist in the router.</p>
</li>
<li>
<p><strong>auto_start</strong></p>
<p>If set to 'true', the app will automatically start after installation. </p>
</li>
</ul>
<h3>install.sh</h3>
<p>This script is executed when the application is installed in the router. Typically it will just add logs for the installation.</p>
<p>For example:</p>
<pre><code>#!/bin/bash
echo "INSTALLATION hello_world on:" >> install.log
date >> install.log
</code></pre>
<h3>start.sh</h3>
<p>This script is executed when the application is started in the router. It contains the command to start the python script and pass any arguments. </p>
<p>For example:</p>
<pre><code>#!/bin/bash
cppython hello_world.py start
</code></pre>
<h3>stop.sh</h3>
<p>This script is executed when the application is stopped in the router. It contains the command to stop the python script. </p>
<p>For example:</p>
<pre><code>#!/bin/bash
cppython hello_world.py stop
</code></pre>
<p><a name="sdk"></a></p>
<h2>SDK Instructions Overview</h2>
<p>The SDK includes a python make.py file which is compatible for all supported platforms. There is also a GNU Makefile which can only be used with Linux or OS X. Both perform the same actions which are noted below. However, there are minor setup differences between the two. Developers can choose the one they prefer. For usage instructions, see:</p>
<ul>
<li><a href="#python_usage">Python SDK Usage</a></li>
<li><a href="gnu_make_usage">GNU Make SDK Usage</a></li>
</ul>
<h3>SDK actions are:</h3>
<p><strong>default (i.e. no action given):</strong>
Build and test the router reference app and create the archive file suitable for deployment to a router DEV mode or for uploading to NCM.</p>
<p><strong>clean:</strong>
Clean all project artifacts. Entails execution of all "-clean" make targets.</p>
<p><strong>package:</strong>
Create the app archive tar.gz file.</p>
<p><strong>status:</strong>
Fetch and print current app status from the locally connected router.</p>
<p><strong>install:</strong>
Secure copy the app archive to a locally connected router. The router must already be in SDK DEV mode via registration and licensing in NCM.</p>
<p><strong>start:</strong>
Start the app on the locally connected router.</p>
<p><strong>stop:</strong>
Stop the app on the locally connected router.</p>
<p><strong>uninstall:</strong>
Uninstall the app from the locally connected router.</p>
<p><strong>purge:</strong>
Purge all apps from the locally connected router.</p>
<p><a name="python_usage"></a></p>
<h3>Python SDK Usage</h3>
<p>All SDK functions are contained in the make.py python file. While this executable is the same regardless of the workstation platform, the python command is not. Use the following python command based on your platform:</p>
<ul>
<li>
<p>Linux or OS X:</p>
<pre><code>python3
</code></pre>
</li>
<li>
<p>Windows:</p>
<pre><code>python
</code></pre>
</li>
</ul>
<p>The command structure is: </p>
<pre><code>python(3) make.py <action>
</code></pre>
<p>The make.py usage is as follows:</p>
<ol>
<li>
<p>Update the sdk_setting.ini file based on your needs.</p>
<p>Example:</p>
<pre><code>[sdk]
app_name=ping
dev_client_ip=192.168.0.1
dev_client_username=admin
dev_client_password=44224267
</code></pre>
</li>
<li>
<p>Update the UUID in the package.ini file located in the app directory. </p>
<p>Example:</p>
<pre><code>[ping]
uuid=dd91c8ea-cd95-4d9d-b08b-cf62de19684f
</code></pre>
</li>
<li>
<p>Build the application package.</p>
<pre><code>python(3) make.py
</code></pre>
</li>
<li>
<p>Test connectivity with your router via the status target.</p>
<pre><code>python(3) make.py status
{
"data": {},
"success": true
}
</code></pre>
</li>
<li>
<p>Install the application on your router.</p>
<pre><code>python(3) make.py install
[email protected]'s password:
hspt.tar.gz 100% 1439 1.4KB/s 00:00
Received disconnect from 192.168.0.1: 11: Bye Bye
lost connection
</code></pre>
</li>
<li>
<p>Get the application execution status from your router.</p>
<pre><code>python(3) make.py status
{
"data": {
"7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c": {
"app": {
"date": "2015-12-04T09:30:39.656151",
"name": "hspt",
"restart": true,
"uuid": "7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"vendor": "Cradlebox",
"version_major": 1,
"version_minor": 1
},
"base_directory": "/var/mnt/sdk/apps/7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"directory": hspt",
"filename": "dist/tmp_znv2t",
"state": "started",
"summary": "Package started successfully",
"type": "development",
"url": "file:///var/tmp/tmpg1385l",
"uuid": "7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c"
}
},
"success": true
}
</code></pre>
</li>
<li>
<p>Uninstall the application from your router.</p>
<pre><code>python(3) make.py uninstall
{
"data": "uninstall 7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"success": true
}
</code></pre>
</li>
</ol>
<p><a name="gnu_make_usage"></a></p>
<h3>GNU Make SDK Usage</h3>
<p>A GNU Makefile, for Linux or OS X, is also included with the SDK which can perform the same functions as the make.py file. The make targets are identical to the make.py actions. However, environment variable will need to be set in lieu of the sdk_setting.ini file. </p>
<p>The GNU make usage is as follows:</p>
<ol>
<li>
<p>Export the following variables in your environment.</p>
<pre><code>APP_NAME - The name of your application.
APP_UUID - Each application must have its own UUID.
DEV_CLIENT_MAC - The mac address of your router.
DEV_CLIENT_IP - The lan ip address of your router.
</code></pre>
<p>Example:</p>
<pre><code>$ export APP_NAME=hello_world
$ export APP_UUID=616acd0c-0475-479e-a33b-f7054843c973
$ export DEV_CLIENT_MAC=44224267
$ export DEV_CLIENT_IP=192.168.20.1
</code></pre>
</li>
<li>
<p>Build the application package.</p>
<pre><code>$ make
</code></pre>
</li>
<li>
<p>Test connectivity with your router via the status target.</p>
<pre><code>$ make status
curl -s --digest --insecure -u admin:441dbbec \
-H "Accept: application/json" \
-X GET http://192.168.0.1/api/status/system/sdk | \
/usr/bin/env python3 -m json.tool
{
"data": {},
"success": true
}
</code></pre>
</li>
<li>
<p>Build, test, and install the application on your router.</p>
<pre><code>$ make install
scp /home/sfisher/dev/sdk/hspt.tar.gz [email protected]:/app_upload
[email protected]'s password:
hspt.tar.gz 100% 1439 1.4KB/s 00:00
Received disconnect from 192.168.0.1: 11: Bye Bye
lost connection
</code></pre>
</li>
<li>
<p>Get application execution status from your router.</p>
<pre><code>$ make status
curl -s --digest --insecure -u admin:441dbbec \
-H "Accept: application/json" \
-X GET http://192.168.0.1/api/status/system/sdk | \
/usr/bin/env python3 -m json.tool
{
"data": {
"7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c": {
"app": {
"date": "2015-12-04T09:30:39.656151",
"name": "hspt",
"restart": true,
"uuid": "7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"vendor": "Cradlebox",
"version_major": 1,
"version_minor": 1
},
"base_directory": "/var/mnt/sdk/apps/7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"directory": hspt",
"filename": "dist/tmp_znv2t",
"state": "started",
"summary": "Package started successfully",
"type": "development",
"url": "file:///var/tmp/tmpg1385l",
"uuid": "7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c"
}
},
"success": true
}
</code></pre>
</li>
<li>
<p>Uninstall the application from your router.</p>
<pre><code>$ make uninstall
curl -s --digest --insecure -u admin:441dbbec \
-H "Accept: application/json" \
-X PUT http://192.168.0.1/api/control/system/sdk/action \
-d data='"uninstall 7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c"' | \
/usr/bin/env python3 -m json.tool
{
"data": "uninstall 7042c8fd-fe7a-4846-aed1-e3f8d6a1c91c",
"success": true
}
</code></pre>
</li>
</ol>
<p><a name="syslog"></a></p>
<h2>Router Syslog for Debugging</h2>
<p>Application debugging is accomplished with the use of debug syslogs. However, the default logging level in the router is set to <strong>info</strong> so this will need to be changed to <strong>debug</strong>. It is also possible to send the router logs to a syslog server running on another device. For more information, see the Knowledge Base article <a href="http://knowledgebase.cradlepoint.com/articles/Support/fw6-Understanding-Router-Log-Files-and-Features?retURL=%2Fapex%2FknowledgeSearch%3Fc%3DAll_Products%26p%3D2%26k%3Dsyslog%26t%3D%26l%3D%26lang%3Den_US&popup=false&c=All_Products&lang=en_US">'Understanding Router Log Files'</a>.</p>
<p>You can also view logs via CLI commands when logged into the router console. This console is available by logging into the router with Secure Shell (i.e. ssh) or by slecting the 'Device Console' from 'System > System Control > Device Options' in the router UI. The logs can be viewed or cleared with the following CLI commands:</p>
<pre><code>log (displays logs in the terminal window)
log -s <text> (search for logs that contain <text> and displays them)
log -s -i <text> (search for logs that contain <text> but case insensitive)
log clear (clears the log buffer)
help log (display the log command options)
</code></pre>
<p><a name="devmode"></a></p>
<h2>Router Development Mode</h2>
<p>In order to install an application directly to the router without using NCM, the router must be placed in <strong>DEV</strong> mode. One would typically debug and test an application using <strong>DEV</strong> mode prior to using NCM for installation. <strong>DEV</strong> mode allows for quicker and easier testing and debugging. Instructions for setting up a router for <strong>DEV</strong> mode is in Knowledge Base article <a href="https://dev.cradlepoint.com/s/article/ka1380000000EXqAAM/sdk-enable-development-mode">'SDK Enable Developer Mode'</a>. </p>
<p><a name="ncm"></a></p>
<h2>NCM Application Deployment</h2>
<p>NCM is used to securely deploy applications to routers at the group level. If an application <em>tar.gz</em> package is uploaded to NCM and then assigned to a router group, NCM will then securely download and install the application to the routers within the group. For security, the application files are not user accessible within NCM or routers. That is, one is not able to download the application from the router or NCM.</p>
<p><a name="sample"></a></p>
<h2>Sample Application Walk Through</h2>
<p>Cradlepoint has provided several sample applications with the SDK which is located <a href="https://github.com/cradlepoint/sdk-samples">here</a>. Any of these apps can be used as a starting point for your application. The application data structure is described <a href="#overview">here</a>. </p>
<p>When using the SDK make.py file, be sure to invoke the proper python command based on your computer OS.</p>
<ul>
<li>
<p>Linux or OS X:</p>
<pre><code>python3
</code></pre>
</li>
<li>
<p>Windows:</p>
<pre><code>python
</code></pre>
</li>
</ul>
<h3>How to Run the Hello World Sample App</h3>
<ol>
<li>Download the SDK and sample apps from <a href="https://github.com/cradlepoint/sdk-samples">here</a>.</li>
<li>Ensure your computer has been setup. See <a href="#setup">Computer Setup Instructions</a>.</li>
<li>Connect the router to your computer. This can be done by connecting the LAN port of the router to the USB port of your computer via a USB to Ethernet adapter.</li>
<li>Ensure the router is in DEV Mode. See <a href="#devmode">here</a>.</li>
<li>Enable Debug logs in the router which is very helpful. See <a href="http://knowledgebase.cradlepoint.com/articles/Support/fw6-Understanding-Router-Log-Files-and-Features?retURL=%2Fapex%2FknowledgeSearch%3Fc%3DAll_Products%26p%3D3%26k%3Ddebug%2Blogs%26t%3D%26l%3D%26lang%3Den_US&popup=false&c=All_Products&lang=en_US">here</a></li>
<li>Open a terminal window.</li>
<li>Change directory to 'sample_apps'.</li>
<li>
<p>Update the sdk_setting.ini file based on your needs and for the sample app you wish to run. The hello_world is a good app to test.</p>
<p>Example:</p>
<pre><code>[sdk]
app_name=hello_world
dev_client_ip=192.168.0.1
dev_client_username=admin
dev_client_password=44224267
</code></pre>
</li>
<li>
<p>Verify router connectivity via:</p>
<pre><code>$ python(3) make.py status
</code></pre>
</li>
<li>
<p>Create the application package</p>
<pre><code>$ python(3) make.py
</code></pre>
</li>
<li>
<p>Install the application package</p>
<pre><code>$ python(3) make.py install
</code></pre>
</li>
<li>
<p>Check the application status to ensure it has started.</p>
<pre><code>$ python(3) make.py status
</code></pre>
</li>
<li>
<p>Also check the logs in the router to ensure the application is creating 'Hello World' logs. In the router console use the 'log' command.</p>
</li>
</ol>
<hr />
<p>Published Date: 6-30-2017</p>
<p>This article not have what you need? Not find what you were looking for? Think this article can be improved? Please let us know at <a href="mailto:suggestions@cradlepoint.com">suggestions@cradlepoint.com</a>.</p>
</body>
</html>
<!-- This document was created with MarkdownPad, the Markdown editor for Windows (http://markdownpad.com) -->