FOBI

FOBI

ถ่ายรูป

ในส่วนของการถ่ายรูปเป็นอีกส่วนที่ใช้เพื่อให้เกิดความหลากหลายในการรับคำสั่งการทำงานของ FOBI และเป็นตัวอย่างการควบคุมอุปกรณ์ IoT เพื่อไม่ให้เกิดความน่าเบื่อในการใช้งาน FOBI ในการทำงานของส่วนนี้จะแบ่งออกเป็น

  • เมื่อได้รับคำสั่งจากผู้ใช้ว่าถ่ายรูป ก็จะทำการนำเอารูปภาพจาก frame ช่วงที่ได้รับคำสั่งมาเก็บไว้
  • เมื่อถ่ายรูปเสร็จก็จะได้รับคำสั่งผ่าน MQTT จาก Node-RED เพื่อมากสั่งงานปริ้นเตอร์
  • เมื่อไฟล์ปริ้นเตอร์ถูกรัน ด้วย OS.system ก็จะทำการสั่งงานผ่าน Terminal เพื่อปริ้นรูปถ่าย

ตัวอย่าง

import os
import paho.mqtt.client as mqtt

def on_connect(client,userdata,flags,rc):
    client.subscribe("module/camera/request")

def on_message(client,userdata,msg):
    message = msg.payload.decode('utf-8')
    if msg.topic == "module/camera/request":
        cmd = "python ther_pnter.py"
        os.system(cmd)
    

client = mqtt.Client()
client.username_pw_set("username",password="hcilab")
client.on_connect = on_connect
client.on_message = on_message

client.connect("192.168.137.188",1883,60)
client.loop_forever()
client.disconnect()