หน้าเว็บ

วันอังคารที่ 27 ตุลาคม พ.ศ. 2563

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

 PHP : การนำวันที่ต่อด้วยเวลาปัจจุบัน และการ Set ค่า NULL เข้าDB
รับ Get หรือ Post มาจาก Form วันที่

  1. list($dd, $mm, $yyyy) = explode("/", $_POST["S_FinishDate_Edit"]);
  2. $S_FinishDate_Edit = "'".$yyyy."-".$mm."-".$dd." ".date("h:i:s")."'";   

ตัวแปร $S_FinishDate_Edit ยัดเข้า Database

การ Set ค่า NULL ให้กับวันที่
ประกาศตัวแปรรับค่า NULL สำคัญต้องใส่ "" ด้วย
  1. $S_FinishDate_Edit = "NULL"


SQL String ไม่ต้องใส่ ' ' หรือ " " ถ้าใส่จะ Error เพราะช่องรับค่า NULL เช่น
  1. $SQL .=" `S_SectionDate`=".$S_SectionDate_Edit.",`S_DoneDate`=".$S_DoneDate_Edit.";


ตัวอย่างใน ข้อเสนอแนะตอนแก้ไข
https://intranet.sci.com/sci/suggestion/qp_start.php?YR=2020

Pi : Pi moition camera notification Line Nofity API

 Pi : Pi moition camera notification Line Nofity API
ติดตั้ง motion
https://intranet.sci.com/blog.php?u=281&b=1667

เพิ่มเติม แก้ Motion ให้ไปเรียกใช้งาน ไฟล์ python ที่สร้างขึ้นเมื่อมีการสร้าง Video

  1. nana /etc/motion/motion.conf

แก้ตรง
on_movie_start python3 /home/pi/line.py


Code pyton ส่ง Line
http://intranet.sci.com/blog.php?u=281&b=1809

Code สำเร็จ
  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. import glob
  6. import os
  7. import time
  8.  
  9. LINE_ACCESS_TOKEN = "XXXXXXX"
  10.  
  11. URL_LINE = "https://notify-api.line.me/api/notify"
  12.  
  13. def line_text(message):
  14.     msg = urllib.parse.urlencode({"message":message})
  15.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  16.     session = requests.Session()
  17.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  18.     print(session_post.text)
  19.  
  20. def line_pic(message, path_file):
  21.     file_img = {'imageFile': open(path_file, 'rb')}
  22.     msg = ({'message': message})
  23.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  24.     session = requests.Session()
  25.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  26.     print(session_post.text)
  27.  
  28. list_of_files = glob.glob('/home/pi/Monitor/*.jpg')
  29. latest_file = max(list_of_files, key=os.path.getctime)
  30. #print(latest_file)
  31. text_send = "Motion Detect OD."
  32. line_pic(text_send, latest_file)
  33.  
  34. #//// Delete All File In Folder Monitor ////#
  35. parth = "/home/pi/Monitor/"
  36. for i in os.listdir ( parth ):
  37.     os.remove(parth+i)

ส่งข้อความเข้า Line Bot ด้วย Sell Script ส่งหา UID ของแต่ละ User ทีละหลาย ๆ User

 ส่งข้อความเข้า Line Bot ด้วย Sell Script ส่งหา UID ของแต่ละ User ทีละหลาย ๆ User
XXX : Token Line Bot
UID = User ID Line
Code

  1. #!/bin/sh
  2. curl -v -X POST https://api.line.me/v2/bot/message/multicast \
  3. -H 'Content-Type: application/json' \
  4. -H 'Authorization: Bearer {XXX}' \
  5. -d '{
  6.     "to": ["UID","UID2","UID2"],
  7.     "messages":[
  8.         {
  9.             "type":"text",
  10.             "text":"Hello, world1"
  11.         },
  12.         {
  13.             "type":"text",
  14.             "text":"Hello, world2"
  15.         }
  16.     ]
  17. }'

Line : Python ส่งรูปเข้า Line API

 Line : Python ส่งรูปเข้า Line API
โปรแกรมที่ต้องใช้ ในเครื่อง rasberry pi
- python 3 ขึ้นไป
- ติดตั้ง

  1. pip install requests

- ติดตั้ง pip
  1. wget "https://bootstrap.pypa.io/get-pip.py"
  2. sudo python get-pip.py


1. เปิดใช้งาน Token ที่ https://notify-bot.line.me/
สามารถทำเป็น User หรือ ทำเป็น Group ก็ได้

*** สำคัญต้องเอา LINE Notify เข้าไปใน Group ด้วย ถึงจะส่งข้อความได้ ***

2. สร้าง Code python line.py
XXXX คือ Token ที่ได้จากข้อ 1.
Code
  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. LINE_ACCESS_TOKEN = "XXXX" #Use Token Or Group Token https://notify-bot.line.me/
  6.  
  7. URL_LINE = "https://notify-api.line.me/api/notify"
  8.  
  9. def line_text(message):
  10.     msg = urllib.parse.urlencode({"message":message})
  11.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  12.     session = requests.Session()
  13.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  14.     print(session_post.text)
  15.  
  16. def line_pic(message, path_file):
  17.     file_img = {'imageFile': open(path_file, 'rb')}
  18.     msg = ({'message': message})
  19.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  20.     session = requests.Session()
  21.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  22.     print(session_post.text)
  23.  
  24. if __name__ == "__main__":
  25.     if len(sys.argv) < 3:
  26.         # <Linux>
  27.         # python line.py "Test"
  28.         line_text(sys.argv[1])
  29.     else:
  30.         # <Linux>
  31.         # python line.py "Test" "/home/pi/test.jpg"
  32.         line_pic(sys.argv[1], sys.argv[2])


3. ทดลองส่งข้อความ
  1. python3 line_group.py "พบการเคลื่อนไหว"

