參考資料:http://dreamingecho.es/blog/internet-of-things-with-python-and-flask
Tutorials For IoT-Makers

 

(1) USING TEMPLATES AND STYLING THINGS

We store all the HTML templates in a special directory called templates, and
all our public content (like stylesheets, javascripts, images...) in a special directory called static

To do some quick styling, I'm going to use Bootstrap with the Jumbotron Narrow example HTML,
so we only have to 
download the files and put it into our static folder.

Once we got all the Bootstrap files on the static folder, we're going to integrate it with the application.
Firstly, let's open the 
main.py file and change our index method with this lines:

@app.route("/")
def index():
    return render_template('index.html')

we have replaced the return "Hello World!" thing for return render_template('index.html' )
 

index.html file
 

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="{{ url_for('static', filename='images/favicon.ico') }}">

  <title>Flask Internet of Things App</title>

  <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">

  <link href="{{ url_for('static', filename='css/jumbotron-narrow.css') }}" rel="stylesheet">

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

  <div class="container">

    <!-- A bunch of magic HTML code :) -->

  </div>
  <!-- /container -->
</body>

</html>

we're going to create a very simple class in the root of our application called raspi.py. With the help of the RPi.GPIO library, we're going to code some very simple methods to be able to read the sensor value and modify the state of the LED. The content of the class will looks like this:

import RPi.GPIO as GPIO

SENSOR_PIN  = 22
LED_PIN     = 23

class Raspi(object):

    def __init__(self):
      GPIO.setmode(GPIO.BCM)
      GPIO.setup(SENSOR_PIN, GPIO.IN)
      GPIO.setup(LED_PIN, GPIO.OUT)

    def read_sensor(self):
      return GPIO.input(SENSOR_PIN)

    def change_led(self, value):
      GPIO.output(LED_PIN, value)

Ok, with this done, let's modify our main.py file to use this new class and be able to interact with the GPIOvia web. At the end we'll have something like this:

import raspi
from flask import *

app = Flask(__name__)
raspi = raspi.Raspi()

# Index route
@app.route("/")
def index():
  # Read the value of the sensor
  value = raspi.read_sensor()
  # Render the index.html template passing the value of the sensor
  return render_template('index.html', sensor_value=value)

# About route
@app.route("/about")
def about():
  # Render the about.html template
  return render_template('about.html')

# Change LED value POST request.
@app.route("/change_led_status/<int:status>", methods=['POST'])
def change_led_status(status):
  # Check the value of the parameter
  if status == 0:
    raspi.change_led(False)
  elif status == 1:
    raspi.change_led(True)
  else:
    return ('Error', 500)
  return ('', 200)

# Starts the app listening to port 5000 with debug mode
if __name__ == "__main__":
  app.run(host="0.0.0.0", debug=True)

To send the value of this parameter we're gonna use some jQuery to do some POST requests to the route depending of the button we click. Something like this:

$(document).ready(function() {
  $('#set_on').click(function() {
    $.post('/change_led_status/1');
  });
  $('#set_off').click(function() {
    $.post('/change_led_status/0');
  });
});

stanley 發表在 痞客邦 留言(0) 人氣()

Raspberry 常用指令

(1) How to set up WiFi on your Raspberry Pi without a keyboard or monitor (or ethernet)
    (1.1) Put the Raspbian SD card into your computer
             (1.2) cd /Volumes/boot
             (1.3) Add your wpa_supplicant.conf file
                    Create a file in this directory called wpa_supplicant.conf. The file should contain the following details:
                    network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK }
              With this file in place, Raspbian will move it in /etc/wpa_supplicant/ when the system is booted.
            (1.4) Put your SD card in the Raspberry Pi, boot, and connect
(2) Raspberry Pi 3 B and B+ - How to Configure Wi-Fi and Bluetooth
     Now you need to add your Wi-Fi settings to the wpa-supplicant configuration file. Type the following in the command line to the configuration file: sudo nano /etc/wpa_supplicant/wpa_supplicant.conf.
    Go to the bottom of the file and add the following Wi-Fi setting, adding your setting in the quotation marks.
    network={
       ssid="The_ESSID_from_earlier"
       psk="Your_wifi_password"
    }

