20180921_jeffrey - silenceuncrio/diary GitHub Wiki

0900

review

多測個幾次從 web ui 做 firmware upgrade

0945

發現卡在 firmware.cgi?act=upgrade 這支 CGI

image

改一下該 CGI 的寫法 - proscend/prosrc/webcgi/firmware.c

@@ -17,13 +17,23 @@

 static void _upgrade()
 {
-
     char cmd[256];

+    pid_t pid;
+    pid = fork();
+    if (pid != 0)
+    {
+        jweb.out.json.ok();
+    }
+
+    fclose (stdin);
+    fclose (stdout);
+
     sprintf(cmd, "/usr/sbin/icos/FirmwareUpgrade.sh /tmp/firmware.upload &");
     system(cmd);

-    jweb.out.json.ok();
+    cgiFree (cgi);
+    exit(0);
 }

目的是讓 firmware.cgi?act=upgrade 這支 CGI 趕快 return 完再去做下面的事

sprintf(cmd, "/usr/sbin/icos/FirmwareUpgrade.sh /tmp/firmware.upload &");
     system(cmd);

成果

image

可以來好好盤一下 javascript 那邊的百分比怎麼畫了

先上 code

commit 0cb2e3e34d737aaadab800680a84804d2cbfb5b1
Refs: [develop], {origin/develop}, {origin/HEAD}
Author: jeffrey <[email protected]>
Date:   Fri Sep 21 09:59:31 2018 +0800

    make sure the 'firmware.cgi?act=upgrade' return first then do the upgrading

 proscend/prosrc/webcgi/firmware.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

1300

上傳大概花了 10.7 秒

整個 upgrade 的過程約 18.95 秒

全部大約花了 29.65 秒

1 秒就算 3 % 吧

1345

成果還算滿意

上 code

commit d6a1645de81c820e006cee96039944aaed6e53db
Refs: [develop], {origin/develop}, {origin/HEAD}
Author: jeffrey <[email protected]>
Date:   Fri Sep 21 13:47:24 2018 +0800

    fine tune the progress bar of firmware upgrade

 proscend/prosrc/www/app/feature/firmware.js | 61 +++++++++++++++++++----------
 1 file changed, 41 insertions(+), 20 deletions(-)

1440

M360 的 ping 要能指定 interface

因為有兩個 APN 的關係

ping 有現成的 option 可以用

root@52XXZ:~# ping --help
BusyBox v1.17.1 (2018-09-20 02:35:46 UTC) multi-call binary.

Usage: ping [OPTIONS] HOST

Send ICMP ECHO_REQUEST packets to network hosts

Options:
        -4, -6          Force IP or IPv6 name resolution
        -c CNT          Send only CNT pings
        -s SIZE         Send SIZE data bytes in packets (default:56)
        -I IFACE/IP     Use interface or IP address as source
        -W SEC          Seconds to wait for the first response (default:10)
                        (after all -c CNT packets are sent)
        -w SEC          Seconds until ping exits (default:infinite)
                        (can exit earlier with -c CNT)
        -q              Quiet, only displays output at start
                        and when finished

1500

架一台 M360 起來吧

在 M360P LTE Net Mode 為 Bridge + Router 時的 Status

image

當下的 ifconfig

root@M360-P:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:43:28:80:F8
          inet6 addr: fe80::20c:43ff:fe28:80f8/64 Scope:Link
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1
          RX packets:931 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1266 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:113476 (110.8 KiB)  TX bytes:1454923 (1.3 MiB)
          Interrupt:3

eth1      Link encap:Ethernet  HWaddr A2:0C:27:9A:82:78
          inet6 addr: fe80::a00c:27ff:fe9a:8278/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:53 errors:0 dropped:2 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:936 (936.0 B)  TX bytes:3912 (3.8 KiB)

