Running on Raspberry Pi smart home prototype

Source: Internet
Author: User
Tags time zones raspi

Brief introduction


A simple device for the control sensor of the terminal

Features that can be implemented

It can realize real-time monitoring of Raspberry Pi terminal by mobile phone, camera gimbal manipulation, intrusion alarm, temperature detection, light control, automatic light control and other functions.

Equipment pictures



Run



All the hardware that needs to be used
    • Router
    • Raspberry Pi Motherboard
    • Raspberry Pi power supply (5V 2A)
    • At least 8g TF card (recommended class 10,8g enough)
    • OUV-enabled Camera (Logitech C170)
    • Peanut stick and power supply (or replace with Peanut Shell Intranet version )
    • Lego bricks (small particles)
    • Two cable
    • Temperature sensor (DHT11)
    • Light sensor (photosensitive resistor module)
    • Human infrared sensor (HC-SR501)
    • Relays (5V low-level triggering)
    • Stepper Motor (28BYJ-48-5V)
    • Stepper Motor Drive Board (UL2003 type)
    • Gpio Connection Line several
Windows side of all software that needs to be installed
    • Python 2.7.9

      • Download Link: https://www.python.org/downloads/
    • Putty (0.63)

    • WinSCP (5.1.7)

    • Win32diskimager (0.9.5)

    • notepad++

Raspberry Pi End
    • RASPBIAN system

      • Download Link: https://www.raspberrypi.org/downloads/
    • Webpy

    • Python-lxml

    • Python-memcache

    • Apache2

    • Mjpg-streamer

    • RPI. GPIO

    • All the source code of this program

      • Source Address: HTTPS://GITHUB.COM/329703622/WECHATPI
Configuration process Initialization Raspberry Pi using putty login Raspberry Pi

Username: pi
Password:raspberry

Get root Permissions

sudo passwd root
(You need to enter the root password you want to set twice)
sudo passwd --unlock root
Restart Putty When Setup is complete, log in as root

Free up space and set time zones

Log in as root will automatically eject the Raspi-config settings tool, you can also directly enter the raspi-config recall
1. Perform the first item, always select OK
2. Select the fourth item and select the second entry to enter the time zone setting
3. Select Asia--shanghai, OK, change to + 8 time zone


Set static IP

sudo nano /etc/network/interfaces
Put this line
iface eth0 inet dhcp
Replaced by

iface192.168.1.101255.255.255.0192.168.1.1114.114.114.114

Modify the Resolv.config file
sudo nano /etc/resolv.conf
Revision changed to

nameserver114.114.114.114

Otherwise, the domain name may not be resolved under static IP conditions

Update the software source (optional)

nano /etc/apt/sources.list
Delete all content from the original file and replace it with the following:

deb http://mirror.sysu.edu.cn/raspbian/raspbian/ wheezy main contrib non-freedeb-src http://mirror.sysu.edu.cn

Ps: Raspberry Pi Official list of software sources http://www.raspbian.org/RaspbianMirrors
PS2: Several software sources in China

Zhongshan university
http://mirror.sysu.edu.cn/raspbian/raspbian/
China University of Science and Technology
http://mirrors.ustc.edu.cn/raspbian/raspbian/
Tsinghua university
http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/
Hust
http://mirrors.hustunique.com/raspbian/raspbian/
Dalian Neusoft Information Institute Source (North user)
http://mirrors.neusoft.edu.cn/raspbian/raspbian/
Chongqing University Source (Midwest users)
http://mirrors.cqu.edu.cn/Raspbian/raspbian/

Update the cache and upgrade the software

sudo apt-get update && apt-get upgrade

Installation and Configuration

Install all required software, install required packages, and debug successfully
If there is a problem with the debugging process, please refer to the other articles in this blog (appendix), or welcome the message to discuss

