หน้าเว็บ

วันพฤหัสบดีที่ 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

Linux Mint 19.3 Go Back To Old Kernel

Linux Mint 19.3 Go Back To Old Kernel And Boot to select grub menu.
1. แก้ grub
nano /etc/default/grub
เดิม
  1. GRUB_TIMEOUT_STYLE=hidden
  2. GRUB_TIMEOUT=0

ใหม่
  1. GRUB_TIMEOUT_STYLE=menu
  2. GRUB_TIMEOUT=4

เลข 4 คือเวลาต้องการให้หน่วงกี่วินาที

2. reboot แล้วเลือก grub ที่ต้องการ
3. ลบ grub ที่ปัญหาออก ใน Update Manager --> View --> Linux Kernel


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