歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 樹莓派學習筆記——webiopi配置文件說明

樹莓派學習筆記——webiopi配置文件說明

日期:2017/2/28 14:34:43   编辑:Linux教程

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看起來更尤優美一些,暫時未詳細測試。

Copyright © Linux教程網 All Rights Reserved