樹莓派學習筆記——webiopi設定檔說明

來源:互聯網
上載者:User

0.前言
    webiopi是一個可控制樹莓派GPIO的web架構,該架構面向物聯網IoT開發。該項目託管於google,並可在sourceforge上下載到原始碼。現在webiopi已經發展到0.7版本,webiopi支援REST Server,CoAP server,並提供python庫和javascript庫,毫無疑問的說webiopi是一個優秀的架構。從sourceforge上的資訊來看,下載量前三位為美國,德國和英國,天朝的下載量排在了26位(2014年3月8日),所以我覺得應該寫點什麼普及一下webiopi,並順便激勵一下仍在玩“單片機”的中國嵌入式工程師們,往前走“一步”海闊天空也。
    要熟練使用webiopi,先要對webiopi的配置有所瞭解,webiopi通過某一個config檔案實現。


1.GPIO初始化
[GPIO]
# Initialize following GPIOs with given function and optional value
# This is used during WebIOPi start process
#21 = IN
#23 = OUT 0
#24 = OUT 0
#25 = OUT 1


【作用】
webiopi運行之後立即設定GPIO連接埠的狀態,例如輸入還是輸出,若是輸出的話輸出高電平還是低電平


2.GPIO重設
[~GPIO]
# Reset following GPIOs with given function and optional value
# This is used at the end of WebIOPi stop process
#21 = IN
#23 = IN
#24 = IN
#25 = OUT 0


【作用】
webiopi結束運行之前,設定GPIO狀態。該設定最好和GPIO初始化相對應,更確切的說恢複所有的GPIO為輸入。


3.載入指令碼
[SCRIPTS]
# Load custom scripts syntax :
# name = sourcefile
# each sourcefile may have setup, loop and destroy functions and macros
#myscript = /home/pi/webiopi/examples/scripts/macros/script.py


【作用】
script.py可理解為一個主檔案,主檔案中包含3大塊內容,setup loop和destroy。webiopi運行之後的順序依次是:setup運行一次,webiopi運行時loop連續運行,webiopi運行結束之前destroy運行一次。script.py檔案的主要功能存在於loop中,在沒有網頁操作時,loop中的相關操作也會運行。


4.HTTP服務
# HTTP Server configuration
enabled = true
port = 8000


# File containing sha256(base64("user:password"))
# Use webiopi-passwd command to generate it
passwd-file = /etc/webiopi/passwd


# Change login prompt message
prompt = "WebIOPi"


# Use doc-root to change default HTML and resource files location
#doc-root = /home/pi/webiopi/examples/scripts/macros


# Use welcome-file to change the default "Welcome" file
#welcome-file = index.html


【作用】
1.使能或者禁止HTTP服務
2.設定HTTP服務的連接埠號碼,預設為8000,注意由於存在web各種web伺服器(apache或者lighttpd),所有請勿使用80連接埠。
3.設定登入使用者名稱和密碼,若是新手建議不用修改。
4.設定html檔案目錄(請注意是目錄而不是檔案)。該設定經常會被修改。


5.CoAP服務
# CoAP Server configuration
enabled = true
port = 5683
# Enable CoAP multicast
multicast = true


【作用】
1.使能CoAP服務
2.CoAP的預設連接埠為5683,不建議修改。


6.載入裝置
[DEVICES]
# Device configuration syntax:
# name = device [args...]
# name : used in the URL mapping
# device : device name
# args : (optional) see device driver doc
# If enabled, devices configured here are mapped on REST API /device/name
# Devices are also accessible in custom scripts using deviceInstance(name)
# See device driver doc for methods and URI scheme available


# Raspberry native UART on GPIO, uncomment to enable
# Don't forget to remove console on ttyAMA0 in /boot/cmdline.txt
# And also disable getty on ttyAMA0 in /etc/inittab
#serial0 = Serial device:ttyAMA0 baudrate:9600


# USB serial adapters
#usb0 = Serial device:ttyUSB0 baudrate:9600
#usb1 = Serial device:ttyACM0 baudrate:9600


#temp0 = TMP102
#temp1 = TMP102 slave:0x49
#temp2 = DS18B20
#temp3 = DS18B20 slave:28-0000049bc218


#bmp = BMP085


#gpio0 = PCF8574
#gpio1 = PCF8574 slave:0x21


#light0 = TSL2561T
#light1 = TSL2561T slave:0b0101001


#gpio0 = MCP23017
#gpio1 = MCP23017 slave:0x21
#gpio2 = MCP23017 slave:0x22


#pwm0 = PCA9685
#pwm1 = PCA9685 slave:0x41


#adc0 = MCP3008
#adc1 = MCP3008 chip:1 vref:5
#dac1 = MCP4922 chip:1


【作用】
載入各種裝置,由於裝置暫缺未詳細測試。


7.REST設定
# By default, REST API allows to GET/POST on all GPIOs
# Use gpio-export to limit GPIO available through REST API 
#gpio-export = 21, 23, 24, 25


# Uncomment to forbid changing GPIO values
#gpio-post-value = false


# Uncomment to forbid changing GPIO functions
#gpio-post-function = false


# Uncomment to disable automatic device mapping
#device-mapping = false
【作用】
預設的情況下,通過REST API可以控制所有的GPIO連接埠。這些危險操作會和loop中的功能衝突,為了防止該情況可通過配置限制REST的功能,例如設定GPIO的方法和輸出電平。


8.URL重路由
# Custom REST API route syntax :
# source = destination
# source : URL to route
# destination : Resulting URL
# Adding routes allows to simplify access with Human comprehensive URLs


# In the next example with have the bedroom light connected to GPIO 25
# and a temperature sensor named temp2, defined in [DEVICES] section
# - GET /bedroom/light => GET /GPIO/25/value, returns the light state
# - POST /bedroom/light/0 => POST /GPIO/25/value/0, turn off the light
# - POST /bedroom/light/1 => POST /GPIO/25/value/1, turn on the light
# - GET /bedroom/temperature => GET /devices/temp2/temperature/c, returns the temperature in celsius
#/bedroom/light = /GPIO/25/value
#/bedroom/temperature = /devices/temp2/temperature/c


#/livingroom/light = /devices/expander0/0
#/livingroom/brightness = /devices/adc/0/float
#/livingroom/temperature = /devices/temp0/temperature/c


#/weather/temperature = /devices/bmp/temperature/c
#/weather/pressure = /devices/bmp/pressure/hpa


【作用】
使得REST API看起來更尤優美一些,暫時未詳細測試。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.