(3) RASPBERRY GPIO SETUP.
pi@raspberrypi:~ $ apt-get update
pip install RPi.GPIO
 

(3) install FTP

http://yhhuang1966.blogspot.com/2017/02/ftp.html
sudo raspi-config

stanley 發表在 痞客邦 留言(0) 人氣()

參考資料:
(1) https://www.instructables.com/id/Python-WebServer-With-Flask-and-Raspberry-Pi/
(2) https://medium.com/@rovai/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d

(1) Installing FLASK and Setting Your RPi WebServer

sudo apt-get update
sudo pip install Flask

(2) Create folder  
(2.0) cd Documents
(2.1)  mkdir rpiWebServer
(2.2)  cd rpiWebServer
(2.3)  mkdir static
(2.4) mkdir templates

(3)  Create helloWorld.py     

from flask import Flask
app = Flask(__name__) 
@app.route("/")
def hello():
    return "Hello World!" 
if __name__ == '__main__':
    app.run(debug=True, port=80, host='0.0.0.0')

 

The final folder “tree”, will look like:

undefined

(4) Execute Hello World program

 pi@scpi:~/Documents/rpiWebServer $ sudo python helloWorld.py
 * Serving Flask app "helloWorld" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 159-728-082

(5) in WebBrower keyin
   http://192.168.0.110/

 


     

  

文章標籤

stanley 發表在 痞客邦 留言(0) 人氣()

參考資料:

(1)https://github.com/intelmakers/robot_in_google_cloud/wiki/Installation_of_OpenCV
(2)https://communities.intel.com/thread/57712

 

(1) 方法1 :   

輸入下方指令

     opkg list | grep python-opencv
     opkg list-installed | grep python-opencv

Unknown package 'python-opencv'.

Collected errors:

* opkg_install_cmd: Cannot install package python-opencv.

方法:
Added src iot-devkit-i586 http://iotdk.intel.com/repos/1.1/iotdk/i586,
src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic
to iot-devkit.conf and updated my opkg then upgraded it.

  cd /var/opkg/
  Create intel-iotdk.conf file      
      echo "src intel-iotdk http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/intel-iotdk.conf 
  opkg update
  opkg upgrade   
  opkg install python-numpy opencv python-opencv

(2) 方法2

root@mylinkit:/etc/opkg# wget http://iotdk.intel.com/repos/1.1/iotdk/i586/opencv_2.4.8+git0+a4b34e7ae1-r0_i586.ipk
Connecting to iotdk.intel.com (104.124.188.30:80)
opencv_2.4.8+git0+a4 100% |*******************************|   732   0:00:00 ETA
root@mylinkit:/etc/opkg# ls -lt
-rw-r--r--    1 root     root           732 Nov 13 22:29 opencv_2.4.8+git0+a4b34e7ae1-r0_i586.ipk
-rw-r--r--    1 root     root           197 Nov 13 21:28 iot-devkit.conf
-rw-r--r--    1 root     root           104 Nov 13 21:15 tomfeeds.conf
drwxr-xr-x    2 root     root            63 Nov 20  2015 keys
-rw-r--r--    1 root     root           103 Nov 18  2015 customfeeds.conf
-rw-r--r--    1 root     root           215 Oct 27  2015 distfeeds.conf
root@mylinkit:/etc/opkg# opkg install opencv_2.4.8+git0+a4b34e7ae1-r0_i586.ipk
Installing opencv (2.4.11-3) to root...
Downloading http://mirror2.openwrt.org/mt7688_v0.9/packages/opencv_2.4.11-3_ramips_24kec.ipk.
Configuring opencv.

[註:以上文章只是收集網站,並没有在LinkIt 7688 測試成功]

stanley 發表在 痞客邦 留言(0) 人氣()

(1) https://forums.xamarin.com/discussion/35430/view-mjpg-video-streaming-in-xamarin-android