Installing the Software
  • Webpy

    git clone git://github.com/webpy/webpy.git
    ln -s `pwd`/webpy/web
    cd /root/webpy
    sudo python setup.py install

  • RPI. GPIO
    (Install Rpi.gpio first need to install Rpi.gpio required Python development Toolkit)

    sudo apt-get install python-dev
    sudo apt-get install python-pip
    sudo pip install rpi.gpio

  • Python-lxml

    sudo apt-get install python-lxml

  • Python-memcache

    sudo apt-get install python-memcache

  • Apache2

    sudo apt-get install apache2

  • Mjpg-streamer
    (Install Mjpg-streamer first need to install a few dependent packages)

    Dependent Packages:
    sudo apt-get install subversion
    sudo apt-get install libv4l-dev
    sudo apt-get install libjpeg8-dev
    sudo apt-get install imagemagick
    (Compile and install mjpg-steamer)
    wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
    unzip mjpg-streamer-code-182.zip
    cd mjpg-streamer-code-182/mjpg-streamer
    make USE_LIBV4L2=true clean all
    make DESTDIR=/usr install

Configure the Router

In the router setup interface, set up a static IP for the Raspberry Pi, or set a static IP on the Raspberry Pi, remembering this IP

Configure the peanut wand (or Peanut Shell Intranet version

If the network environment has a public IP, you can set DDNS on the router (DDNS can search other related articles), if this environment is not available, the Peanut shell Intranet version (software) or peanut stick (hardware) to achieve public address and docking with the common platform.
First apply for a peanut shell domain name, and then log on to the Peanut Stick Management page (http://hsk.oray.com/bang/)
Select the intranet map to add the map, fill in the Raspberry Pi static IP, map the Raspberry Pi 80 port to the domain name, and check the use of the external network 80 port (very important, otherwise unable to complete the docking)
Apply for another peanut shell domain name, map this domain name to the Raspberry Pi 8080 port, still check the use of the external network 80 port

Ps: On the Peanut shell intranet version of the acquisition, you can
http://www.oray.com/activity/140902/
To pay one-yuan certification fee to open the free service
Peanut shell internal version of the installation and peanut stick is similar, it is necessary to note that if the use of Peanut shell intranet version in the work before the need to confirm the Peanut shell Intranet version of normal work and can be normal analysis

Configure Apache2

Because my 80 port needs to be occupied by the public platform, so I can not let the page go 80 ports, need to change the port
nano /etc/apache2/ports.conf
Change listen 80 to listen 8080

Debug camera

Run the "stream.sh" file in the Testcam folder into the git package directory in the Raspberry Pi:
sudo chmod +x stream.sh(The script file must be compiled before it can be run with./filename)
sudo ./stream.sh

When you run the program, if an error occurs, the process is still working because it was running, and it is not possible to run it, you can run Ps-a, view the running process and process ID number, and then use the " kill id号 " kill process

Run the "testcam.html" file in the Git package on your PC, right-click on edit index.html, change to 树莓派ip your Raspberry Pi fixed IP, save, double-tap open testcam.html

See the camera output image to indicate that the camera is working properly.

Application and configuration of public platform test account
    1. Open page http://mp.weixin.qq.com/wiki/home/index.html request a test account for a public platform
    2. Select Test number application on the left | online debug Select interface Test number application
    3. After successful application, enter the management interface
    4. Enter the domain name you applied for in the peanut shell at the URL of the interface configuration information, followed /weixin by
      Fill in tokens with a list of your favorite letters and don't click Submit when you're done.
      (At this point you can download my previous public platform base template for docking, you can successfully docking after the next work to test the network environment is configured to complete
      Article address: http://blog.csdn.net/u010027419/article/details/40835963)
Download and configure the main program
    • Download the full code package on this github and edit it after decompression
      (GIT:HTTPS://GITHUB.COM/329703622/WECHATPI)
    • Fill in the token you just set up and the AppID and Appsecret provided by the test number (Yeekey mentioned later)
    • Fill in the Gpio interface for all of your sensors
      (Sensor debug Reference this blog (or appendix) other articles)
    • After Setup, use WINSCP to put the Raspberry Pi file directory
    • Log in to the Raspberry Pi using putty
    • Change file permissions in the directory where the file is just being executed chmod +x start.sh
    • Perform./start.sh
    • If the message appears, the program runs correctly
    • Click Submit on the Web page of the public platform test account, and if the prompt is successful, the basic configuration of the whole system is successful.

deploying Web pages
    1. Edit the index.html in the file in the GIT package and change it to the IP address of the Raspberry Pi in your Raspberry Pi IP
    2. Upload the index.html to the /var/www directory, replacing the previous index.html
    3. Enter in the browser http://你的树莓派局域网ip:8080/ to try to access
      If the page appears successfully, the Web page deployment succeeds
Set up a public account menu
    1. Select Get access token below the public platform management test account
    2. On the left menu select * Base interface get access token*
    3. At the bottom right, select Debug this interface using the Web Debugging tool
    4. Get access token first
      Before you fill in AppID and secret to manage the data provided on the Test Account page, click Check Questions
    5. The blue Access_token Below is the one that will be used to submit the menu access_token, copy this token
    6. Select the custom menu in the interface type and select the custom menu in the interface list to create the interface. Enter the following interface, fill in just the access_token(access_token has a certain timeliness, time is too long to be re-acquired)
    7. In the body, fill in the contents of the Menu.txt in the Git package, and click Check Questions
    8. The menu creation is successful if Request successful is displayed.

Ps: You can view the effect directly by cancelling the attention number again. Otherwise constrained, it takes 24 hours for the cache to be refreshed before it can be viewed.
PS2: parameter Description

Parameters whether you must Description
button Is The first-level menu array, the number should be one
Sub_button Whether Two-level menu array, the number should be a
Type Is Response Action type for menu
Name Is Menu title, no more than 16 bytes, sub-menu no more than 40 bytes
Key Click Type must Menu key value, for message interface push, no more than 128 bytes
Url The view type must Web links, users click on the menu to open the link, no more than 256 bytes
Apply for Yeelink Internet of Things service
    1. Open http://www.yeelink.net/Registered Account
    2. After landing on the admin home page, your API Key is Yeekey
    3. Add a new device
    4. Remember your device ID when you're finished adding it
    5. Fill in the program with your device ID and yeekey, and change the neighborhood to 自己的yeelink页面 your own page
End & Tips
    • In touch with Python, a very good language
    • Learned to write a blog markdown, too convenient
    • Playing Raspberry Pi, super awesome little computer
    • I bought a lot of fun little things with my money.
    • Have developed a lot of good habits
Appendix
  • Python's public platform base code
    Https://github.com/329703622/raspchat

  • Sensor Debug Code separately
    Https://github.com/329703622/Sensor

  • Raspberry Pi, topsy-public platform – Beginner's chapter
    http://tieba.baidu.com/p/3232803694

  • Raspberry Pi, play public platform – Intermediate
    http://tieba.baidu.com/p/3477722264

  • Using Raspberry Pi with public platform docking (python)
    http://blog.csdn.net/u010027419/article/details/40835963

  • Public Platform button and menu creation
    http://blog.csdn.net/u010027419/article/details/40949065

  • Raspberry Pi Camera related to surveillance
    http://blog.csdn.net/u010027419/article/details/41123709

  • Raspberry Pi Control Stepper motor (python) via Gpio
    http://blog.csdn.net/u010027419/article/details/41518321

  • Raspberry Pi Connection dht11 temperature sensor get temperature (python)
    http://blog.csdn.net/u010027419/article/details/41722261

  • Raspberry Pi set up HTTP Server Mount Web page
    http://blog.csdn.net/u010027419/article/details/42343057

  • HTML page compatible with mobile browser (to solve the problem of small display page)
    http://blog.csdn.net/u010027419/article/details/44857827

Running on Raspberry Pi smart home prototype

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.