หน้าเว็บ

วันอาทิตย์ที่ 23 กุมภาพันธ์ พ.ศ. 2563

Home Assistant : HA Install On Pi Run Play MP3

Home Assistant : HA Install On Pi Run Play MP3
1. Download PI และ Restore ใส่ SD Card นำไป Boot
https://www.raspberrypi.org/downloads/raspbian/

2. ตั้งค่า wifi
https://raspberrypihq.com/how-to-connect-your-raspberry-pi-to-wifi/
ถ้ามี Error แสดง
Wi-Fi is currently blocked by rfkill

ใช้คำสั่ง
  1. sudo rfkill unblock 0
  2. ifconfig wlan0 up

https://www.raspberrypi.org/forums/viewtopic.php?t=206223

3. Set Wifi Connect
  1. iwlist wlan0 scan
  2. nano /etc/wpa_supplicant/wpa_supplicant.conf

เพิ่ม
network={
ssid="SCI_EMP"
psk="XXXXXX"
}
แล้ว reboot เครื่อง Run คำสั่ง
  1. ifconfig wlan0

จะได้ IP

4. Config rapberry pi
เลือก Time zone
  1. open ssh timezone

  1. raspi-config

- เปลี่ยนชื่อ Host ตามที่ต้องการ เช่น pi-moning
- เปิด ssh
และอื่น ๆ
Run set locale
  1. locale-gen en_US en_US.UTF-8 th_TH th_TH.UTF-8

ติดตั้ง ntp และ config ntp

5. ติดตั้ง
https://www.home-assistant.io/docs/installation/raspberry-pi/
Run Command
  1. sudo apt-get update
  2. sudo apt-get upgrade -y
  3. sudo apt-get install python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev
  4. sudo useradd -rm homeassistant -G dialout,gpio,i2c
  5. cd /srv
  6. sudo mkdir homeassistant
  7. sudo chown homeassistant:homeassistant homeassistant
  8. sudo -u homeassistant -H -s
  9. cd /srv/homeassistant
  10. python3 -m venv .
  11. source bin/activate
  12. python3 -m pip install wheel
  13. pip3 install homeassistant


hass ใช้เวลาสักพัก ประมาณ 20-30 นาที
ถ้าขึ้น INFO (MainThread) [homeassistant.core] Timer:starting คือเสร็จแล้ว
6. เข้าหน้า Web ตั้งรหัสผ่าน user
http://ipaddress:8123

7. ทำ hass auto service
ทำต่อจากข้อ 8
https://intranet.sci.com/blog.php?u=281&b=1603
เพิ่มเติม
https://www.home-assistant.io/docs/autostart/systemd/
https://community.home-assistant.io/t/unit-home-assistant-homeassistant-service-not-found/28507

8. Confing configuration.yaml
all config file
  1. cd /home/homeassistant/.homeassistant

คำสั่ง restart service
  1. systemctl restart home-assistant@homeassistant

AIQ
สร้างไฟล aqi.sh
#!/bin/sh
#New Key 20200206 348 Day
result=$(curl -s --location --request GET "api.airvisual.com/v2/city?city=Samut%20Sakhon&state=Samut%20Sakhon&country=Thailand&key=XXXXXXXXXXXXXX")
echo $result | jq -r .data.current.pollution.aqius


สมัครฟรี 10000 ครั้ง/เดือน หมดอายุ 348 วัน XXXX คือคีย์ที่ได้จาก Web
https://www.airvisual.com/thailand/bangkok

9. ติดต้ง jq
  1. sudo apt install jq

10. Code sh ยัดค่าใส่ sensor
  1. nano configuration.yaml

เพิ่ม
#AIQ From aiq.sh
sensor:
- platform: command_line
name: AQI
scan_interval: 3600
command: "/home/homeassistant/.homeassistant/aqi.sh"


11. เล่นเพลง MP3
copy mp3 ไปไว้ตามที่ต้องการ
ติดตั้งโปรแกรม
  1. apt-get install omxplayer

ทดลองเล่นด้วยคำสั่ง
  1. omxplayer /home/pi/MP3/Auto_7.55.mp3

ถ้ามี Error
Error: Unable to open font

ให้ติดตั้ง fonts เพิ่ม
  1. apt-get install libpcre3 fonts-freefont-ttf