จะมีข้อความแจ้ง
{"status":200,"message":"ok"}

และมีข้อความส่งไป Line

4. ส่งรูปใช้คำสั่ง
  1. python3 line.py "พบการเคลื่อนไหว" "/home/pi/3923-7.jpg"


ส่วนตัว Line Bot จะส่งได้เฉพาะรูปที่ผ่าน Link และต้องเป็น https เมื่อรูปถูกลบหรือเปลี่ยนชื่อ Line จะไม่สามารถแสดงผลรูป
ข้อจำกับ Line notify ส่งได้เดือนละ 1000 ครั้ง
https://notify-bot.line.me/doc/en/

ตัวอย่าง
https://maker.goisgo.net/raspberry-pi-w ... ne-notice/
https://medium.com/@dome.soda125/%E0%B8 ... 8ce98f0bd6
https://medium.com/dolab/blog-7-line-no ... 9724796428
https://engineering.linecorp.com/en/blo ... ad-images/

วันจันทร์ที่ 28 กันยายน พ.ศ. 2563

Axapta 2009 : Split, Export แบ่งคำด้วย String

 Axapta 2009 : Split, Export แบ่งคำด้วย String

  1. static void Job1(Args _args)
  2. {
  3.     str paramAsStr = "Value 1|Value 2|Value 3";
  4.     container paramAsCon;
  5.     int i;
  6.  
  7.     paramAsCon = str2con(paramAsStr, "|");
  8.    
  9.     for (i=1;i<=conLen(paramAsCon);i++)
  10.     {
  11.         info(conPeek(paramAsCon, i));    
  12.     }
  13. }


ส่วน Version 2012 เป็นต้นมามี Function strSplit
  1. static void Job1(Args _args)
  2. {
  3.     str paramAsStr = "Value 1|Value 2|Value 3";
  4.     List paramAsList;
  5.     ListEnumerator le;
  6.  
  7.     paramAsList = strSplit(paramAsStr, "|");
  8.    
  9.     le = paramAsList.getEnumerator();
  10.     while(le.moveNext())
  11.     {
  12.         info(le.current());    
  13.     }
  14. }

https://www.schweda.net/blog_ax.php?bid=628&wdl=en

Pi : Pi moition camera notification Line Nofity API

 Pi : Pi moition camera notification Line Nofity API
ติดตั้ง motion
https://porpramarn.blogspot.com/2019/02/pi-pi-camera-motion.html

เพิ่มเติม แก้ Motion ให้ไปเรียกใช้งาน ไฟล์ python ที่สร้างขึ้นเมื่อมีการสร้าง Video

  1. nana /etc/motion/motion.conf
แก้ตรง
on_movie_start python3 /home/pi/line.py


Code python ส่ง Line
https://porpramarn.blogspot.com/2020/09/line-python-line-api-notify.html

Code สำเร็จ

  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. import glob
  6. import os
  7. import time
  8.  
  9. LINE_ACCESS_TOKEN = "XXXXXXX"
  10.  
  11. URL_LINE = "https://notify-api.line.me/api/notify"
  12.  
  13. def line_text(message):
  14.     msg = urllib.parse.urlencode({"message":message})
  15.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  16.     session = requests.Session()
  17.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  18.     print(session_post.text)
  19.  
  20. def line_pic(message, path_file):
  21.     file_img = {'imageFile': open(path_file, 'rb')}
  22.     msg = ({'message': message})
  23.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  24.     session = requests.Session()
  25.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  26.     print(session_post.text)
  27.  
  28. list_of_files = glob.glob('/home/pi/Monitor/*.jpg')
  29. latest_file = max(list_of_files, key=os.path.getctime)
  30. #print(latest_file)
  31. text_send = "Motion Detect OD."
  32. line_pic(text_send, latest_file)
  33.  
  34. #//// Delete All File In Folder Monitor ////#
  35. parth = "/home/pi/Monitor/"
  36. for i in os.listdir ( parth ):
  37.     os.remove(parth+i)

Line : Python ส่งรูปเข้า Line API Notify

 Line : Python ส่งรูปเข้า Line API Notify
โปรแกรมที่ต้องใช้ ในเครื่อง rasberry pi
- python 3 ขึ้นไป
- ติดตั้ง

  1. pip install requests

- ติดตั้ง pip
  1. wget "https://bootstrap.pypa.io/get-pip.py"
  2. sudo python get-pip.py


1. เปิดใช้งาน Token ที่ https://notify-bot.line.me/
สามารถทำเป็น User หรือ ทำเป็น Group ก็ได้

2. สร้าง Code python line.py
XXXX คือ Token ที่ได้จากข้อ 1.
Code
  1. import requests, json
  2. import urllib.parse
  3. import sys
  4.  
  5. LINE_ACCESS_TOKEN = "XXXX" #Use Token Or Group Token https://notify-bot.line.me/
  6.  
  7. URL_LINE = "https://notify-api.line.me/api/notify"
  8.  
  9. def line_text(message):
  10.     msg = urllib.parse.urlencode({"message":message})
  11.     LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  12.     session = requests.Session()
  13.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, data=msg)
  14.     print(session_post.text)
  15.  
  16. def line_pic(message, path_file):
  17.     file_img = {'imageFile': open(path_file, 'rb')}
  18.     msg = ({'message': message})
  19.     LINE_HEADERS = {"Authorization":"Bearer "+LINE_ACCESS_TOKEN}
  20.     session = requests.Session()
  21.     session_post = session.post(URL_LINE, headers=LINE_HEADERS, files=file_img, data=msg)
  22.     print(session_post.text)
  23.  
  24. if __name__ == "__main__":
  25.     if len(sys.argv) < 3:
  26.         # <Linux>
  27.         # python line.py "Test"
  28.         line_text(sys.argv[1])
  29.     else:
  30.         # <Linux>
  31.         # python line.py "Test" "/home/pi/test.jpg"
  32.         line_pic(sys.argv[1], sys.argv[2])


