12/10/2020

PI : PI Motion Monitor HC-SR501 PIR จับการเคลื่อนไหว และแจ้งเตือน

 PI : PI Motion Monitor HC-SR501 PIR จับการเคลื่อนไหว และแจ้งเตือน
การต่อ


เมื่อมีการเคลื่อนไหว ผ่าน หน้า Sensor ก็จะมีแจ้งเตือน ไฟก็จะติด
Code Python
  1. #!/usr/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5.  
  6. GPIO.setmode(GPIO.BOARD)            #Set GPIO to pin numbering
  7. pir = 8                             #Assign pin 8 to PIR
  8. led = 10                            #Assign pin 10 to LED
  9. GPIO.setup(pir, GPIO.IN)            #Setup GPIO pin PIR as input
  10. GPIO.setup(led, GPIO.OUT)           #Setup GPIO pin for LED as output
  11. print ("Sensor initializing . . .")
  12. time.sleep(2)                       #Give sensor time to startup
  13. print ("Active")
  14. print ("Press Ctrl+c to end program")
  15.  
  16. try:
  17.   while True:
  18.    if GPIO.input(pir) == True:      #If PIR pin goes high, motion is detected
  19.       print ("Motion Detected!")
  20.       GPIO.output(led, True)        #Turn on LED
  21.       time.sleep(4)                 #Keep LED on for 4 seconds
  22.    GPIO.output(led, False)          #Turn off LED
  23.    time.sleep(0.1)
  24.  
  25. except KeyboardInterrupt:           #Ctrl+c
  26.   pass                              #Do nothing, continue to finally
  27.  
  28. finally:
  29.   GPIO.output(led, False)           #Turn off LED in case left on
  30.   GPIO.cleanup()                    #reset all GPIO
  31.   print ("Program ended")
  32.  

12/07/2020

Axapta : Error Transaction is already marked for settlement

 Error Transaction is already marked for settlement.


ใน Open Transaction Editing เกิดขึ้นได้ทั้งฝั่ง Vendor และ Customer
เกิดจากมีการไปกด Mark ที่รายการนั้น
1. เข้าไปหาเล่มที่จะปลด Mark ออก เข้าไปที่
Inquiry --> Specifications
2. เลือก View ที่ต้องการดู เป็นเช่น Sales Order แล้วกด Open Journal Form

3. กด Functions --> Open Transaction Editing

4. ตอบ No
5. กดจะมีรายการ Mark ไว้ ให้ติ๊กออก

6. กลับไปที่ Open Transaction Editing ของ Customer Is Mark จะหายไป ก็จะสามารถกด Mark และ Update ออกได้




11/07/2020

SQL : SQL Server Enterprise Manager นำเข้าข้อมูลจากการ Query

 SQL : SQL Server Enterprise Manager นำเข้าข้อมูลจากการ Query
โดยการ Query เอาเฉพาะข้อมูลส่วนที่ต่างกัน หรือส่วนที่ไม่มีในอีก Table 1
1. นำ Table ที่ต้องการมาไว้ที่ Database เดียวกัน ด้วยการ copy table และใส่ชื่อต่อท้าย


2. เลือก Table ที่ต้องการ Export
เลือก Source Database
เลือก Destination Database
3. เลือก Use a query to specify the data to transfer.

4. เขียนคำสั่งสำหรับ Query (สามารถไปลองใน SQL ก่อนเพื่อดูความถูกต้องของข้อมูลแล้วค่อย copy มาใส่ก็ได้)
ตัวอย่างคือ เอาข้อมูลที่ไม่มีใน Table2 ไปเทียบกับข้อมูลใน Table1 ใช้ NOT EXISTS

5. เลือก Table destination สามารถกด Preview เพื่อดูข้อมูล หรือกด Transform เพื่อดู File ได้
6. กด Next
7. กด Finish ดูรายระเอียดว่าส่งไปถูกที่หรือไม่
8. ส่งข้อมูลสำเร็จ

10/27/2020

ตัวแปร $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)