https://raspberrypi.stackexchange.com/questions/32755/install-omxplayer-on-the-commandline

จากข้อ 11. user อื่น ๆ เล่นได้แต่พอไป Test run จาก หน้า Web Home Assistant จะไม่ได้ ไม่เล่นเพลง
ต้อง Add user homeassistant เข้า Group ด้วย ไม่อย่างนั้น จะ Error เมื่อเรียกจาก homeassistant
  1. usermod -a -G audio homeassistant
  2. usermod -G video homeassistant

แล้ว reboot เครื่อง

ลอง Run ที่ User homeassistant
  1. su - homeassistant
  2. /usr/bin/omxplayer /home/pi/MP3/1.mp3


12. Fix IP Wifi
https://electrondust.com/2017/11/25/setting-raspberry-pi-wifi-static-ip-raspbian-stretch-lite/
  1. nono /etc/dhcpcd.conf

เพิ่มไว้ล่างสุด
interface wlan0
static ip_address=192.168.0.175
static routers=192.168.0.2
static domain_name_servers=8.8.8.8

แล้ว Reboot เครื่อง

13. configuration.yaml
  1. nano configuration.yaml

shell_command:
auto_normal: /usr/bin/omxplayer /home/homeassistant/.homeassistant/MP3/Auto_7.55.mp3
song_national: /usr/bin/omxplayer /home/homeassistant/.homeassistant/MP3/Song_National.mp3
no_act: /usr/bin/omxplayer /home/homeassistant/.homeassistant/MP3/No_Act.mp3
song_enough: /usr/bin/omxplayer /home/homeassistant/.homeassistant/MP3/Song_Enough.mp3
stop_mp3: bash /home/homeassistant/.homeassistant/stop_mp3.sh


14. scrip.yaml
  1. nano scrip.yaml