3. ทดลองส่งข้อความ
  1. python3 line_group.py "พบการเคลื่อนไหว"

จะมีข้อความแจ้ง
{"status":200,"message":"ok"}

และมีข้อความส่งไป Line

4. ส่งรูปใช้คำสั่ง
  1. python3 line.py "พบการเคลื่อนไหว" "/home/pi/3923-7.jpg"


ส่วนตัว Line Bot จะส่งได้เฉพาะรูปที่ผ่าน Link และต้องเป็น https เมื่อรูปถูกลบหรือเปลี่ยนชื่อ Line จะไม่สามารถแสดงผลรูป
ข้อจำกับ Line notify ส่งได้เดือนละ 1000 ครั้ง
https://notify-bot.line.me/doc/en/

ตัวอย่าง
https://maker.goisgo.net/raspberry-pi-webcam-cctv-line-notice/
https://medium.com/@dome.soda125/%E0%B8%A1%E0%B8%B2%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87-line-notification-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-python-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B9%80%E0%B8%96%E0%B8%AD%E0%B8%B0-ab8ce98f0bd6
https://medium.com/dolab/blog-7-line-notify-with-python-8c9724796428
https://engineering.linecorp.com/en/blog/using-line-notify-to-send-stickers-and-upload-images/

 

วันจันทร์ที่ 24 สิงหาคม พ.ศ. 2563

Axapta : การ Adjust มูลค่าของที่ Onhand เป็น 0 สามารถทำได้

 Axapta : การ Adjust มูลค่าของที่ Onhand เป็น 0 สามารถทำได้
แต่ก่อนเข้าใจว่าถ้ายอดเป็น 0 แล้วมีการ Adjust + Recall จะทำให้รายงาน Inventory ไม่มียอด Onhand แต่จะมีมูลค่า

หลังจากได้ทดลองอีกครั้ง พบว่า สามารถทำได้ เช่น 154360121003
1. หายอด Onhand ที่มียอด เป็น 0 เรียกรายงาน Inventory ไม่มียอดและมูลค่า


2. ทำการ Adjust ต้นทุนเข้าไป และเรียกรายงาน Invent จะพบมียอดเงินแต่ไม่มีของตามรูป
3. ทำการ Recalculation พบว่ามูลค่าที่ค้างอยู่หายไป
และต้นทุน Code อื่น ๆ ที่นำ Item นี้ไปใช้ ก่อน Recalculation


หลัง Call ต้นทุนที่นำ Parts ที่ Adjust ไปใช้ก็จะเปลี่ยนไป

สรุปคือ สามารถทำได้ การที่รายงาน Inventory ไม่มีของแต่มีมูลค่าอาจจะมาจากสาเหตุอื่น

วันพุธที่ 19 สิงหาคม พ.ศ. 2563

การ Update Firmware ของเครื่อง Ubiquiti loco m5 (กรณีเครื่องสามารถออก Internet ได้)

 การ Update Firmware ของเครื่อง Ubiquiti loco m5 (กรณีเครื่องสามารถออก Internet ได้)
ให้ทำเครื่อง Station ก่อน แล้วค่อยทำเครื่อง AP เพราะจะหลุดเพื่อเข้าไม่ได้
1. เข้า Menu SYSTEM ดู Version เก่า แล้วกด Check Now


2. ที่มุมขวาล่างถ้ามี Version ใหม่จะมีขึ้นมาให้กด Update

ถ้าเป็น Version ล่าสุดแล้วจะขึ้นเป็น Last Version

 
3. รอจนกว่าจะ Download เสร็จใช้เวลาไม่นาน



4. กด agree


5. กด Update อีกครั้ง

6. รอจนกว่าจะเสร็จระหว่างนั้นห้ามปิดเครื่อง

7. รอจนกว่าจะเสร็จแล้วเครื่องจะ Reboot

8. เมื่อเสร็จ Login อีกครั้ง ตัว Version ก็จะเปลี่ยนไป

วันจันทร์ที่ 3 สิงหาคม พ.ศ. 2563

Axapta : Axapta Sales Order Invoice ไปแล้วถูกลบ Line Status จะเปลี่ยนจาก Invoice เป็น Open

Axapta : Axapta Sales Order Invoice ไปแล้วถูกลบ Line Status จะเปลี่ยนจาก Invoice เป็น Open
เช่น SO20-221 ฝบง. Post Invoice ไปแล้ว แต่มีการลบและแก้ไข Line ใหม่ ทำให้ Status ของ Sales Order เปลี่ยน แต่ Transaction เกิดไปแล้ว
ใช้วิธี Reinsert จาก Database Logs ไม่ได้ Error Lot ID is not specified.


วิธีแก้
1. ให้ งสข. ใส่ Item ที่ลบไปและข้อมูลใน Line เหมือนเดิม
2. ลอกข้อมูลจาก Database จาก Local ที่จะต้องแก้มี
SalesLine, SalesTable แก้ข้อมูลเหมือนเหมือนกับ Local (จด InventTransID ไว้ด้วยสำหรับไปลบ Transaction ออก)
3. ลบ ข้อมูลใน Table Inventtrans ออก ใช้ TransId จากข้อ 2.
4. Run Job recalcInventSum เพื่อให้ Update Onhand จำนวนจะได้ถูกต้อง

วันอังคารที่ 14 กรกฎาคม พ.ศ. 2563

FreeNas : FreeNas SMB Ldap Login Shared Samba

FreeNas : FreeNas SMB Ldap Login Shared Samba
ตั้งค่า
1. Storage --> Pool สร้าง HOME
2. Directory Services ตั้งค่า AD
2.1. Active Directory
2.2. LDAP

