树莓派应用实例6:测量土壤湿度(改进WEB发布)
生活随笔
收集整理的這篇文章主要介紹了
树莓派应用实例6:测量土壤湿度(改进WEB发布)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上一篇(https://blog.csdn.net/fm0517/article/details/80967569)通過Python代碼實現了通過YL-69模塊監測土壤濕度。本片實現通過Django發布監測結果。
1. 前期準備
已完成上一篇的內容:https://blog.csdn.net/fm0517/article/details/80949387
2. 創建soil應用
cd /home/pi/helloworld python manage.py startapp soil3. 配置Django路徑
cd /home/pi/helloworld/helloworld vi urls.py from django.conf.urls import include, url from django.contrib import admin from helloworld.view import hellourlpatterns = [url(r'^hello/$', hello),url(r'^raspberrypistate/', include('raspberrypistate.urls',namespace="raspberrypistate")),url(r'^temhum/', include('temhum.urls',namespace="temhum")),url(r'^temhum2/', include('temhum2.urls',namespace="temhum2")),url(r'^illuminance/', include('illuminance.urls',namespace="illuminance")),url(r'^soil/', include('soil.urls',namespace="soil")), #添加這一行url(r'^admin/', admin.site.urls), ]4. 配置soil的urls.py
cd /home/pi/helloworld/soil vi urls.py from django.conf.urls import urlfrom . import viewsurlpatterns = [url(r'^$', views.index, name='index'), ]5. 配置soil的views.py
cd /home/pi/helloworld/soil vi views.py # -*- coding:utf-8 -*- from django.http import HttpResponse from . import soil# Create your views here. def index(request):sh=soil.getSoilHum()return HttpResponse(sh)5. 編寫代碼soil.py
cd /home/pi/helloworld/soil vi soil.py #!/usr/bin/python # -*- coding: UTF-8 -*- import RPi.GPIO as GPIO import timedef getSoilHum():channel = 21 #管腳40GPIO.setmode(GPIO.BCM)GPIO.setup(channel, GPIO.IN)if GPIO.input(channel) == GPIO.LOW:return "土壤檢測結果:潮濕"else:return "土壤檢測結果:干燥"6. 重啟服務,進行測試
sudo systemctl restart emperor.uwsgi.service在樹莓派瀏覽器輸入 http://127.0.0.1/soil
或者在電腦瀏覽器輸入 http://raspberrypi/soil
總結
以上是生活随笔為你收集整理的树莓派应用实例6:测量土壤湿度(改进WEB发布)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信用卡逾期如何处理
- 下一篇: 年金是什么意思?个人年金有什么用?