2021年11月30日 星期二

EZChart Data

意外看到EZChart臺灣股市歷史資料
寫一下程式把資料爬出來

static void Main(string[] args) { var file = File.OpenRead(@"C:\Program Files (x86)\ezChart\Data\0050.dat"); var size = file.Length; using (var br = new BinaryReader(file)) { long readsize = 0; while (size > readsize) { int date = br.ReadInt32(); decimal opening = (decimal)br.ReadInt32() / 100; decimal highest = (decimal)br.ReadInt32() / 100; decimal lowest = (decimal)br.ReadInt32() / 100; decimal closing = (decimal)br.ReadInt32() / 100; int volume = br.ReadInt32(); Console.WriteLine($"date: {date},opening: {opening}, highest: {highest}, lowest: {lowest}, closing: {closing}, volume: {volume}"); readsize += sizeof(Int32) * 6; } } }

https://ez1data.blogspot.com/2024/11/ezchart-1131127.html?m=1

2021年3月3日 星期三

Install Jupyterlab on Cygwin

 setup-x86_64.exe -q --packages=libzmq-devel,libffi-devel,python37-devel

pip3.7 install jupyterlab

Offline Install Ansible on Windows using Cygwin

1. Downloading setup-x86_64.exe(https://www.cygwin.com/)

2. if no admin

     Comment
setup-x86_64.exe --no-admin

3. search ansible and download

4. Offline install

5. search ansible and install


6. 直接安裝

setup-x86_64.exe -q --packages=ansible

2021年1月16日 星期六

Grafana 筆記

handling NULL values in Query-based variable

 PostgreSQL query 變數空值處理

WHERE "my_field" IN (${my_variable})

當變數出現空值時

Templating
Template variables could not be initialized: pq: syntax error at or near ")"

變數格式改用pipe

WHERE "my_field" ~ ('${my_variable:pipe}')

解決~


key/value pairs as template variables on grafana

寫法

SELECT hostname AS __text, id AS __value FROM host

https://grafana.com/docs/grafana/latest/datasources/postgres/



LDAP - Active Directory server setup

公司環境再設定綁定不希望設定檔上出現帳密

調整設定如下:

[註:]內部Ldap 查詢功能會不能使用

bind_dn = "CORP\\%s" # or "%s@corp.local"
search_filter = "(sAMAccountName=%s)"
search_base_dns = ["dc=corp,dc=local"]

# 註解group mappings
# [[servers.group_mappings]]

https://grafana.com/docs/grafana/latest/auth/ldap/




2020年11月27日 星期五

redhat8 offline install ansible

Redhat Ansible by Py3.8
================
Red Hat 8.1
Python 3.8
ansible-2.9.13

# Python 3.8
------------------
python38-3.8.0-6.module_el8.2.0+317+61fa6e7d.x86_64.rpm
python38-libs-3.8.0-6.module_el8.2.0+317+61fa6e7d.x86_64.rpm
python38-pip-19.2.3-5.module_el8.2.0+317+61fa6e7d.noarch.rpm
python38-pip-wheel-19.2.3-5.module_el8.2.0+317+61fa6e7d.noarch.rpm
python38-setuptools-41.6.0-4.module_el8.2.0+317+61fa6e7d.noarch.rpm
python38-setuptools-wheel-41.6.0-4.module_el8.2.0+317+61fa6e7d.noarch.rpm

## 下載來源
------------------
http://rpmfind.net/linux/rpm2html/search.php?query=pkgconfig(python-3.8)

# Ansible
------------------
Jinja2-2.11.2-py2.py3-none-any.whl
MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
PyYAML-5.3.1.tar.gz
ansible-latest.tar.gz
cffi-1.14.3-cp38-cp38-manylinux1_x86_64.whl
cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl
pycparser-2.20-py2.py3-none-any.whl
python3.8
six-1.15.0-py2.py3-none-any.whl

## 下載來源
------------------
ansible-2.9.13.tar.gz
https://releases.ansible.com/ansible/ansible-latest.tar.gz
or
https://pypi.org/simple/ansible/

six-1.15.0-py2.py3-none-any.whl
https://pypi.org/simple/six/

pycparser-2.20-py2.py3-none-any.whl
https://pypi.org/simple/pycparser/

cffi-1.14.3-cp38-cp38-manylinux1_x86_64.whl
https://pypi.org/simple/cffi/

cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl
https://pypi.org/simple/cryptography/

MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
https://pypi.org/simple/markupsafe/

Jinja2-2.11.2-py2.py3-none-any.whl
https://pypi.org/simple/jinja2/

PyYAML-5.3.1.tar.gz
https://pypi.org/simple/pyyaml/

# Instaill
------------------
#!/bin/bash

RPM_INSTALL_PATH=/install/python


echo ""
echo "-------Python install---------"
rpm -ivh $RPM_INSTALL_PATH/*.rpm

WHL_INSTALL_PATH=/install/ansible

echo ""
echo "-------Ansible install---------"

sudo pip3.8 install $WHL_INSTALL_PATH/six-1.15.0-py2.py3-none-any.whl
sudo pip3.8 install $WHL_INSTALL_PATH/pycparser-2.20-py2.py3-none-any.whl
sudo pip3.8 install $WHL_INSTALL_PATH/cffi-1.14.3-cp38-cp38-manylinux1_x86_64.whl
sudo pip3.8 install $WHL_INSTALL_PATH/cryptography-3.2.1-cp35-abi3-manylinux2010_x86_64.whl

sudo pip3.8 install $WHL_INSTALL_PATH/MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl
sudo pip3.8 install $WHL_INSTALL_PATH/Jinja2-2.11.2-py2.py3-none-any.whl

sudo pip3.8 install $WHL_INSTALL_PATH/PyYAML-5.3.1.tar.gz
sudo pip3.8 install $WHL_INSTALL_PATH/ansible-latest.tar.gz


2020年1月18日 星期六

Intel® Joule™ 550x 安裝ubuntu

前言

Intel 已經沒有維護了才拿出來玩...
物盡其用就把它當作小PC使用吧!

BIOS

joule-firmware-2017-06-02-1H3-public

[註]:千萬不要用最新的版本1J2,我當初刷下去後開機會卡在BIOS無法使用

OS

內存:
eMMC 8GB
內建Yocto作業系統
不建議刷掉此作業系統,
作業系統已經設好serial consle,
可以只接serial line直接連進機器
[註]:shutdown -r 0 //Yocto重開機指令


SDCard:
安裝ubuntu-18.04.3-server

安裝過程:
CPU是x86架構沒什麼困難
只要想辦法把OS塞進SDCard插進板子就沒問題了

我下載ubuntu-18.04.3-live-server-amd64.iso
直接使用PC將ubuntu安裝至SDCard
安裝完成順便安裝套件wireless-tools、wpa_supplicant、firmware-iwlwifi
機器插入SDCard,接上HDMI、鍵盤開機

為了方便使用serial line直接Debug,
設定serial consle,Grub及Ubuntu的sericl consle參照下方設定

設定完成後開機過程包含BIOS都可以透過serial去做操作
[註]:baud rate 115200



Serial Consle

GRUB

https://c4691294.coding.me/Linux/Ubuntu-18-04配置serial-console/
我這邊找到serial port是掛在ttyS6
使用dmesg | grep tty
Yocto跟Ubuntu比對查找
/etc/default/grub
mowei@mowei:/etc/default$ vim grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS6,115200n8"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"


sudo update-grub




\boot\grub\grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_msdos
insmod ext2
set root='hd3,msdos5'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd3,msdos5 --hint-efi=hd3,msdos5 --hint-baremetal=ahci3,msdos5  2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
else
  search --no-floppy --fs-uuid --set=root 2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ] ; then
  set timeout=30
else
  if [ x$feature_timeout_style = xy ] ; then
    set timeout_style=menu
    set timeout=5
  # Fallback normal timeout code in case the timeout_style feature is
  # unavailable.
  else
    set timeout=5
  fi
fi
play 480 440 1
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
	set gfxpayload="${1}"
}
set linux_gfx_mode=
export linux_gfx_mode
menuentry 'Debian GNU/Linux' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b' {
	load_video
	insmod gzio
	if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
	insmod part_msdos
	insmod ext2
	set root='hd3,msdos5'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd3,msdos5 --hint-efi=hd3,msdos5 --hint-baremetal=ahci3,msdos5  2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
	else
	  search --no-floppy --fs-uuid --set=root 2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
	fi
	echo	'Loading Linux 4.19.0-14-amd64 ...'
	linux	/boot/vmlinuz-4.19.0-14-amd64 root=UUID=2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b ro  quiet
	echo	'Loading initial ramdisk ...'
	initrd	/boot/initrd.img-4.19.0-14-amd64
}
submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option 'gnulinux-advanced-2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b' {
	menuentry 'Debian GNU/Linux, with Linux 4.19.0-14-amd64' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.0-14-amd64-advanced-2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd3,msdos5'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd3,msdos5 --hint-efi=hd3,msdos5 --hint-baremetal=ahci3,msdos5  2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
		else
		  search --no-floppy --fs-uuid --set=root 2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
		fi
		echo	'Loading Linux 4.19.0-14-amd64 ...'
		linux	/boot/vmlinuz-4.19.0-14-amd64 root=UUID=2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b ro  quiet
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.19.0-14-amd64
	}
	menuentry 'Debian GNU/Linux, with Linux 4.19.0-14-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.0-14-amd64-recovery-2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b' {
		load_video
		insmod gzio
		if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
		insmod part_msdos
		insmod ext2
		set root='hd3,msdos5'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd3,msdos5 --hint-efi=hd3,msdos5 --hint-baremetal=ahci3,msdos5  2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
		else
		  search --no-floppy --fs-uuid --set=root 2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b
		fi
		echo	'Loading Linux 4.19.0-14-amd64 ...'
		linux	/boot/vmlinuz-4.19.0-14-amd64 root=UUID=2efeb6e4-c104-4fcb-a3f1-1b3c74a8867b ro single 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-4.19.0-14-amd64
	}
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {
	fwsetup
}
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

Systemd

下面似乎無效改用getty@.service


vim /etc/init.d/ttyS6.conf
# ttyS6 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -L 115200 ttyS6 vt100

getty@.service

sudo nano /lib/systemd/system/serial-getty@.service
First we need to edit the serial-getty service to set the correct bard rate.

# Edit this line
ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM

# To This
ExecStart=-/sbin/agetty 115200 %I $TERM
Set this to the bard rate that you wish to use. This should be the same at the computer is using at the other end.

systemctl daemon-reload

# For a USB serial adaptor
systemctl enable serial-getty@ttyUSB0.service

# For a built in serial port /dev/ttyS6
systemctl enable serial-getty@ttyS6.service

NetWork

抓取iwlwifi-8000C 至/lib/firmware
modprobe -r iwlwifi; modprobe iwlwifi
安裝wpa_supplicant
sudo ifconfig wlp1s0 up
sudo iwlist wlp1s0 scan
sudo wpa_passphrase EssidName Pass  | sudo cat >> /etc/wpa_supplicant/wpa_supplicant.conf
sudo wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf  -i wls1p0
sudo dhclient wlp1s0
Network設定
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

allow-hotplug wlp1s0
    iface wlp1s0 inet dhcp
    wireless-essid EssidName
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Bluetooth 設定
https://chenhh.gitbooks.io/ubuntu-linux/content/bluetooth.html

wget http://ftp.tw.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-iwlwifi_20190114-2_all.deb
dpkg -i firmware-iwlwifi_20190114-2_all.deb

sudo apt-get install bluez* bluetooth rfkill

hciconfig -a
sudo hciconfig info
sudo hciconfig hci0 up
sudo hcitool scan

2017年7月15日 星期六

Voip SPA3000/9000 設定


架設Voip

1.Analog Telephone Adaptor (ATA)

一個類比電話轉換到基於數位VoIP電話網路

An ATA contains the following components:
  • FXS Ports – Used for interfacing with analog telephones.
  • RJ45 Ports – Used for interfacing with the LAN/WAN
  • FXO Ports – Used for interfacing with the PSTN

2.網絡電話交換機(IPPBX)

能通過IP網提供語音、視頻以及即時消息通信。這些通信不僅可以在企業內部網上進行,也可以通過Internet與外網甚至PSTN(Public Switched Telephone Network)電話間進行。

3.網路電話(IPPHONE)

SPA921、支援SIP應用程式或電話


SPA3000設定

參照 OSSLab 的設定設完發現會PSTN接到來電時
等到 PSTN Answer Delay 秒數過後將會自動接起外線
仍然等待Voip分機接起話筒可能會造成撥打者不必要的電話費
可能原因是 Off Hook While Calling VoIP  被設為Yes

SPA9000設定

Wan Setup
Internet Connection Settings
Connection Type:
SIP
Hunt Groups:
設定群組獵線 群組號碼為500,分機100-102, 響鈴300秒

回到SPA3000

PSTN Line
Dial Plan 2:

來電時將轉接至群組


發現的問題:
剛開機使用SPA3000 LINE1 撥打至PSTN Line 分機
在打外線會導致所有分機都將無法在外線
開完機後先用其他分機撥打測試後就可正常使用

預測2031/1/1可能 TWCA 憑證 IOS會出現不信任

緣由: TWCA CYBER Root CA 有兩張、兩個效期 (2030、2047年到期) 推測TWCA 預計 2030年12月會停用: TWCA CYBER Root CA (2030 年到期) TWCA Global Root CA 改用啟用: TWCA CYBER ...