2018年4月22日 星期日

居家保全系統

# 目標

  • 每次開關門的事件,都會以 Line 通知,並且用 webcam 拍下當時的照片,傳送到手機上
  • 偵測節點可以擴充
  • 可以像保全系統一樣,開啟保全&解除保全
  • 每次的告警事件,都會存在主機的資料庫上供日後查詢

# DEMO VIDEO

#架構












  • 每個門窗的節點用 nodeMcu(esp8266),使用 Arduino IDE 開發
  • 中控台使用 raspberry pi3,程式以 python3撰寫
  • 中文語音和合成使用 syn7318 晶片
  • Line 的訊息傳遞,使用 IFTTT 的服務
  • python 使用到的重要的模組有 bottle(web框架),pygame , pymysql , pyserial

# 原理

  • 中控台的 raspberry 運行 python 的 bottle web 框架,等於是一台微型的 web server
  • 擔任節點的 nodemcu 偵測到異常事件時,向中控台發出對應的 http request 
  • 中控台收到 nodemcu 的 http request 時,做後續的處理,判斷,拍照,發出警告,發 line ,寫入資料庫

# Python & Arduino Code




2018年4月18日 星期三

(Personal memo notes) using python to implement Chinese speech recognition

let's see the demo first



#Required components

   1. Execute python computer, I use iMac 27, python3 version can support unicode
   2. SYN7318 Chinese Speech Recognition Chip
   3. A piece of Arduino UNO to verify that python can control on/off of GPIO on                 Arduino through firmata protocol

#Architecture principle

    1.  iMac(Python 3) <==> (pySerial) <==> SYN7318
    2.  iMac(Python 3) <==> (firmata)  <==> Arduino



    
    
       
   
    
    
    
    

    
    
    
        
    

2018年4月14日 星期六

(個人備忘筆記) 用 Python 實現透過 Google API 將 Arduino + SHT10 傳回的溫濕度資料 寫到 google sheets

#1. 在 Google Cloud Consel 要啟用 Google Sheet API ,並且將產生的 json 檔案存放到 pythont 程式的相同目錄

#2. 在 Google Sheets的工作表上要新增共享權限到剛剛啟用的 Google Sheet API 的 service account

#3. 安裝 python 的 google-api-python-client 模組
      pip3 install --upgrade google-api-python-client

#4. 安裝 python 的 pygsheets 模組
     pip3 install pygsheets








========= python 端程式 ===========

#coding:utf-8

import serial
import sys
import time
import pygsheets

port = "/dev/tty.usbmodem1421"

serialArduino = serial.Serial(port, 9600)

serialArduino.flushInput()

#google API
gc = pygsheets.authorize(service_file='pythongoogle.json')
sh = gc.open('pythontest')
wks = sh[0]
rowCount = 2



while True:
       
        input = serialArduino.readline()
        temp = str(input[0:5],'utf-8')
        humi = str(input[-7:-2],'utf-8')
        now = time.strftime("%Y/%m/%d %H:%M:%S")
        print(now + ' > ' + 'Temperature: ' + temp + '°C  ,Humidity: ' + humi + '%')
        # proc cells
        try:
            rowCount=int(wks.get_value('A1'))
            if rowCount > 998 :
                print("google sheet row is full , exit the process")
                sys.exit()
         
            wks.update_cell((rowCount,1), now)
            wks.update_cell((rowCount,2), temp)
            wks.update_cell((rowCount,3), humi)
            print("writen " + str(rowCount-2) + " records in sheets")
            rowCount = rowCount + 1
            wks.update_cell((1,1), rowCount)
        except Exception as exec:
            print('update the google sgeet is fail, pls check the networking connect ....')
            sys.exit()

===============================

=============================== Arduino 程式 ===============
#include <SHT1x.h>

// Specify data and clock connections and instantiate SHT1x object
#define dataPin  10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);

void setup()
{
   Serial.begin(9600); // Open serial connection to report values to host
   // Serial.println("Starting up");
}

void loop()
{
  float temp_c;
  float temp_f;
  float humidity;

  // Read values from the sensor
  temp_c = sht1x.readTemperatureC();
  temp_f = sht1x.readTemperatureF();
  humidity = sht1x.readHumidity();

  // Print the values to the serial port
  
  Serial.print(temp_c, DEC);
  Serial.print(",");
  Serial.println(humidity);
  

  delay(300000);
}