树莓派学习笔记——webiopi配置文件说明

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看起来更尤优美一些,暂时未详细测试。

一文理解DDD领域驱动设计
解析VR硬件排行榜,井喷式的发展缔造下个“红海”
ADRF6520ACPZ全差分低噪声、低失真可编程滤波器
iphone13系列有望支持屏息显示
你了解螺杆螺纹吗?
树莓派学习笔记——webiopi配置文件说明
热释电红外传感器工作原理
人工智能驱动未来发展的新方向在哪
H7310线性恒流42V警示灯LED
华为丁耘:WTTx、NB-IOT成为构建5G新商业能力
谷景科普差模磁环电感漆包线断裂故障的应对方案
一个简单的磁开关电路分享
iOS 11.3 正式发布新功能全方位的汇总
吸引头部芯企涌入,IC PARK打造中国芯旗舰
嵌入式开发FPGA有哪一些设计的要点
6700K是否应该升级到9900K
光耦原理、应用以及减少选型,设计,替代导致的产品问题的规范
骨传导耳机有什么危害?骨传导耳机对人体有什么影响?
前置放大器在生物医学信号方面的应用
PCB上的串扰的三种产生机制