(2) http://www.netosa.com/blog/2015/01/android-sdk-access-mjpeg-streamer.html

(3) https://www.androidbegin.com/tutorial/android-video-streaming-videoview-tutorial/

(4) http://solderer.tv/cxemcar2/

(5) https://searchcode.com/codesearch/view/42365870/
(7) http://sampleprogramz.com/android/media.php
(8) https://o7planning.org/en/10487/android-mediaplayer-and-videoview-tutorial
(9)https://jerrynest.io/app-android-webview/

(10)詳解Android App中使用VideoView來實現視訊播放的方法
(11)android 視訊播放(一)利用android原生的videoview
(12)android video 播放 - VideoView 教學

 

 

stanley 發表在 痞客邦 留言(0) 人氣()

一起學 Python 107 : 五分鐘學會使用 Python 傳送 Line 訊息 在 Raspberry pi 開機啟動提醒

LINE Notify / LINE Login 實作小問題整理-黑暗執行緒

stanley 發表在 痞客邦 留言(0) 人氣()

[ MediaTek ] 透過 LinkIt Smart 7688 拍照上傳到 Dropbox 並透過 IFTTT 發送 Notification 教學7688 Duo 程式資料相當有限,是故收集相關程式記錄在此網站,讀完這些範例,你的程式功力將會大

(1) Create and run your first example (Blink D13 LED)

(2) 透過 WebSocket 傳送 Sensing Data 到 IoT Studio

(3) Smart Lighting and Notifications

(4) LinkIt Smart 7688 Duo: Subscribing to MQTT topic

(5) 使用 LinkIt smart 7688 Duo 搭配 MCS gamepad channel 製作遙控戰車
(6) GitHub - NCKU-CCS/Mosquito-Killer-X: 專殺蚊子用的捕蚊燈

(7) Linkit Smart 7688 Duo上使用PMS3003 (G3) 空汙感測器
(8) [LinkIt Smart 7688] FPV第一人稱輪型機器人- 可愛小瓦力
(9) Michael Huang 的 LinkIt Smart 7688小案 – WiFi工程車

(10) 7688 Duo有趣的專案及參考資料@Ted好玩
(11) 雷虎遙控車 – 使用LinkIt Smart 7688 改裝成FPV第一人稱視角載具

(12) LinkIt Smart 7688 傳送感測資訊到 Google Spreadsheet 教學

(13) 如何使用LinkIt 7697在MCS上監控溫溼度變化

(15) 7688 Duo有趣的專案及參考資料@Ted好玩

(16)[ MediaTek ] 透過 LinkIt Smart 7688 拍照上傳到 Dropbox 並透過 IFTTT 發送 Notification 教學 

(17)Build Surveillance Camera and Save All Images on MCS Cloud
(18)[ Linkit Smart 7688 ] 透過 Python 傳送 Video Stream 到 MediaTek Cloud Sandbox (MCS)  using ffmpeg
(19)[誰偷喝我的五十嵐?] 使用7688 Duo與MCS雲服務打造小偷偵測系統   (using fswebcam)
(20) 7688 Duo Monitor Toy – 居家監控娃娃
(21) Auto Trashcan 自動垃圾桶
(22) DIY簡易空氣盒子
(23) Who's Home
(24) Zoned Climate Control.

 

 

 

 

 

 

 

文章標籤

stanley 發表在 痞客邦 留言(0) 人氣()

(1) LinkIt Smart 7688 資源[官方網站]連接
(2) 開始使用 7688 Duo Board

(3) 如何設定WIFI
      Reset 後利用手機連線至Duo 板子,然後在手機chrome 輸入192.168.100.1,再輸入route 資訊切換至Station mode
(3) 執行第一支程式(Python program)
(4)
  LinkIt Smart 7688 FAQ
(5) 如何 Reset linkit smart 7688 Duo
(5) 開機及Wi-Fi LED states
(6) LinkIt Smart 7688 Developer’s Guide(Advanced user)
(7) OpenWrt Project[官方網站]
     Quick Start Guide, User Guide , Developer Guide

