Uživatelské nástroje

Nástroje pro tento web


zarizeni:raspberry_pi

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Obě strany předchozí revizePředchozí verze
Následující verze
Předchozí verze
zarizeni:raspberry_pi [2017/01/13 22:39] – [Raspberry PI + SHT21] monkeytechzarizeni:raspberry_pi [2022/12/16 10:35] (aktuální) – [Raspberry PI s více DS18B20 na jedné sběrnici] multitricker
Řádek 19: Řádek 19:
  
 <code bash> <code bash>
-#! /bin/bash+#!/bin/bash
  
 # This script reads the temperature from all connected 1-wire temperature # This script reads the temperature from all connected 1-wire temperature
Řádek 113: Řádek 113:
 </WRAP> </WRAP>
 <code bash> <code bash>
-#! /bin/bash+#!/bin/bash
  
 # This script reads the temperature from all connected 1-wire temperature # This script reads the temperature from all connected 1-wire temperature
Řádek 126: Řádek 126:
  
 SERVER="tst.tmep.cz" SERVER="tst.tmep.cz"
 +NAZEVCIDLA="cidlo"
 +NAZEVMERENI="&mojemereni"
  
 W1DIR="/sys/bus/w1/devices" W1DIR="/sys/bus/w1/devices"
Řádek 181: Řádek 183:
                 # Write result of this sensor                 # Write result of this sensor
                 echo "$DEVICE=$INTEGER.$FRACTION"                 echo "$DEVICE=$INTEGER.$FRACTION"
-                curl -s -H "Cache-Control: no-cache" $SERVER/?$DEVICE=$INTEGER.$FRACTION > /dev/null+                curl -s -H "Cache-Control: no-cache" $SERVER/?$NAZEVCIDLA=$DEVICE$NAZEVMERENI=$INTEGER.$FRACTION > /dev/null
             else             else
                 # A CRC was found, show error message instead                 # A CRC was found, show error message instead
Řádek 231: Řádek 233:
     temperature = round(temperature, 1)     temperature = round(temperature, 1)
     humidity = round(humidity, 1)     humidity = round(humidity, 1)
-    url = 'http://' + SERVER + '?' + GUID + '=' + str(temperature) + '&humV='+    url = 'http://' + SERVER + '?' + GUID + '=' + str(temperature) + '&humV='str(humidity) 
-    print url+    print(url)
     urllib2.urlopen(url)     urllib2.urlopen(url)
 else: else:
Řádek 238: Řádek 240:
     sys.exit(1)     sys.exit(1)
 </code> </code>
-Změňte souboru práva pro čtení a můžete ho spustit:+Přidejte souboru právo spuštění a můžete ho vyzkoušet:
 <code> <code>
 chmod +x ./tmep_DHT.py chmod +x ./tmep_DHT.py
Řádek 305: Řádek 307:
     humidity = round(humidity, 1)     humidity = round(humidity, 1)
     url = 'http://' + SERVER + '?' + GUID + '=' + str(temperature) + '&humV=' + str(humidity)     url = 'http://' + SERVER + '?' + GUID + '=' + str(temperature) + '&humV=' + str(humidity)
-    print url+    print(url)
     urllib2.urlopen(url)     urllib2.urlopen(url)
  
Řádek 324: Řádek 326:
 <code> <code>
 *              /home/pi/sht21_python/tmep_sht21.py > /dev/null 2>&1 *              /home/pi/sht21_python/tmep_sht21.py > /dev/null 2>&1
 +</code>
 +
 +===== Raspberry s HTU21DF a OLED displejem =====
 +
 +Příklad od ''mikroma''.
 +
 +**Web autora příkladu:** http://mikrom.cz/\\
 +**Kontakt na autora:** [[mikrom@mikrom.cz]]
 +
 +{{ :zarizeni:pasted:20180918-091506.png?400 }}
 +
 +<code python>
 +#!/usr/bin/env python
 +# -*- coding: utf-8 -*-
 +
 +# Author: mikrom, 2018
 +#
 +# Based on:
 +# https://github.com/rm-hull/luma.oled
 +# https://github.com/dalexgray/RaspberryPI_HTU21DF
 +# https://github.com/al45tair/netifaces
 +# https://github.com/httplib2/httplib2
 +#
 +# HTU21DF needs to run $sudo pigpiod
 +# tmep.sh added to $sudo nano /etc/rc.local
 +
 +from oled.serial import i2c
 +from oled.device import sh1106
 +from oled.render import canvas
 +from PIL import ImageFont, ImageDraw
 +import time #from time import sleep <- do not use this
 +import HTU21DF
 +import netifaces as ni
 +import httplib2
 +
 +# Settings
 +sleep = 5                                    # Time between two measuring cycles (seconds)
 +url = "http://tmep.server.url/?"             # Server url (ending with question mark)
 +guid = "guid"                                # Secret guid
 +rotation = 0                                 # Display rotation 0=no, 1=90, 2=180, 3=270
 +fontname = "BRBELRT0.ttf"                    # Font name
 +fontsize = 18                                # Font size
 +serial = i2c(port=1, address=0x3C)           # Do not touch
 +device = sh1106(serial, rotate=rotation)     # Change it to ssd1306 if you have more common display
 +ni.ifaddresses('eth0'                      # Probably no need to change it (maybe to wlan0)
 +font = ImageFont.truetype("/home/pi/fonts/" + fontname, fontsize) # specify where your fonts are stored
 +
 +# Run infinitely
 +while True:
 +  # Get temperature and humidity from HTU21D
 +  HTU21DF.htu_reset                          # Reset sensor first
 +  temp = "%.1f" % HTU21DF.read_temperature() # Round float to 1 decimal and convert to string
 +  time.sleep(1)                              # Sensor is slow, so add some delay
 +  hum = "%.0f" % HTU21DF.read_humidity()     # Round float to 0 decimal and convert to string
 +  print("Temp=" + temp + "C")
 +  print("Hum=" + hum + "%")
 +
 +  # Get IP address from netifaces
 +  ip = ni.ifaddresses('eth0')[ni.AF_INET][0]['addr']
 +  print("IP=" + ip)
 +
 +  # Display data on OLED
 +  with canvas(device) as draw:
 +    temperature = "Temp: " + temp + u"\N{DEGREE SIGN}C"        # Prepare string to display. Degree sign is little bit challenging to add :)
 +    w, h = font.getsize(temperature)                           # Get dimensions of the string
 +    draw.text(((128-w)/2,0), temperature, font=font, fill=255) # Just some positioning, it is centered by x and y=0
 +    humidity = "Hum: " + hum + "%"                             # Prepare string to display. 
 +    w, h = font.getsize(humidity)                              # Get dimensions of the string
 +    draw.text(((128-w)/2,20), humidity, font=font, fill=255)   # Just some positioning, it is centered by x and y=20
 +    w, h = font.getsize(ip)                                    # Get dimensions of the string
 +    draw.text(((128-w)/2,40), ip, font=font, fill=255)         # Just some positioning, it is centered by x and y=40
 +
 +  # Send data to tmep server
 +  requesturl = url + guid + "=" + temp + "&humV=" + hum
 +  print("Send to: " + requesturl)
 +  resp, content = httplib2.Http().request(requesturl)
 +  if resp.status == 200:
 +    print("Send OK")
 +  else:
 +    print("Send Error")
 +
 +  # Take a nap
 +  print("Go to sleep for %d s..." % sleep)
 +  time.sleep(sleep)
 </code> </code>