'1582256882671':
alias: 1. ^{ ^a ^d ^h ^` ^b ^i ^a ^v Manual
sequence:
- service: shell_command.no_act
- service: system_log.write
'1582256923595':
alias: 2. ^` ^~ ^g ^h ^h ^g ^~ ^` ^~ ^g Manual
sequence:
- service: shell_command.song_enough
'1582256950346':
alias: 3. ^` ^~ ^g ^j ^u Manual
sequence:
- service: shell_command.song_national
'1582259558847':
alias: Stop Sound
sequence:
- data: {}
service: shell_command.stop_mp3


15. automations.yaml
  1. nano automations.yaml

- id: '1582084332514'
alias: 1. ^` ^b ^i ^a ^v ^{ ^a ^u ^{ ^a ^w ^a ^y 7:55
description: ^` ^b ^i ^a ^v ^{ ^a ^u ^` ^{ ^t ^` ^~ ^g ^h ^h ^g ^~ ^` ^~ ^g + ^` ^~ ^g ^j ^u
trigger:
- at: '7:54:57'
platform: time
condition: []
action:
- service: shell_command.auto_normal
initial_state: true
- id: '1582106072377'
alias: 2. ^g ^t ^a ^h ^a 7:30, 7:50 ^a ^` ^{ ^t ^` ^~ ^g ^j ^u 8:00
description: ^{ ^a ^g ^t ^a ^h ^a ^a ^` ^{ ^t ^` ^~ ^g ^j ^u 8:00
trigger:
- at: '7:30:00'
platform: time
condition: []
action:
- data: {}
service: shell_command.no_act
- delay: 00:19:45
- service: shell_command.no_act
- delay: 00:09:45
- service: shell_command.song_national
initial_state: false


***** เพิ่มเติม IP Wifi มีปัญหา ****
พบปัญหา Wifi ที่ Config จาก Service dhcpcd มีปัญหา
เครื่องเปิดปกติทำงานปกติ แต่ Wifi ใช้ไม่ได้เข้าไม่ได้

เปลี่ยนวิธี Config ip wifi ใหม่ ใช้
https://raspberrypi.stackexchange.com/questions/37920/how-do-i-set-up-networking-wifi-static-ip-address

  1. nano /etc/network/interfaces

เพิ่ม
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.175
netmask 255.255.255.0
gateway 192.168.0.2
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf


ของ Lan ถ้าต้องการใช้ก็ Fix จากไฟล์นี้เหมือนกัน เช่น
auto eth0
iface eth0 inet static
address 10.1.1.30
netmask 255.255.255.0
gateway 10.1.1.1


แล้วปิด Service dhcpcd ไปให้ไปใช้ network/interfaces แทน
  1. sudo systemctl disable dhcpcd
  2. sudo systemctl enable networking


แล้ว Reboot เครื่อง ก็จะสามารถใช้ IP ที่ Fix ได้

วันอาทิตย์ที่ 2 กุมภาพันธ์ พ.ศ. 2563

Raspberry Pi Headless Setup With WiFi and SSH Enabled

Raspberry Pi Headless Setup With WiFi and SSH Enabled
https://www.gngrninja.com/code/2019/3/10/raspberry-pi-headless-setup-with-wifi-and-ssh-enabled

1. Download
https://www.raspberrypi.org/downloads/raspbian/
2. แตกไฟล์ Burn ใส่ SD ด้วยการ Restore ทับทั้งหมด
3. นำ SD ไปใส่เครื่องให้ Boot ก่อนสักพัก เพื่อให้ทำ Config และ Resize Partition (ถ้าไม่ทำมีการสร้างไฟล์เพิ่มใหม่ใน Boot จะหาย เมื่อนำไป Boot )
4. ปิดเครื่องเอา SD ไปต่อ Linux เปิดใน Disk Boot
5. สร้าง ไฟล์ wpa_supplicant.conf ในไปไว้ใน Boot
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
ap_scan=1
fast_reauth=1
country=JP

network={
ssid="Your network's SSID"
psk="Your network's password/psk"
id_str="0"
priority=100
}


6. สร้างไฟล์ ssh ด้วย text editor ไม่ต้องใส่นามสกุล ไว้ที่ Dive Boot
7. เปลี่ยนสิทธิ์ เป็น 777 ทั้ง 2 ไฟล์
8. นำไป Boot จะต่อ WIFI และ ได้ IP สามารถ SSH ไปได้

วันพฤหัสบดีที่ 2 มกราคม พ.ศ. 2563

Axapta : Axapta Auto Create Batch List By Call Class By Code

Axapta : Axapta Auto Create Batch List By Call Class By Code
สิ่งที่ต้องการ
- ต้องการสร้าง Batch List ให้เรียกใช้ Class ที่สร้างขึ้นเพื่อเรียกรายงานและส่งเมล์
เป็นอาทิตย์ หรือเป็นเดือน หรือตามที่ต้องการโดยไม่ต้องสร้างเองให้ Code สร้างให้
- Run Batch ไว้ที่เครื่อง Database เมื่อถึงเวลา ให้เรียกรายงานและส่ง รายงาน ทาง Email ให้ผู้เกี่ยวข้อง

ทำโดย
1. สร้าง Class Auto Create Batch List ให้เลือกวันที่ ที่ต้องการ ตัวอย่างใน Code ให้ทำเฉพาะวันอาทิตย์ เวลาห้าทุ่ม
2. สร้าง Class ที่จะเรียก Reports และส่งเมล์ (ต้องมี Dialog ด้วยไม่อย่างนั้น Run Batch จะ Error)
นำ Class ID ในข้อ 2 ไปใส่ใน Code Class สร้าง Batch List ข้อ 1

(ปัจจุบันส่งเมล์ได้เฉพาะ Windows XP และ Windows7 Windows10 Run Register Dll ไม่ผ่าน)

ส่ง Mail : https://porpramarn.blogspot.com/2016/07/axapta-send-mail-to-zimbra.html

Project :
https://drive.google.com/file/d/1OWawJRESBEb1Re_yG3IThRB2c6VJvmm1/view?usp=sharing

วันพุธที่ 1 มกราคม พ.ศ. 2563

Window 10 : Ubuntu + Linux Mount Partition Windows10 Read only.

Window 10 : Ubuntu + Linux Mount Partition Windows10 Read only.

เนื่องจากมีการเปิดโหมด
Turn on fast startup ไว้ ต้อง ปิดก่อนถึงจะสามารถนำไป Mount ใน Linux เพิ่มหรือแก้ไขไฟล์ต่าง ๆ ใน Disk ได้

If it happens in case of dual booting with Windows 10, you need to uncheck turn on fast startup in Control Panel --> Power Options --> Choose what the power buttons do and then shutdown, not reboot. Once it's done properly you'll be able to access the NTFS partitions normally with read/write permissions.

This happens due to the Windows 10 update resets it to the default fast startup which is a form of hibernation.
https://askubuntu.com/questions/70281/why-does-my-ntfs-partition-mount-as-read-only

https://www.linuxuprising.com/2019/01/fix-windows-10-or-8-partition-mounted.html

วันเสาร์ที่ 7 ธันวาคม พ.ศ. 2562

Windows Server 2003 : Windows Server 2003 Update To R2

Windows Server 2003 : Windows Server 2003 Update To R2
DC04 ที่ Copy VMware มาจากเครื่อง Intranet Local Join และ ทำ Domain เสร็จแล้ว แต่ตัว Version ไม่ใช่ Windows Server 2003 R2
ซึ่งต้อง Update ในหนังสือหน้า 23-24
ทำดังนี้
- Backup Snapshots ก่อนทำ
- หาแผ่นที่ใช้ลง ถ้าของแท้ให้เอาแผ่น 2 ใส่ แต่ตัวนี้เป็น skz ให้ mout แผ่น windows server 2003 skz เข้าไปเลย
ในแผ่นจะมี Folder Update R2
พบปัญหาเวลากดที่ Link Update แล้ว Error
Windows 2003 Wizard Another
Application requires a restart of this computer. Before Setup can run, you must restart the computer.
วิธีแก้ต้องลบ registry เข้าไปที่
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
แล้วลบ PendingFileRenameOperations ออก ถึงจะลงได้
- ติดตั้งตามขึ้นตอน เสร็จแล้ว Reboot
จะเป็น Windows Server 2003 R2

- ต้องดู Active Directory schema version ต้องเป็น Version เดียวกัน กับตัว Master
WINDOWS EDITION SCHEMA VERSION
Windows 2000 Server : 13
Windows Server 2003 : 30
Windows Server 2003 R2 : 31
Windows Server 2008 : 44
Windows Server 2008 R2 : 47
Windows Server 2012 : 56
Windows Server 2012 R2 - Preview : 69

โดยใช้คำสั่ง
dsquery * cn=schema,cn=configuration,dc=domain,dc=com -scope base -attr objectVersion"

เปลี่ยนชื่อ Domain และ dc ที่ใช้ จะต้องได้ Version เดียวกัน กับตัว Master

31 เป็นตัว Windows Server 2003 R2 ถ้าไม่ได้เป็นคนตัวตัวต้อง Update Active Directory schema version (ในหนังสือหน้า 24)

https://nolabnoparty.com/en/finding-active-directory-schema-version/

วันจันทร์ที่ 2 ธันวาคม พ.ศ. 2562

mysql Error Set Default Date 0000-00-00 ไม่ได้

mysql Error Set Default Date 0000-00-00 ไม่ได้
เนื่องจาก mysql 5.7 ไม่รองรับให้ใส่วันที่ ที่ไม่ถูกต้อง
https://dzone.com/articles/upgrading-to ... strict-mod

วิธีแก้ต้องแก้ โหมด mysql
Select มาดูได้ด้วยคำสั่ง
  1. SELECT @@SESSION.sql_mode;

ค่า Default
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


วิธีแก้ ต้องนำค่า NO_ZERO_IN_DATE,NO_ZERO_DATE ออก
  1. SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'


หรือ ก็ได้
  1. SELECT @@GLOBAL.sql_mode;
  2. SET GLOBAL sql_mode = '...';
 

วันพฤหัสบดีที่ 28 พฤศจิกายน พ.ศ. 2562

Ubuntu : Ubuntu 14.04 Update Vmware Tools แล้ว Error

Ubuntu : Ubuntu 14.04 Update Vmware Tools แล้ว Error
https://intranet.sci.com/blog.php?u=3&b=832

root@webax:/tmp/vmware-tools-distrib# ./vmware-install.pl -d
open-vm-tools packages are available from the OS vendor and VMware recommends
using open-vm-tools packages. See http://kb.vmware.com/kb/2073803 for more
information.
Do you still want to proceed with this installation? [no]
INPUT: [no] default


ต้อง run คำสั่ง
  1. ./vmware-install.pl -f


https://kb.vmware.com/s/article/2107676