(8) 如何在 MT7688 開機時自動啟動服務?
      至/etc/rc.local 內新增 python /root/app/xx.py &    
(9) 7688  關機

     當你想要將 LinkIt Smart 7688 關機時,不建議直接拔除 USB 線或是使用其他直接斷電的操作,否則將會有檔案系統損毀進而無法開機的現象發生。標準做法為:想要將系統關機時,先至命令列         (透過 SSH 或是 UART) 中輸入 reboot 或是 poweroff 的指令*,讓系統將所有尚未完成的 I/O 操作完成。等到這一步驟完成後,你會看到板上的橘色 LED 閃爍並亮起準備進行開機程序時,就可以       安全地將系統斷電。

      * OpenWrt 並無提供 shutdown 這個指令,而且 poweroff 指令與 reboot 指令都是相同的行為 (亦即重開機)。
        (9.1) 555 timer delay cicruit 
        (9.2) 555 Monostable Circuit Calculator     
(10) 7688 模擬器
(11) File storage

(12) Network

(13)讓 LinkIt Smart 7688 的 Wi-Fi AP 與 station 同時運作

(14)Peripheral support on LinkIt Smart 7688 development board

(14) Using USB Webcam
(14.1)用Python寫CGI傳輸即時影像並控制GPIO
(14.2) 
mjpg_streamer -i "input_uvc.so -d /dev/video0 -r 640x480 -f 25" -o "output_http.so -p 8080 -w /www/webcam" &
(14.3)
http://192.168.X.105:8080/
(!4.4)    http://mylinkit.local:8080?action=stream
(15) mediatek Forums
(16) Make Python code run much faster by pre-compiling python py modules into pyc
(17) LinkIt Smart 7688 Duo-Wi-Fi 掛點急救篇
(18)
Switch the PinMux  【7688】不用Libmraa一樣可以控制GPIO ]
(19-0) Firmata 設定: Prototyping Arduino Projects using Python
(19) 玩IOT(8) -利用 Firmata PyFirmata函式庫讓7688 MPU和 Arduino MCU 溝通
(20) Update the firmware with a USB drive, Enabling SFTP, Mounting the root FS on an SD card
(21) GPIO IN, OUT, gpio input using interrupt
(22) 7688 Duo Python Server 
(23) 使用Firmata_tets 程式測試pinout接腳使用Firmata讀取analog 值,使用PWM 範例
(24) How to read and write to Arduino using Python
(25) Servomotor – moving the motor to certain angle (read & Write),範例1-Hello World,
範例2:Hello World-Python可以這樣玩(19):電位計實驗 

               直接設定腳位物件:
                   
A2 = board.get_pin('a:2:i')        # a 代表類比, i 代表 input
    
D3 = board.get_pin('d:10:o')       # d 代表數位, o 代表 output
   
D5 = board.get_pin('d:11:p')       # d 代表數位,   代表PWM
    D10 = board.get_pin('d:12:s')      # d 
代表數位,       代表SERVO
       a:0:i for analog 0 as input or d:11:p for digital pin 11 as pwm 

>>> analog_0 = board.get_pin('a:0:i')
>>> analog_0.read()
0.661440304938
>>> pin3 = board.get_pin('d:3:p')
>>> pin3.write(0.6)

   
(26) Firmata Library
(27) OpenWrt boot 
(28) Python x Arduino物聯網整合開發實戰-第3-4章使用python & firmata

(29)[ Linkit Smart 7688 ] 傳送檔案與登入到開發板 (putty ftp)
(30) MediaTek ] 擴充 LinkIt Smart 7688 容量教學
(31)Mounting the root FS on an SD card

(32)IOT(19) 加按鍵試7688 DUO input port

(33)IOT(11) 了解7688 DUO 和 Arduino 的接腳位置

(34)查詢及修改GPIO輸入,輸出設定

(35) [ Linkit Smart 7688 ] 安裝 USB 音效卡

