แสดงบทความที่มีป้ายกำกับ Raspberry pi แสดงบทความทั้งหมด
วันอาทิตย์ที่ 14 มิถุนายน พ.ศ. 2558
[HOW TO] LINE Bot on Raspberry PI with LINE API Python
Posted by
Unknown,
on
23:14:00
[HOW TO] LINE Bot on Raspberry PI with LINE API Python
1. ทำการอัพเดท packet ของ raspbian ก่อน
ทำการเพิ่ม สคริป ภายใต้
5. ทำการรันไฟล์ config.py และ ติดตั้งด้วย setup.py
6. หากไม่มี Error ใดๆในการติดตั้ง ให้ทดลองการส่งข้อความด้วยไฟล์ echobot.py ใน examples (อย่าลืมเข้าไปแก้ไฟล์ โดยการใส่ ID และ Pass ด้วยนะครับ)
เพิ่มเติม script checks status
ขอบคุณ Api ดีๆจาก https://github.com/carpedm20/LINE
เครดิต : ตาเล็ก วินโด้
1. ทำการอัพเดท packet ของ raspbian ก่อน
sudo apt-get install update
sudo apt-get install upgrade2. ซึ่ง [LINE API Python] จำเป็นต้องลง packet python
sudo apt-get install python
sudo apt-get install python-pip3. ทำการ download [LINE API Python] จาก https://github.com/carpedm20/LINE ในนี้จะมีทั้งวิธีใช้ด้วย
wget https://github.com/carpedm20/LINE/archive/master.zip
unzip master.zip
cd LINE-master/4. ทำการแก้ไข ไฟล์ api.py ให้สามารถเชื่อมต่อกับ server หลักได้
ทำการเพิ่ม สคริป ภายใต้
def ready(self): """ After login, make `client` and `client_in` instance to communicate with LINE server """เอาเครื่องหมาย + ออกด้วย
+ self.transport = THttpClient.THttpClient(self.LINE_HTTP_URL) + self.transport_in = THttpClient.THttpClient(self.LINE_HTTP_IN_URL) + self.transport.setCustomHeaders(self._headers) + self.transport_in.setCustomHeaders(self._headers) + self.protocol = TCompactProtocol.TCompactProtocol(self.transport) + self.protocol_in = TCompactProtocol.TCompactProtocol(self.transport_in) + self._client = CurveThrift.Client(self.protocol) + self._client_in = CurveThrift.Client(self.protocol_in) + self.transport.open() + self.transport_in.open()
5. ทำการรันไฟล์ config.py และ ติดตั้งด้วย setup.py
python config.py
python setup.py install
6. หากไม่มี Error ใดๆในการติดตั้ง ให้ทดลองการส่งข้อความด้วยไฟล์ echobot.py ใน examples (อย่าลืมเข้าไปแก้ไฟล์ โดยการใส่ ID และ Pass ด้วยนะครับ)
vi echobot.py
เพิ่มเติม script checks status
vi check.py
import subprocess
from line import LineClient, LineGroup, LineContact
try:
client = LineClient("ID", "PASS")
#client = LineClient(authToken="TOKEN")
except:
print "Login Failed"
while True:
op_list = []
for op in client.longPoll():
op_list.append(op)
for op in op_list:
sender = op[0]
receiver = op[1]
message = op[2]
msg = message.text
if 'GetRAM' in msg:
proc=subprocess.Popen('egrep --color "Mem|Cache|Swap" /proc/meminfo', shell=True, stdout=subprocess.PIPE, )
output=proc.communicate()[0]
sender.sendMessage("[%s] %s" % (sender.name, output))
if 'GetDATE' in msg:
proc=subprocess.Popen('date', shell=True, stdout=subprocess.PIPE, )
output=proc.communicate()[0]
sender.sendMessage("[%s] %s" % (sender.name, output))
if 'GetKERNAL' in msg:
proc=subprocess.Popen('uname -a', shell=True, stdout=subprocess.PIPE, )
output=proc.communicate()[0]
sender.sendMessage("[%s] %s" % (sender.name, output))
ขอบคุณ Api ดีๆจาก https://github.com/carpedm20/LINE
เครดิต : ตาเล็ก วินโด้
วันเสาร์ที่ 6 กรกฎาคม พ.ศ. 2556
BitTorrent
BitTorrent Box
Deluge on Raspbian
HOW TO
Raspberry
Raspberry pi
Raspberry pi torrent client
[HOW TO] Make Raspberry Pi ให้เป็น BitTorrent Box
Posted by
Unknown,
on
17:59:00
Raspberry
pi torrent client : Deluge on Raspbian
ในที่นี้ USBHDD1 ถ้าเราไมเหมือนให้เปลี่ยนเป็นชื่อของHDDเราในคำสั่งข้างล่างจะเป็นการสร้าง folderใหม่สำหรับการเก็บไฟล์
sudo mkdir /media/USBHDD1/shares/torrents/completed
sudo mkdir /media/USBHDD1/shares/torrents/watch
sudo mkdir /media/USBHDD1/shares/torrents/torrent-backups
ทำการอัพเดทฐานข้อมูลของแพ็กเก็จทั้งหมดก่อนด้วยคำสั่ง
sudo apt-get update
sudo apt-get upgrade
ติดตั้งโปรแกรม Deluge for ThinClient Access
ขั้นแรกทำการติดตั้ง deluged และ deluge-console
sudo apt-get install
deluged
sudo apt-get install
deluge-console
หลังจากที่ติดตั้งเสร็จ แล้ว ทำการรัน deluged ด้วยคำสั่งนี้
deluged
sudo pkill deluged
พิมพ์คำสั่งต่อไปนี้เพื่อสำรองข้อมูลของไฟล์การตั้งค่าเดิมแล้วเปิดสำหรับการแก้ไข:
cp
~/.config/deluge/auth ~/.config/deluge/auth.old
nano
~/.config/deluge/auth
พอมาอยู่ในหน้าของ
nano ให้เพิ่มคำสั่ง
user:password:level
username ,
password ตามทีต้องการ, กำหนดเป็น level 10 (the full-access/administrative level for the daemon).
ในที่นี้เราใช้ pi:raspberry:10.จากนั้น CTRL+X และ save your changes จากนั้น ทำการรัน deluged และ deluge-console ด้วยคำสั่ง
deluged
deluge-console
ถ้าทำแล้วเกิดข้อผิดพลาดหรือ error ให้ใช้คำสั่ง “exit”
แล้วทำการรันใหม่อีกครั้ง
พอมาอยู่หน้าจอ console ให้ตั้งค่าคำสั่งตามนี้
config -s allow_remote
True
config allow_remote
exit
จากนี้เราก็สามารถจะคอนโทรลจากที่อื่นได้แล้ว
ต่อไปทำการปิดโปรเซสเพื่อให้การตั้งค่าใหม่สมบูรณ์ด้วยคำสั่ง และรัน deluged ใหม่อีกครั้ง
sudo pkill deluged
deluged
ติดตั้ง WebUI เพื่อรีโมทเข้ามา
คราวนี้มารีโมท deluge ด้วย WebUI กัน
ต่อด้วยคำสั่ง:
sudo apt-get install
deluged
sudo apt-get install
python-mako
sudo apt-get install
deluge-web
deluge-web
แล้วทำการรัน deluge-web
พอร์ตเริ่มต้นสำหรับ WebUI เป็น 8112; หากต้องการที่จะเปลี่ยนใช้คำสั่งดังต่อไปนี้
sudo pkill deluge-web
nano ~/.config/deluge/web.conf
หยุด WebUI และเปิดแฟ้มการตั้งค่า
ใช้ nano เพื่อแก้ไขบรรทัด:
"port ": 8112, และแทนที่ 8112 มีจำนวนพอร์ต (ใช้มากกว่า
1000 เพราะ 1-1000 จะถูกสงวนโดยระบบ)
จากนี้ก็จะสามารถรีโมทผ่าน WebUI ได้แล้วจาก browser ในวงแลน หรือ ของ raspberry pi โดยการใส่ IP (http://<ใส่ IP ของ Raspberry PI>:8112)
พอเข้ามา อาจจะมีการถาม Password ให้ใส่ “deluge”
ตอนนี้เราก็จะได้รูปแบบเว็บคอนโทรลที่ใช้ง่ายและสะดวกมาก
ตั้งค่าที่เก็บไฟล์ไว้ในHDD
การกำหนดที่อยู่ของไฟล์ .torrent ต่างๆ
ไปที่ Preferences -> Downloads ค่าเริ่มต้นจะเป็น /home/pi. :ซึ่งจะเก็บไว้ใน SDcard ที่มีขนาดน้อยนิด
จากนั้นก็กำหนดที่อยู่ของการเก็บไฟล์ใน Deluge ใหม่:
แล้วทำการกด OK เพื่อเสร็จสิ้น
สมัครสมาชิก:
บทความ
(
Atom
)