2.3. Kerberos Realms


3. Sharing --> Windows Shares (SMB) ตั้งค่า Folder Shared จาก Home ที่สร้างไว้ในข้อ 1


4. Services --> SMB Stop แล้ว Start ใหม่

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

Axapta : Error Post PO Invoice ไม่ผ่าน

Axapta : Error Post PO Invoice ไม่ผ่าน
Error
Summary account for vendor account in posting profile default does no exist.

เกิดจาก
ร้านสร้างขึ้นมาให้เลือก Group ที่ไม่มี Default Profile ทำให้ Error ดังกว่า
ที่ Vendor
ที่ PO Go to main ที่ Default Profile จะมี Group ที่เลือกใน Vendor

ต้องให้ทาง บัญชี Group ที่ Profile ไม่มีให้ แล้วค่อย Post PO

Datacenter ขยาย Partition Disk ได้แค่ 2 TB

Datacenter ขยาย Partition Disk ได้แค่ 2 TB
นำ Disk ไปขยาย Partition แล้ว Error ขยายไม่ได้
libparted messages (ERROR)
partition length of เลขขนาดที่ต้องการขยาย sectors exceeds the msdos-partition-table-imposed maximum of เลขขนาดที่ Disk รับได้

เนื่องจาก Disk ของ Datacenter เป็น ชนิด MBR จึงได้ขนาดสูงสุดแค่ 2 TB ทำให้เกิด Error ดังกล่าว
วิธีเช็คว่า Disk เป็น MBR หรือ GPT
1. ติดตั้ง gdisk
  1. apt-get install gdisk

2. ใช้คำสั่ง
gdisk -l /dev/XXX dev ที่ต้องการ เช่น
  1. gdisk -l /dev/sdc

VMware : VMware ไม่ Boot เข้า CD

VMware : VMware ไม่ Boot เข้า CD
เกิดจากการเพิ่ม Disk แล้ว Bios ของ VM Set ให้ Boot เข้า Disk ก่อน ทำให้ไม่ Boot CD

วิธีแก้

1. Edit VMware ที่ไม่ Boot เข้า CD
ที่ Tab VM Options ทำเครื่องหมายถูกที่ Force BIOS Setup ตามรูป เพื่อให้ Boot เข้า Bios
2. ตั้งค่า Bios ให้ Boot จาก CD ก่อน แล้ว Save




เครื่องก็จะ Boot เข้า CD

วันเสาร์ที่ 4 กรกฎาคม พ.ศ. 2563

โปรแกรม MasterTime มีปัญหา ขึ้นวันที่ ซ้ำกัน

โปรแกรม MasterTime มีปัญหา ขึ้นวันที่ ซ้ำกัน ปกติรหัสหนึ่งคนใน 1 วันจะขึ้นแค่วันเดียว
แต่พบปัญหาขึ้นวันเดียวกัน 2 วัน ทำให้ข้อมูลไม่ถูกต้อง
ลบในตัวโปรแกรมไม่มีที่ลบ จึงต้องทำ VB ที่ Connect ผ่าน ODBC เข้าไปลบข้อมูลในฐานข้อมูลชื่อ _daily
วิธีแก้
1. Backup ข้อมูลก่อนทำ ปิดโปรแกรม MasterTime เพื่อไม่ให้ Lock Database
2. Run Program MT ที่เขียนขึ้น เข้า Tab ลบข้อมูลผิด ใส่รหัสพนักงาน ใส่วันที่ที่มีข้อมูลผิด กด ลบข้อมูล
3. กด OK
4. ลบแล้วแต่ไฟล์ Database ข้อมูลยังมีอยู่ วิธีแก้ต้องซ่อม Database ในตัวโปรแกรม MasterTime ก่อน ข้อมูลจึงจะถูกลบจริง
ซ่อมเฉพาะ _daily ก็ได้
5. ใช้ไฟล์ Text เดิมหลอกเพิ่มวันที่ และรหัสพนักงานที่ต้องการ แล้วคีย์ข้อมูลใหม่
Code ลบ
  1.        If EmpID.TextLength <> 5 Then
  2.             MessageBox.Show("รหัสพนักงานไม่ถูกต้อง !")
  3.         Else
  4.             myConnection.ConnectionString = ConnectionString
  5.             myConnection.Open()
  6.             myCommand.Connection = myConnection
  7.  
  8.             'ConnectionString = "Provider=Microsoft.Jet.odbc.4.0;" & "Data Source=C:\MasterTech\mastertime;Extended Properties=dBase IV"
  9.             ConnectionString = "dsn=MT"
  10.             Console.WriteLine("Connecting...")
  11.  
  12.             DBaseConnection = New System.Data.Odbc.OdbcConnection(ConnectionString)
  13.             DBaseConnection.Open()
  14.  
  15.             Dim WorkDay As String = DateTimePickerDel.Value.ToString("yyyy'/'MM'/'dd")
  16.             Dim DBaseCommand As System.Data.Odbc.OdbcCommand
  17.             'Dim DBaseDataReader As System.Data.Odbc.OdbcDataReader
  18.  
  19.             SQL = "DELETE FROM _daily WHERE ID_CARD ='" & EmpID.Text & "' AND WORKDAY = #" & WorkDay & "#"
  20.             'SQL = "DELETE FROM _daily WHERE ID_CARD ='" & EmpID.Text & "' AND WORKDAY LIKE #" & WorkDay & "%#"
  21.  
  22.             'SQL = "SELECT ID_CARD, WORKDAY FROM _daily  WHERE ID_CARD ='" & EmpID.Text & "' AND WORKDAY = #" & WorkDay & "#"
  23.             'SQL = "SELECT ID_CARD, WORKDAY FROM _daily WHERE ID_CARD ='" & EmpID.Text & "'"
  24.             Console.WriteLine(SQL)
  25.             DBaseCommand = New System.Data.Odbc.OdbcCommand(SQL, DBaseConnection)
  26.             'DBaseDataReader = DBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)
  27.  
  28.             'While DBaseDataReader.Read()
  29.             '    Console.WriteLine(String.Format("{0}, {1}", _
  30.             '    DBaseDataReader(0), DBaseDataReader(1)))
  31.             'End While
  32.  
  33.             DBaseCommand.ExecuteNonQuery()
  34.             myConnection.Close()
  35.             MessageBox.Show("ลบข้อมูลสำเร็จ")
  36.             Environment.Exit(0)
  37.         End If

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

