kokoichi206 / til

0 stars 1 forks source link

Grafana とか #8

Open kokoichi206 opened 1 year ago

kokoichi206 commented 1 year ago

https://grafana.com/get/?plcmt=top-nav&cta=downloads&tab=self-managed

kokoichi206 commented 1 year ago

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

sudo apt update && sudo apt install -y grafana

sudo systemctl unmask grafana-server.service sudo systemctl start grafana-server sudo systemctl enable grafana-server.service

sudo systemctl restart grafana-server

kokoichi206 commented 1 year ago

Links

kokoichi206 commented 1 year ago

湿度計

import RPi.GPIO as GPIO
import dht11
import influxdb
import datetime
import time

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin=17)

db = influxdb.InfluxDBClient(
    host='localhost',
    port=8086,
    database='sensortag'
)

def write_to_influxdb(data):
    points = [{
        'measurement': 'sensortag',
        'time': datetime.datetime.utcnow(),
        'fields': data
    }]
    db.write_points(points)

while True:
    result = instance.read()
    if result.is_valid():
        data = {}
        data['temperature'] = result.temperature
        data['humidity'] = result.humidity
        write_to_influxdb(data)
    else:
        print("Error: %d" % result.error_code)
    time.sleep(15)