erlang_raspberrypi_temperature_sensor

所属分类:collect
开发工具:Erlang
文件大小:0KB
下载次数:0
上传日期:2016-06-15 09:11:57
上 传 者sh-1993
说明:  使用Adafruit IO Dashboard、MCP3008 ADC和DHT11传感器的小覆盆子Pi-IoT项目。
(A small Raspberry Pi IoT-project using Adafruit IO Dashboard, MCP3008 ADC and DHT11-sensor.)

文件列表:
LICENSE (52, 2016-06-15)
Makefile (259, 2016-06-15)
dht11_src/ (0, 2016-06-15)
dht11_src/dht11 (8108, 2016-06-15)
dht11_src/dht11.c (2214, 2016-06-15)
erlang.mk (207224, 2016-06-15)
relx.config (72, 2016-06-15)
rpi3-wiring.png (821044, 2016-06-15)
run.sh (59, 2016-06-15)
src/ (0, 2016-06-15)
src/dht11.erl (672, 2016-06-15)
src/file_read.erl (522, 2016-06-15)
src/iottimer.erl (260, 2016-06-15)
src/lightlevel_handler.erl (944, 2016-06-15)
src/mcp3008.erl (697, 2016-06-15)
src/rest.erl (1058, 2016-06-15)
src/toppage_handler.erl (879, 2016-06-15)
src/webserver.app.src (371, 2016-06-15)
src/webserver_app.erl (1035, 2016-06-15)
src/webserver_sup.erl (1032, 2016-06-15)
templates/ (0, 2016-06-15)
templates/lightlevel.dtl (130, 2016-06-15)
templates/toppage.dtl (120, 2016-06-15)

Raspberry Pi Erlang IoT Webserver ===== Erlang application with an embedded [Cowboy webserver](https://github.com/ninenines/cowboy) for reading values from sensors and publishing to a Adafruit.io IoT-Dashboard. The program uses [Erlang ALE module](https://github.com/esl/erlang_ale) to read an analog sensor through the SPI-interface and a C driver program to read the DHT11-sensor. Being more low level, the C program reads more accurate values and outputs them as JSON. Erlang executes the C program and extracts the values using the [JSX library](https://github.com/talentdeficit/jsx#encode12). - [Prerequisites - Hardware](#pregh) - [Prerequisites - Software](#preqs) - [Wiring the Raspberry and the sensors](#wiring) - [Building](#building) - [Starting the server](#starting) - [Automatic timer to continuously publish sensor values to Adafruit.io](#timer) - [Testing the sensors from the Erlang Shell](#testing) - [Accessing the sensors throught the embedded webserver](#webserver) Prerequisites - Hardware ---- - Raspberry 3B/2B - Full size breadboard, [Buy from Adafruit](https://www.adafruit.com/products/239) - Adafruit T-Cobbler Plus GPIO Breakout, [Buy from Adafruit](https://www.adafruit.com/products/2028) - MCP3008 Analog to Digital Converter, [Buy from Adafruit](https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008) - Keyes DHT11 Digital temperature and humidity sensor, [Amazon](https://www.amazon.com/Digital-Temperature-Humidity-Sensor-Arduino/dp/B0100A9SZ2/ref=sr_1_cc_3?s=aps&ie=UTF8&qid=1465662964&sr=1-3-catcorr&keywords=keyes+dht11) - Keyes Photo Resistor (analog light level sensor), [Amazon](https://www.amazon.com/HobbyKing-KY-018-resistor-Module-Arduino/dp/B01EE0WNZQ/ref=sr_1_2?s=toys-and-games&ie=UTF8&qid=1465663093&sr=1-2&keywords=keyes+photo+resistor) Prerequisites - Software ----- You must download and install [Erlang](https://www.erlang-solutions.com/home.html) in order to build and run this project. For Raspberry Pi, you can download Erlang Mini (without gui packages) which is good for small embedded devices. Go to the [download page](https://www.erlang-solutions.com/resources/download.html), select "Raspbian" and follow the installation instructions. To read values from sensors with Erlang, this project uses the [Erlang ALE module](https://github.com/esl/erlang_ale). I highly recommend you to follow the directions in the modules repository to test it in a local repo before integrating it in your own project. The software tries to publish values to [Adafruit IoT Dashboard](https://io.adafruit.com), so you will need an account and a dashboard. You can read Jeremy Morgans great blog post [here](https://www.jeremymorgan.com/internet-of-things/how-to-adafruit-io/) on how to do that. Wiring the Raspberry and the sensors ---- 0. Start by connecting the Cobbler to the breadboard and then to the Raspberry PI 1. Wire the Analog-to-Digital Converter (ADC) according to [Adafruit's excellent guide](https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008). On a Raspberry 3, you can wire the ADC directly to the hardware SPI interface (see a separat section in the guide for that). 2. Connect the Photo Resistor to channel 0 on the ADC. 3. Connect the DHT11 to GPIO #4 4. Git clone this repo and then build the code as described below. Build ----- $ make distclean $ make Starting the server ---- To start the release in the console: $ chmod u+x run.sh $ ./run.sh or $ ./_rel/webserver/bin/webserver console Automatic timer to continuously publish sensor values to Adafruit.io ---- By starting a timer, you can let Erlang read and publish sensor values continuously to Adafruit.io. (webserver@127.0.0.1)1> iottimer:start(5000). In this example, Erlang will read and publish new values every 5 seconds. To stop the timer, call the stop function: (webserver@127.0.0.1)2> iottimer:stop(). Testing the sensors from the Erlang Shell ---- After you have startet the server with one of the terminal commands above, you will be able to execute commands directly in the Erlang Shell: pi@raspberrypi3:~/erlang_raspberrypi_temperature_sensor $ ./run.sh .... /home/pi/erlang_raspberrypi_temperature_sensor/_rel/webserver Erlang/OTP 18 [erts-7.3] [source] [smp:4:4] [async-threads:10] [kernel-poll:false] Eshell V7.3 (abort with ^G) (webserver@127.0.0.1)1> Try running "mcp3008:readSPI(0)." to read a value from the light-level sensor connected to channel 0 on the ADC: (webserver@127.0.0.1)1> mcp3008:readSPI(0). { "id": 649281259, "value": "116", "position": null, "lat": null, "lon": null, "ele": null, "feed_id": 592856, "group_id": null, "expiration": null, "completed_at": null, "created_at": "2016-06-12T11:57:21.688Z", "updated_at": "2016-06-12T11:57:21.688Z", "created_epoch": 1465732641.68893 } Try running "dht11:read()." to read and publish humidity and temperature values: (webserver@127.0.0.1)2> dht11:read(). { "id": 649260154, "value": "32.0", "position": null, "lat": null, "lon": null, "ele": null, "feed_id": 592854, "group_id": null, "expiration": null, "completed_at": null, "created_at": "2016-06-12T11:51:11.719Z", "updated_at": "2016-06-12T11:51:11.719Z", "created_epoch": 1465732271.71952 }{ "id": 649260167, "value": "26.0", "position": null, "lat": null, "lon": null, "ele": null, "feed_id": 592855, "group_id": null, "expiration": null, "completed_at": null, "created_at": "2016-06-12T11:51:11.935Z", "updated_at": "2016-06-12T11:51:11.935Z", "created_epoch": 1465732271.93519 } Accessing the sensors throught the embedded webserver ---- The embedded Cowboy webserver's endpoints are coded in the file webserver_app.erl. Point your browser at http://localhost:8080/sensors/light to see output from the sensor (that is, if your Raspberry actually has a sensor connected).

近期下载者

相关文件


收藏者