Axapta : รายงาน Invent ไม่มีของแต่มียอดเงินเหลือ 0.01 Item 553015614025-T

Axapta : รายงาน Invent ไม่มีของแต่มียอดเงินเหลือ 0.01 Item 553015614025-T
จากการตรวจสอบพบ
มีรายการที่โอนออกขายแล้วมูลค่าไม่เท่ากับที่โอนมา
ยอดพึ่งมาให้เห็นปัจจุบันเนื่องจากของที่ FINI-CN หมดเลยพึ่งแสดงให้เห็น ว่าไม่มีของแต่มียอด 0.01
เป็นแบบนี้ไม่สามารถ Adjust โดย Transaction ปกติได้ เพราะเป็นยอดนานมาแล้ว และไม่มี Onhand รวมทั้งปิด Inventory ไปแล้ว

วิธีแก้คือต้องแก้ Transaction
1. ใช้ SQL Enterprise Manager Select ข้อมูลที่เกี่ยวข้องเพื่อแก้ไข ใช้ Item กับ InventDimID ในการหา
  1. SELECT     *
  2. FROM         INVENTTRANS
  3. WHERE     (ITEMID = '553015614025-T') AND (INVENTDIMID LIKE '%18-00077784')

2. แก้ข้อมูล Transaction ที่ไม่ถูกต้อง ที่ช่อง COSTAMOUNTADJUSTMENT และช่อง COSTAMOUNTSETTLED
จะเห็นว่ามีค่า .01 และอีกช่องเป็น -6872.15 ตามรูป
ซึ่งที่ถูกต้องควรจะเป็น ช่อง COSTAMOUNTADJUSTMENT เป็น 0 ช่อง COSTAMOUNTSETTLED เป็น -6872.15
ตามที่ยอดโอนมา จึงจะทำให้ไม่มียอดค้าง แก้ตามรูป
3. Run Code Job recalcInventSum หรือ Run Recalculation ก็ได้
  1. static void recalcInventSum(Args _args)
  2. {
  3.     ItemId                  myItemId = "553015614025-T";
  4.     InventSumRecalcItem     inventSumRecalcItem;
  5.     ;
  6.  
  7.     inventSumRecalcItem = new InventSumRecalcItem(myItemId, true, CheckFix::Fix);
  8.     inventSumRecalcItem.updatenow();
  9. }

4. จะปีการปรับปรุ่ง Inventsum ให้ถูกต้อง
5. ทดลองเรียกรายงาน Invent ยอดก็จะไม่มี

PO Post Invoice ไม่ได้ Error

PO Post Invoice ไม่ได้ Error เช่น PO20-05374 : 901228012000
Transaction is financially closed and may not be split.
You may not split mor then what is financially open.

เกิดจาก PO ทำรับมาแล้ว แต่จะทำติดลบออกเพราะ มีการเปลี่ยนแปลง Invoice และ PO ใหม่
แต่ทำไม่ได้ เพราะมีการทำ TAW01 เปลี่ยน Batch ให้เป็น 191128 แต่ใน Item --> Functions --> Edit Dimensions ยังเป็น Batch เดิม
ต้องแก้ Batch ให้เป็น Batch ที่จะใช้ ให้เหมือนกันตาม Onhand ที่เหลืออยู่
เดิมเป็น 191017 และ 191024 แก้เป็น 191128 ตามรูป
แล้วค่อยให้ งคส. ทดลองทำรับใหม่อีกครั้ง

วันพฤหัสบดีที่ 25 มิถุนายน พ.ศ. 2563

Ubuntu : Ubuntu resolv.conf nameserver เปลี่ยน

Ubuntu : Ubuntu resolv.conf nameserver เปลี่ยน ทำให้ออกเน็ตไม่ได้
ค่าเดิม
nameserver 127.0.0.53

วิธีแก้
# Use Google's public DNS servers.
nameserver 8.8.4.4
nameserver 8.8.8.8


But things change and now it’s not that simple. If you now edit /etc/resolv.conf on Ubuntu you’ll find that the edits are ephemeral. If you restart (or even hibernate) your machine then they’ll be overwritten by default content.

nameserver 127.0.0.53
search Home


This is pretty simple to fix though.
1.Install the resolvconf package.
  1. sudo apt install resolvconf


2. Edit /etc/resolvconf/resolv.conf.d/head and add the following:
  1. # Make edits to /etc/resolvconf/resolv.conf.d/head.
  2. nameserver 8.8.4.4
  3. nameserver 8.8.8.8


3. Restart the resolvconf service.
  1. /etc/init.d/resolvconf restart

Fix should be permanent.
https://datawookie.netlify.app/blog/2018/10/dns-on-ubuntu-18.04/

สร้าง QR Code ด้วย Google API

สร้าง QR Code ด้วย Google API
https://developers.google.com/chart/infographics/docs/qr_codes

