zarizeni:raspberry_pi
Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Obě strany předchozí revizePředchozí verzeNásledující verze | Předchozí verzePoslední revizeObě strany příští revize | ||
zarizeni:raspberry_pi [2017/01/13 22:37] – [Raspberry PI + SHT21] monkeytech | zarizeni:raspberry_pi [2022/12/15 23:01] – 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: | ||
</ | </ | ||
<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 181: | Řádek 181: | ||
# Write result of this sensor | # Write result of this sensor | ||
echo " | echo " | ||
- | curl -s -H " | + | curl -s -H " |
else | else | ||
# A CRC was found, show error message instead | # A CRC was found, show error message instead | ||
Řádek 231: | Řádek 231: | ||
temperature = round(temperature, | temperature = round(temperature, | ||
humidity = round(humidity, | humidity = round(humidity, | ||
- | url = ' | + | url = ' |
- | print url | + | print(url) |
urllib2.urlopen(url) | urllib2.urlopen(url) | ||
else: | else: | ||
Řádek 238: | Řádek 238: | ||
sys.exit(1) | sys.exit(1) | ||
</ | </ | ||
- | Změňte | + | Přidejte |
< | < | ||
chmod +x ./ | chmod +x ./ | ||
Řádek 305: | Řádek 305: | ||
humidity = round(humidity, | humidity = round(humidity, | ||
url = ' | url = ' | ||
- | print url | + | print(url) |
urllib2.urlopen(url) | urllib2.urlopen(url) | ||
Řádek 313: | Řádek 313: | ||
sys.exit(1) | sys.exit(1) | ||
</ | </ | ||
- | Změňte souboru | + | Přidejte |
< | < | ||
chmod +x ./ | chmod +x ./ | ||
Řádek 324: | Řádek 324: | ||
< | < | ||
* | * | ||
+ | </ | ||
+ | |||
+ | ===== Raspberry s HTU21DF a OLED displejem ===== | ||
+ | |||
+ | Příklad od '' | ||
+ | |||
+ | **Web autora příkladu: | ||
+ | **Kontakt na autora:** [[mikrom@mikrom.cz]] | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | # Author: mikrom, 2018 | ||
+ | # | ||
+ | # Based on: | ||
+ | # https:// | ||
+ | # https:// | ||
+ | # https:// | ||
+ | # https:// | ||
+ | # | ||
+ | # HTU21DF needs to run $sudo pigpiod | ||
+ | # tmep.sh added to $sudo nano / | ||
+ | |||
+ | 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 = " | ||
+ | guid = " | ||
+ | rotation = 0 # Display rotation 0=no, 1=90, 2=180, 3=270 | ||
+ | fontname = " | ||
+ | fontsize = 18 # Font size | ||
+ | serial = i2c(port=1, address=0x3C) | ||
+ | device = sh1106(serial, | ||
+ | ni.ifaddresses(' | ||
+ | font = ImageFont.truetype("/ | ||
+ | |||
+ | # Run infinitely | ||
+ | while True: | ||
+ | # Get temperature and humidity from HTU21D | ||
+ | HTU21DF.htu_reset | ||
+ | temp = " | ||
+ | time.sleep(1) | ||
+ | hum = " | ||
+ | print(" | ||
+ | print(" | ||
+ | |||
+ | # Get IP address from netifaces | ||
+ | ip = ni.ifaddresses(' | ||
+ | print(" | ||
+ | |||
+ | # Display data on OLED | ||
+ | with canvas(device) as draw: | ||
+ | temperature = "Temp: " + temp + u" | ||
+ | w, h = font.getsize(temperature) | ||
+ | draw.text(((128-w)/ | ||
+ | humidity = "Hum: " + hum + " | ||
+ | w, h = font.getsize(humidity) | ||
+ | draw.text(((128-w)/ | ||
+ | w, h = font.getsize(ip) | ||
+ | draw.text(((128-w)/ | ||
+ | |||
+ | # Send data to tmep server | ||
+ | requesturl = url + guid + " | ||
+ | print(" | ||
+ | resp, content = httplib2.Http().request(requesturl) | ||
+ | if resp.status == 200: | ||
+ | print(" | ||
+ | else: | ||
+ | print(" | ||
+ | |||
+ | # Take a nap | ||
+ | print(" | ||
+ | time.sleep(sleep) | ||
</ | </ |