lan       Link encap:Ethernet  HWaddr 00:0C:43:28:80:F8
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:43ff:fe28:80f8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:933 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1254 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:96004 (93.7 KiB)  TX bytes:1452914 (1.3 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:172 errors:0 dropped:0 overruns:0 frame:0
          TX packets:172 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:134022 (130.8 KiB)  TX bytes:134022 (130.8 KiB)

ppp800    Link encap:Point-to-Point Protocol
          inet addr:10.108.32.143  P-t-P:10.64.67.96  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1280  Metric:1
          RX packets:39 errors:0 dropped:0 overruns:0 frame:0
          TX packets:58 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:6110 (5.9 KiB)  TX bytes:3396 (3.3 KiB)

APN1 就是 eth1, APN2 就是 ppp800

目前 M360P Ping 的功能如下

image

如果想指定經由 APN1(eth1) 來 ping 比如 8.8.8.8 的話

可以用 ping -c 4 -I eth1 8.8.8.8

root@M360-P:/tmp/www/app/feature# ping -c 4 -I eth1 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss

如果想指定經由 APN2(ppp800) 來 ping 比如 8.8.8.8 的話

可以用 ping -c 4 -I ppp800 8.8.8.8

root@M360-P:/tmp/www/app/feature# ping -c 4 -I ppp800 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=56 time=29.494 ms
64 bytes from 8.8.8.8: seq=1 ttl=56 time=81.711 ms
64 bytes from 8.8.8.8: seq=2 ttl=56 time=27.749 ms
64 bytes from 8.8.8.8: seq=3 ttl=56 time=71.368 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 27.749/52.580/81.711 ms

1540

修改如下

diff --git a/proscend/prosrc/www/app/feature/ping.html b/proscend/prosrc/www/app/feature/ping.html
index 2c45855..d248338 100644
--- a/proscend/prosrc/www/app/feature/ping.html
+++ b/proscend/prosrc/www/app/feature/ping.html
@@ -13,6 +13,28 @@

 <form class="form-horizontal" name="form">

+  <div class="form-group">
+    <label class="col-sm-3 control-label">{{ 'PING_LABEL_USE_INTERFACE_AS_SOURCE' | translate }}</label>
+    <div class="col-sm-9">
+      <label class="radio-inline">
+        <input type="radio" ng-model="vm.use_interface_as_source" value="0">
+          {{ 'NO' | translate }}</label>
+      <label class="radio-inline">
+        <input type="radio" ng-model="vm.use_interface_as_source" value="1">
+          {{ 'YES' | translate }}</label>
+    </div>
+  </div>
+
+  <div class="form-group">
+    <label class="col-sm-3 control-label">{{ 'PING_LABEL_INTERFACE' | translate }}</label>
+    <div class="col-sm-9">
+      <select class="form-control" ng-model="vm.use_interface">
+      <option value="eth0">APN1</option>
+      <option value="ppp800">APN2</option>
+      </select>
+    </div>
+  </div>
+
   <div class="form-group" ng-class="{ 'has-error': form.host.$invalid }">
     <label for="addr" class="col-sm-3 control-label">{{ 'PING_LABEL_HOST' | translate }}</label>
     <div class="col-sm-9">
diff --git a/proscend/prosrc/www/app/feature/ping.js b/proscend/prosrc/www/app/feature/ping.js
index c6d0858..1dc5b6b 100644
--- a/proscend/prosrc/www/app/feature/ping.js
+++ b/proscend/prosrc/www/app/feature/ping.js
@@ -21,8 +21,18 @@ angular.module('app').controller('pingController', pingController);
 function pingController() {
     var vm = this;

+    vm.use_interface_as_source = 0;
+    vm.use_interface = "ppp800";
+    vm.host = "";
+
     vm.ping = function () {
-        vm.url = '/cgi-bin/popen.cgi?command=ping -c 4 ' + vm.host + '&v=' + Math.random();
+        if (vm.use_interface_as_source == 0) {
+            vm.url = '/cgi-bin/popen.cgi?command=ping -c 4 ' + vm.host + '&v=' + Math.random();
+            console.log(vm.url);
+        } else {
+            vm.url = '/cgi-bin/popen.cgi?command=ping -c 4 -I ' + vm.use_interface + ' ' + vm.host + '&v=' + Math.random();
+            console.log(vm.url);
+        }
     }

 };
diff --git a/proscend/prosrc/www/app/locale-en.json b/proscend/prosrc/www/app/locale-en.json
index abca3f5..42327e5 100644
--- a/proscend/prosrc/www/app/locale-en.json
+++ b/proscend/prosrc/www/app/locale-en.json
@@ -1504,6 +1504,8 @@
   "PING_PANEL_TITLE":                           "Ping",
   "PING_LABEL_HOST":                            "Host",
   "PING_BUTTON_PING":                           "Ping",
+  "PING_LABEL_USE_INTERFACE_AS_SOURCE":         "Use Interface As Source",^M
+  "PING_LABEL_INTERFACE":                       "Use Interface",^M



diff --git a/proscend/prosrc/www/app/locale-fr.json b/proscend/prosrc/www/app/locale-fr.json
index ea18e78..129468f 100644
--- a/proscend/prosrc/www/app/locale-fr.json
+++ b/proscend/prosrc/www/app/locale-fr.json
@@ -1504,6 +1504,8 @@
   "PING_PANEL_TITLE":                           "Ping",
   "PING_LABEL_HOST":                            "Host",
   "PING_BUTTON_PING":                           "Ping",
+  "PING_LABEL_USE_INTERFACE_AS_SOURCE":         "Use Interface As Source",^M
+  "PING_LABEL_INTERFACE":                       "Use Interface",^M



diff --git a/proscend/prosrc/www/app/locale-zh-tw.json b/proscend/prosrc/www/app/locale-zh-tw.json
index bdae3d7..6103a5c 100644
--- a/proscend/prosrc/www/app/locale-zh-tw.json
+++ b/proscend/prosrc/www/app/locale-zh-tw.json
@@ -1504,6 +1504,8 @@
   "PING_PANEL_TITLE":                           "Ping",
   "PING_LABEL_HOST":                            "Host",
   "PING_BUTTON_PING":                           "Ping",
+  "PING_LABEL_USE_INTERFACE_AS_SOURCE":         "Use Interface As Source",^M
+  "PING_LABEL_INTERFACE":                       "Use Interface",^M

成果

image

測試

M360P - Ping - use interface as source - test - APN2

image

M360P - Ping - use interface as source - test - APN1

image

上 code

commit 8048b1c8d45fa5a9ea39a3de2378aa2e0d0a6f6c
Refs: [develop], {origin/develop}
Author: jeffrey <[email protected]>
Date:   Fri Sep 21 15:48:12 2018 +0800

    add 'Use Interface As Source' for 'Diagnosis / Ping'

 proscend/prosrc/www/app/feature/ping.html | 22 ++++++++++++++++++++++
 proscend/prosrc/www/app/feature/ping.js   | 12 +++++++++++-
 proscend/prosrc/www/app/locale-en.json    |  2 ++
 proscend/prosrc/www/app/locale-fr.json    |  2 ++
 proscend/prosrc/www/app/locale-zh-tw.json |  2 ++
 5 files changed, 39 insertions(+), 1 deletion(-)

1555

M360P 的 firmware.cgi?act=upgrade 一樣有咬住的問題

image

M360 firmware upload 大約要 5.3 秒

upgrade 大概只要 9 秒

總共要 14.3 秒

每 1 秒可以當成 7%

那 upload 大概就佔了 42%

上 code

commit dec9ae28e67ba5b9e2cfe072f39f7f99e1259921
Refs: [develop], {origin/develop}
Author: jeffrey <[email protected]>
Date:   Fri Sep 21 16:21:51 2018 +0800

    make sure the 'firmware.cgi?act=upgrade' return first then do the upgrading:
    - fine tune the progress bar of firmware upgrade

 proscend/prosrc/webcgi/firmware.c           | 14 ++++++-
 proscend/prosrc/www/app/feature/firmware.js | 65 +++++++++++++++++++----------
 2 files changed, 55 insertions(+), 24 deletions(-)

1710

盤一下待做工作

M360 的 schedule reboot 不用在 下禮拜五 release

multiple lock pic 還比較緊急

不過我花了一些時間先 survey 一下後續 M360 schedule reboot 要怎麼作

M360P 目前已經有 crond 可以用了

先測試一下

每兩分鐘紀錄一下目前時間到 /tmp/xxx.txt

root@M360-P:~# killall crond
root@M360-P:~# vi /etc/crontabs/root
root@M360-P:~# cat /etc/crontabs/xxx
*/2 * * * * date >> /tmp/xxx.txt

把 crond 叫起來

root@M360-P:~# crond
root@M360-P:~# 

等一小段時間然後看一下 /tmp/xxx.txt

root@M360-P:~# cat /tmp/xxx.txt
Fri Sep 21 09:26:01 GREEN 2018
Fri Sep 21 09:28:01 GREEN 2018
Fri Sep 21 09:30:01 GREEN 2018
root@M360-P:~#

看來沒什麼問題

雖然不能直接套用 M300 上的 code

但一步一步邊套邊測一定是沒問題的

⚠️ **GitHub.com Fallback** ⚠️