Code ตัวอย่าง
$Action คือค่าข้อมูลที่เราต้องการส่งไป ตอน Save ข้อมูล จะได้ QR Code มา เมื่ออ่าน QR Code ก็จะไปทำงานใน File ตาม Link ที่กำหนด และส่งตัวแปรไปด้วย
  1. <?php
  2.     $Link = "https://intranet.scivalve.com/sci/QRCode/qr_save.php?ACTION=".$Action."&chld=L|0";
  3.     //$Link = "https://intranet.sci.com/sci/QRCode/qr_get.php?ACTION=1,3842-7,2020-06-25";
  4.     $qr = "<img src='https://chart.googleapis.com/chart?cht=qr&chs=300x300&chl=$Link' alt=''>";
  5.     echo $qr;
  6. ?>

อธิบาย Parameter ที่ส่งค่าไป
cht=qr ต้องระบุเป็น qr
chs=<width>x<height> ขนาด กว้าง x สูง ไม่ต้องใส่หน่วยใส่แค่ตัวเลข
chl=<data> ข้อความหรือ URL ที่เราต้องการทำ QR Code

Parameter เพิ่มเติม
choe=<output_encoding> การเข้ารหัสค่าเดิมเป็น UTF-8
chld=<error_correction_level>|<margin> ระดับความคลาดเคลื่อนค่าเดิมอยู่ที่ 7 %

วันอังคารที่ 23 มิถุนายน พ.ศ. 2563

Squid Error : tcp logger buffer overflowed

Squid Error : tcp logger buffer overflowed
ทำให้ใช้งานไปสักพักมีข้อความถามรหัส proxy ขึ้นมาอีก

ใช้คำสั่ง
/etc/init.d/squid status
Jun 23 13:11:58 proxy squid[969]: Squid Parent: (squid-1) process 31962 started
Jun 23 13:13:04 proxy (squid-1)[31962]: tcp logger buffer overflowed
Jun 23 13:13:04 proxy squid[969]: Squid Parent: (squid-1) process 31962 exited with status 1
Jun 23 13:13:07 proxy squid[969]: Squid Parent: (squid-1) process 32384 started
Jun 23 13:14:11 proxy (squid-1)[32384]: tcp logger buffer overflowed
Jun 23 13:14:11 proxy squid[969]: Squid Parent: (squid-1) process 32384 exited with status 1
Jun 23 13:14:14 proxy squid[969]: Squid Parent: (squid-1) process 311 started
Jun 23 13:15:03 proxy (squid-1)[311]: tcp logger buffer overflowed
Jun 23 13:15:03 proxy squid[969]: Squid Parent: (squid-1) process 311 exited with status 1
Jun 23 13:15:06 proxy squid[969]: Squid Parent: (squid-1) process 763 started

เกิดจากตัว squid ส่ง log ไปเก็บที่เครื่อง log server ไม่ได้
ตรวจสอบที่เครื่อง log server มีการย้าย Folder เก็บข้อมูลใหม่
พบว่า driver lan เปลี่ยนชื่อไป จาก eth3 เป็น eth4 ทำให้ เครื่อง log ไม่ได้ ip แก้ไขใหม่ reboot ใช้งานได้

ทดลองแก้ squid ไม่ให้ส่งไป ที่เครื่อง 192.168.2.108 ก็จะไม่มี error Mark ไว้ เมื่อ server log ใช้งานได้ตามปกติก็แก้คืนเอา Mark ออก
#Sent To Log Server.
logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
access_log tcp:192.168.2.108:514 squid

วันพุธที่ 17 มิถุนายน พ.ศ. 2563

Linux Mint แก้ปัญหา Add Printer Auto ใน Network

Linux Mint แก้ปัญหา Add Printer Auto ใน Network
เมื่อต่อ Network แล้วเข้า printer ตัว Printer ที่อยู่ใน Network จะ Add เข้ามา Auto บางตัวไม่ได้ใช้
ลบออกแล้วก็ยัง Add เข้ามาใหม่

แก้โดย
  1. nano /etc/cups/cups-browsed.conf

Uncomment
CreateIPPPrinterQueues LocalOnly

  1. /etc/init.d/cups restart


ก็จะเหลือเฉพาะ Printer ที่เรา Add ไว้

https://forums.linuxmint.com/viewtopic.php?t=277091

วันพฤหัสบดีที่ 11 มิถุนายน พ.ศ. 2563

PI : Pi zero ตรวจวัดความร้อนและวัดการสั่น

PI : Pi zero ตรวจวัดความร้อนและวัดการสั่น
1. ติดตั้ง PI และ Set Headless
https://intranet.sci.com/blog.php?u=281&b=1770
boot เข้า Pi update upgrade set ntp

2. Fix ip wifi for pi zero
  1. nano /etc/dhcpcd.conf

Add
interface wlan0
static ip_address=192.168.0.164/24
static routers=192.168.0.2
static domain_name_servers=192.168.0.2 8.8.8.8

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


การต่อวัดอุณหภูมิ mlx90614
1. วัดอุณหภูมิ mlx90614 4 ขา ใช้ ไฟ 5V GNC SCL SDA

2. เปิดโหมด I2C
  1. raspi-config


http://domoticx.com/raspberry-pi-i2c-bus-gebruiken/
3. เปิดดูไฟล์ Boot config ว่า
  1. nano /boot/config.txt

ถูกเปิดแล้วหรือยัง
dtparam=i2c_arm=on
dtparam=spi=on

4. Download
https://github.com/mcauser/micropython-mlx90614
micropython-mlx90614-master(1).zip
(55.74 KB) Not downloaded yet

5. ติดตั้ง Uzip และแตกไฟล์
  1. apt-get install unzip

6. เข้าไปใน Folder ที่แตกได้ ติดตั้งโปรแกรม
  1. python setup.py install