文章標籤

stanley 發表在 痞客邦 留言(0) 人氣()

最近開始在玩

undefined

undefined

PinOUT 大型圖

undefined

undefined

[註]Finding GPIO pins on the PCB
      D0~D13 為數位腳位(Digital Pin),D14~D17 為SPI 的腳位,D18~D23 為類比. 腳位(Analog Pin)(MediaTek, 2016)。
     PWM Pins are : D3, D5, D6, D9, D10, D11, D12, D13
     GPIO 44 maps to Wi-Fi LED
      玩IOT(6) 便用 libmraa 函式庫來控製WiFi LED

 

Specification

  • MPU
    • Chipset: MT7688AN
    • Core: MIPS24KEc
    • Clock Speed: 580MHz
    • Working Voltage: 3.3V
  • MCU
    • Chipset: ATmega32U4
    • Core: Atmel AVR
    • Clock Speed: 8MHz
    • Working Voltage: 3.3V
  • Memory
    • Flash: 32MB
    • RAM: 128MB DDR2
  • GPIO
    • Pin Count: 3(MT7688AN), 24(ATmega32U4)
    • Voltage: 3.3V
  • PWM
    • Pin Count: 8(Atmega32U4)
    • Voltage: 3.3V
    • Max. Resolution: 16 bits(customizable)
  • ADC
    • Pin Count 12(ATmega32U4)
    • Resolution: 10 bits
  • External Interrupts: 8
  • SPI/SPIS
    • Pin numbers: S0, S1, S2, S3
    • Max Speed: 4MHz
  • I2C
    • Pin Number: D2/D3
    • Speed: 400KHz
  • UART Lite
    • 1 for ATmega32U4, 1 for MT7688AN
    • Pin Number: P8/P9(MT7688AN), D0/D1(ATmega32U4)
  • USB Host
    • Pin Number: P6/P7
    • Connector Type: Micro-AB
  • Communication
    • Wi-Fi: 1T1R 802.11 b/g/n (2.4G)
    • Ethernet: 1-port 10/100 FE PHY
    • Pin Numbers: P2/P3/P4/P5
  • User Storage: SD Card Micro SD/SDXC
  • Size: 60.8x26.0mm

Switch the PinMux

mt7688_pinmux get
mt7688_pinmux set <group> <function>

 

stanley 發表在 痞客邦 留言(0) 人氣()

WifiManager 是一個功能很強的class,它描述Wi-Fi 連接的所有資訊,
我做了一個簡單且重要常用的資料整理,
它包括了 

(1)  //重新掃描Wi-Fi資訊
      WifiMager.startScan();
(2)  //偵測周圍的Wi-Fi環境(返回很多組Wi-Fi,型態為List)
    WifiScanResultList = WifiManager.getScanResults();
(3)  //手機內已存的Wi-Fi資訊(返回很多組Wi-Fi,型態為List)
    WifiConfigurationList = WifiManager.getConfiguredNetworks();
(4)  //目前已連線的Wi-Fi資訊
    WifiInfo = WifiManager.getConnectionInfo(); 
(5) //開啓及關閉Wi-Fi網路 
     WifiManager.enableNetwork, WifiManager.disableNetwork
(6) // Wi-Fi中斷
     WifiManager.disconnect()
(7) // Wi-Fi偵測 :
     WifiManager.isWifiEnabled()
(8) //Enable or disable Wi-Fi  
     WifiManager.setWifiEnabled()
(9)//新增一個wifi 
     WifiManager.addNetwork
#------------------------------------------------


     
 

 

文章標籤

stanley 發表在 痞客邦 留言(0) 人氣()

Close

您尚未登入,將以訪客身份留言。亦可以上方服務帳號登入留言

請輸入暱稱 ( 最多顯示 6 個中文字元 )

請輸入標題 ( 最多顯示 9 個中文字元 )

請輸入內容 ( 最多 140 個中文字元 )

reload

請輸入左方認證碼:

看不懂,換張圖

請輸入驗證碼