7. เขียน Code
  1. nano Tmp_Sensor.py
  1. import smbus
  2.  
  3. class MLX90614():
  4.  
  5.     MLX90614_RAWIR1=0x04
  6.     MLX90614_RAWIR2=0x05
  7.     MLX90614_TA=0x06
  8.     MLX90614_TOBJ1=0x07
  9.     MLX90614_TOBJ2=0x08
  10.  
  11.     MLX90614_TOMAX=0x20
  12.     MLX90614_TOMIN=0x21
  13.     MLX90614_PWMCTRL=0x22
  14.     MLX90614_TARANGE=0x23
  15.     MLX90614_EMISS=0x24
  16.     MLX90614_CONFIG=0x25
  17.     MLX90614_ADDR=0x0E
  18.     MLX90614_ID1=0x3C
  19.     MLX90614_ID2=0x3D
  20.     MLX90614_ID3=0x3E
  21.     MLX90614_ID4=0x3F
  22.  
  23.     def __init__(self, address=0x5a, bus_num=1):
  24.         self.bus_num = bus_num
  25.         self.address = address
  26.         self.bus = smbus.SMBus(bus=bus_num)
  27.  
  28.     def read_reg(self, reg_addr):
  29.         return self.bus.read_word_data(self.address, reg_addr)
  30.  
  31.     def data_to_temp(self, data):
  32.         temp = (data*0.02) - 273.15
  33.         return temp
  34.  
  35.     #def get_amb_temp(self):
  36.     #    data = self.read_reg(self.MLX90614_TA)
  37.     #    return self.data_to_temp(data)
  38.  
  39.     def get_obj_temp(self):
  40.         data = self.read_reg(self.MLX90614_TOBJ1)
  41.         return self.data_to_temp(data)
  42.  
  43. if __name__ == "__main__":
  44.     sensor = MLX90614()
  45.     #print(sensor.get_amb_temp())
  46.     print(sensor.get_obj_temp())


http://domoticx.com/raspberry-pi-thermometer-ir-contactloos-mlx90614/

8. Test Run
  1. python Tmp_Sensor.py

9. จะได้ค่าอุณหภูมิ ของความร้อนที่ยิง
root@pi200:/home/pi# python Temp_Sensor.py
32.25
root@pi200:/home/pi# python Temp_Sensor.py
31.69
root@pi200:/home/pi#


การต่อตัววัดการสั่น 801S

1. การต่อ ตัววัดการสั่น 801S ตัว PI รับค่าได้เฉพาะ Digital ถ้าต้องการให้ได้รับค่า Analog ตัวใช้ตัวแปลงค่า
MCP3008
https://www.arduinoall.com/product/984/mcp3008-8-channel-10-bit-adc-with-spi-interface
การต่อเข้า PI
ไฟ 3.3V
GND
Aout
ต่อ PI และ MCP3008

2. เขียน Code
  1. nano Vibration_Sensor.py  

Code
  1. # Simple example of reading the MCP3008 analog input channels and printing
  2. # them all out.
  3. # Author: Tony DiCola
  4. # License: Public Domain
  5. import time
  6. import datetime
  7.  
  8. # Import SPI library (for hardware SPI) and MCP3008 library.
  9. import Adafruit_GPIO.SPI as SPI
  10. import Adafruit_MCP3008
  11.  
  12. # Software SPI configuration:
  13. ## GPIO ##
  14. CLK  = 11
  15. MISO = 9
  16. MOSI = 10
  17. CS   = 8
  18.  
  19. ## PIN ##
  20. #CLK  = 23
  21. #MISO = 21
  22. #MOSI = 19
  23. #CS   = 24
  24.  
  25. mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
  26. print(datetime.datetime.now())
  27. # Hardware SPI configuration:
  28. # SPI_PORT   = 0
  29. # SPI_DEVICE = 0
  30. # mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
  31.  
  32. print('Reading MCP3008 values, press Ctrl-C to quit...')
  33. # Print nice channel column headers.
  34. #print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
  35. #print('{6:>4}|{7:>4}'.format(*range(8)))
  36. print('{7:>4}'.format(*range(8)))
  37. print('-' * 57)
  38. # Main program loop.
  39. while True:
  40.     # Read all the ADC channel values in a list.
  41.     values = [0]*8
  42.     for i in range(8):
  43.         # The read_adc function will get the value of the specified channel (0-7).
  44.         values[i] = mcp.read_adc(i)
  45.     # Print the ADC values.
  46.     print('{7:>4}'.format(*values))
  47.     #print('{6:>4}|{7:>4}'.format(*values))
  48.     #print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
  49.     # Pause for half a second.
  50.     time.sleep(1)


***สำคัญ SPI ใช้ GPIO ไม่ได้ใช่ PIN *** จะไม่ได้ค่า
https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008
3. Test Run คำสั่ง จะได้ค่า ตัวเลข
python Vibration_Sensor.py
2020-05-21 18:37:18.288545
Reading MCP3008 values, press Ctrl-C to quit...
7
---------------------------------------------------------
0
1023
31
896
1023

////##########################////
Code สำเร็จที่ใช้ Run ทั้งวัดการสั่นและความร้อน
  1. # Simple example of reading the MCP3008 analog input channels and printing
  2. # them all out.
  3. # Author: Tony DiCola
  4. # License: Public Domain
  5. # Vibration 801S
  6. import time
  7. import datetime
  8. # Import SPI library (for hardware SPI) and MCP3008 library.
  9. import Adafruit_GPIO.SPI as SPI
  10. import Adafruit_MCP3008
  11.  
  12. # Tmp Sensor
  13. import smbus
  14.  
  15. # Vibration 801S
  16. # Software SPI configuration:
  17. ## GPIO ##
  18. CLK  = 11
  19. MISO = 9
  20. MOSI = 10
  21. CS   = 8
  22.  
  23. ## PIN ##
  24. #CLK  = 23
  25. #MISO = 21
  26. #MOSI = 19
  27. #CS   = 24
  28.  
  29. mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
  30. print(datetime.datetime.now())
  31. # Hardware SPI configuration:
  32. # SPI_PORT   = 0
  33. # SPI_DEVICE = 0
  34. # mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
  35. #print('Reading MCP3008 values, press Ctrl-C to quit...')
  36. # Print nice channel column headers.
  37. #print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*range(8)))
  38. #print('{6:>4}|{7:>4}'.format(*range(8)))
  39. #print('{7:>4}'.format(*range(8)))
  40. #print('-' * 57)
  41.  
  42. # Tmp Sensor Use
  43. class MLX90614():
  44.  
  45.     MLX90614_RAWIR1=0x04
  46.     MLX90614_RAWIR2=0x05
  47.     MLX90614_TA=0x06
  48.     MLX90614_TOBJ1=0x07
  49.     MLX90614_TOBJ2=0x08
  50.  
  51.     MLX90614_TOMAX=0x20
  52.     MLX90614_TOMIN=0x21
  53.     MLX90614_PWMCTRL=0x22
  54.     MLX90614_TARANGE=0x23
  55.     MLX90614_EMISS=0x24
  56.     MLX90614_CONFIG=0x25
  57.     MLX90614_ADDR=0x0E
  58.     MLX90614_ID1=0x3C
  59.     MLX90614_ID2=0x3D
  60.     MLX90614_ID3=0x3E
  61.     MLX90614_ID4=0x3F
  62.  
  63.     def __init__(self, address=0x5a, bus_num=1):
  64.         self.bus_num = bus_num
  65.         self.address = address
  66.         self.bus = smbus.SMBus(bus=bus_num)
  67.  
  68.     def read_reg(self, reg_addr):
  69.         return self.bus.read_word_data(self.address, reg_addr)
  70.  
  71.     def data_to_temp(self, data):
  72.         temp = (data*0.02) - 273.15
  73.         return temp
  74.  
  75.     #def get_amb_temp(self):
  76.     #    data = self.read_reg(self.MLX90614_TA)
  77.     #    return self.data_to_temp(data)
  78.  
  79.     def get_obj_temp(self):
  80.         data = self.read_reg(self.MLX90614_TOBJ1)
  81.         return self.data_to_temp(data)
  82.  
  83. #if __name__ == "__main__":
  84. #    sensor = MLX90614()
  85. #    #print(sensor.get_amb_temp())
  86. #    print(sensor.get_obj_temp())
  87.  
  88. # Main program loop.
  89. while True:
  90.     # Read all the ADC channel values in a list.
  91.     values = [0]*8
  92.     for i in range(8):
  93.         # The read_adc function will get the value of the specified channel (0-7).
  94.         values[i] = mcp.read_adc(i)
  95.  
  96.         sensor = MLX90614()
  97.         #print(sensor.get_amb_temp())
  98.         #print(sensor.get_obj_temp())
  99.  
  100.     # Print the ADC values.
  101.     print('{7:>4}'.format(*values))
  102.     print(sensor.get_obj_temp())
  103.     #print('{6:>4}|{7:>4}'.format(*values))
  104.     #print('| {0:>4} | {1:>4} | {2:>4} | {3:>4} | {4:>4} | {5:>4} | {6:>4} | {7:>4} |'.format(*values))
  105.     # Pause for half a second.
  106.     time.sleep(10)

นำข้อมูลเข้า Database
https://pynative.com/install-mysql-connector-python/

1. ติดตั้ง mysql-connector
  1. pip install mysql-connector-python

2. Code
  1. nano DB.py

  1. import mysql.connector
  2. from mysql.connector import Error
  3. from mysql.connector import errorcode
  4.  
  5. try:
  6.     connection = mysql.connector.connect(host='192.168.2.101',
  7.                                          database='sci_pi',
  8.                                          user='XXX',
  9.                                          password='XXX')
  10.     #INSERT INTO `Data` (`ID`, `Vibration`, `Tmp`, `TransDate`) VALUES (NULL, '50', '60', '2020-05-22');
  11.     mySql_insert_query = """INSERT INTO Data (ID, Vibration, Tmp, TransDate, FromPI)
  12.                           VALUES
  13.                           (NULL, 50, 60, '2020-05-22','192.168.0.164') """
  14.  
  15.     cursor = connection.cursor()
  16.     cursor.execute(mySql_insert_query)
  17.     connection.commit()
  18.     #print(cursor.rowcount, "Record inserted successfully into Laptop table")
  19.     cursor.close()
  20.  
  21. #except mysql.connector.Error as error:
  22. #    print("Failed to insert record into Laptop table {}".format(error))
  23.  
  24. finally:
  25.     if (connection.is_connected()):
  26.         connection.close()
  27.         #print("MySQL connection is closed")
  28.  


3. Test Run
  1. python DB.py


ดูว่าข้อมูลเข้า Database ที่สร้างไว้หรือไม่
ส่งเมล์ Zimbra แจ้งเตือนผู้เกี่ยวข้อง
เมื่อเครื่องสั่น มากหรือ มอเตอร์ร้อนมาก

1. ติดตั้ง
  1. apt-get install ssmtp


2. Code
  1. nano Mail.py

  1. import smtplib
  2.  
  3. server=smtplib.SMTP('192.168.2.102',25)
  4. server.starttls()
  5. server.login("suwit_j@sci.com","XXX")
  6.  
  7. message = """From: PI <suwit_j@sci.com>
  8. Subject: Wraning From PI Check Machine.
  9.  
  10. Wrannnig From PI Check machine.
  11. Please Chack.
  12. http://intranet.sci.com/sci/PR/rp_start.php
  13. """
  14.  
  15. server.sendmail("suwit_j@sci.com","suwit_j@sci.com", message)
  16.  
  17. server.quit()


3. ทดสอบ Run คำสั่ง
  1. python Mail.py

https://iotdesignpro.com/projects/sending-smtp-email-using-raspberry-pi