〇Stellariumの画面
インストール方法
シェルから以下のコマンド実行しますsudo dnf -y install stellarium
sudo dnf -y install stellarium
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
from grove.grove_rotary_angle_sensor import GroveRotaryAngleSensor
import time
PIN_A0 = 0
sensor = GroveRotaryAngleSensor( PIN_A0)
while True:
print("value: {}".format(sensor.value))
time.sleep(1)
python3 grove_rotary_angle_value.py
sudo dnf -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install flathub org.kde.kalzium
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
pip3 install paho-mqtt
import paho.mqtt.client as mqtt
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received: {}".format(msg.topic))
print(str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(host, port, secs_keep_alive)
client.loop_forever()
python3 mosquitto_sub_grove_temp_sensor.py
import paho.mqtt.publish as publish
from grove.factory import Factory
import time
PIN_A0 = 0
sensor = Factory.getTemper("NTC-ADC", PIN_A0)
def read_grove_temp_sensor():
return sensor.temperature
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
val = read_grove_temp_sensor()
publish.single(topic, "grove_temp_sensor:{}".format(val), hostname=host, port=port, keepalive=secs_keep_alive)
python3 mosquitto_pub_grove_temp_sensor.py
sudo dnf -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install flathub org.gnome.Genius
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
pip3 install flask
from flask import Flask, jsonify, request
from grove.factory import Factory
import time
app = Flask(__name__)
PIN_A0 = 0
sensor = Factory.getTemper("NTC-ADC", PIN_A0)
@app.route('/grove_temp_sensor')
def get_grove_temp_sensor():
return {"temperature":sensor.temperature}
export FLASK_APP=app.py
~/.local/bin/flask run -h 0.0.0.0
sudo dnf -y install mariadb mariadb-server
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
sudo mysql -uroot -e "SET PASSWORD = PASSWORD('root'); FLUSH PRIVILEGES;"
※パスワードは適宜変更してくださいsudo dnf -y install libXScrnSaver
wget https://github.com/OmniDB/OmniDB/releases/download/3.0.3b/omnidb-app-3.0.3b_linux_x86_64.rpm
sudo dnf -y install omnidb-app-3.0.3b_linux_x86_64.rpm
create table grove_temperature_sensor
(
device_name varchar(30) not null,
data_ts timestamp not null,
temperature float,
constraint pk_grove_temperature_sensor primary key (device_name, data_ts)
);
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
pip3 install psycopg2-binary
import os
import psycopg2
import psycopg2.extras
from grove.factory import Factory
import time
PIN_A0 = 0
sensor = Factory.getTemper("NTC-ADC", PIN_A0)
device_name = 'test device'
sql = """insert into grove_temperature_sensor values (%s, current_timestamp, %s)"""
conn = psycopg2.connect(host=os.environ['PG_HOST'], port=os.environ["PG_PORT"], database=os.environ['PG_DB'], user=os.environ['PG_USER'], password=os.environ['PG_PASS'])
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(sql , (device_name, sensor.temperature))
conn.commit()
export PG_HOST=データベースホスト名またはIP
export PG_PORT=データベースのポート番号(※通常5432)
export PG_DB=データベース名
export PG_USER=ユーザ名
export PG_PASS=パスワード
python3 record_grove_temperature_sensor.py
sudo mkdir -p /opt/openscad
cd /opt/openscad
sudo wget https://files.openscad.org/OpenSCAD-2021.01-x86_64.AppImage
sudo chmod +x OpenSCAD-2021.01-x86_64.AppImage
cat << EOF | sudo tee /usr/share/applications/openscad.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/openscad/OpenSCAD-2021.01-x86_64.AppImage
Name=OpenSCAD
EOF
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
from grove.factory import Factory
import time
PIN_A0 = 0
sensor = Factory.getTemper("NTC-ADC", PIN_A0)
while True:
print("temp: {:.1f}C".format(sensor.temperature))
time.sleep(1)
python3 grove_temp.py
sudo dnf -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install flathub org.gnome.Notes
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/grovepy_mqtt
cd ~/grovepy_mqtt
pipenv --python 3
pipenv install paho-mqtt Seeed-grove.py==0.3
pipenv shell
import paho.mqtt.client as mqtt
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received: {}".format(msg.topic))
print(str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(host, port, secs_keep_alive)
client.loop_forever()
python3 mosquitto_sub_grove_light_sensor.py
import paho.mqtt.publish as publish
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import time
PIN_A0 = 0
sensor = GroveLightSensor(PIN_A0)
def read_grove_light_sensor():
return sensor.light
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
val = read_grove_light_sensor()
publish.single(topic, "grove_light_sensor:{}".format(val), hostname=host, port=port, keepalive=secs_keep_alive)
python3 mosquitto_pub_grove_light_sensor.py
sudo mkdir -p /opt/stacer
cd /opt/stacer
sudo wget https://github.com/oguzhaninan/Stacer/releases/download/v1.1.0/Stacer-1.1.0-x64.AppImage
sudo chmod +x Stacer-1.1.0-x64.AppImage
cat << EOF | sudo tee /usr/share/applications/stacer.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/stacer/Stacer-1.1.0-x64.AppImage
Name=Stacer
Categories=Accessories;
EOF
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/grovepi_flask
cd ~/grovepi_flask
pipenv --python 3
pipenv install Seeed-grove.py==0.3 flask
pipenv shell
from flask import Flask, jsonify, request
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import time
app = Flask(__name__)
@app.route('/grove_light_sensor')
def get_grove_light_sensor():
PIN_A0 = 0
sensor = GroveLightSensor(PIN_A0)
return {"lightness":sensor.light}
export FLASK_APP=app.py
flask run -h 0.0.0.0
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload
sudo dnf -y install mariadb mariadb-server
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
sudo mysql -uroot -e "SET PASSWORD = PASSWORD('root'); FLUSH PRIVILEGES;"
mysql -uroot -proot -e "CREATE DATABASE kanboard DEFAULT CHARACTER SET utf8mb4;"
mysql -uroot -proot -e "CREATE USER kanboard@localhost IDENTIFIED BY 'kanboard';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON kanboard.* TO 'kanboard'@'localhost';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"
sudo dnf install -y httpd \
php \
php-mysqlnd \
php-json \
php-opcache \
php-xml \
php-dom \
php-mbstring \
php-gd \
php-curl
sudo systemctl enable php-fpm
sudo systemctl enable httpd
sudo setenforce 0
sudo getenforce
sudo sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
wget https://github.com/kanboard/kanboard/archive/v1.2.18.zip
unzip v1.2.18.zip
sudo mv kanboard* /opt/kanboard
cp /opt/kanboard/config.default.php /opt/kanboard/config.php
sed -i -e "s#define('DB_DRIVER', 'sqlite');#define('DB_DRIVER', 'mysql');#" /opt/kanboard/config.php
sed -i -e "s#define('DB_USERNAME', 'root');#define('DB_USERNAME', 'kanboard');#" /opt/kanboard/config.php
sed -i -e "s#define('DB_PASSWORD', '');#define('DB_PASSWORD', 'kanboard');#" /opt/kanboard/config.php
sudo chown -R apache:apache /opt/kanboard
sudo ln -s /opt/kanboard/ /var/www/html/
sudo systemctl restart httpd
create table grove_light_sensor
(
device_name varchar(30) not null,
data_ts timestamp not null,
lightness float,
constraint pk_grove_light_sensor primary key (device_name, data_ts)
);
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
sudo apt-get -y install libpq-dev
mkdir -p ~/grovepi_pg
cd ~/grovepi_pg
pipenv --python 3
pipenv install Seeed-grove.py==0.3 psycopg2-binary
pipenv shell
import os
import psycopg2
import psycopg2.extras
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import time
PIN_A0 = 0
sensor = GroveLightSensor(PIN_A0)
device_name = 'test device'
sql = """insert into grove_light_sensor values (%s, current_timestamp, %s)"""
conn = psycopg2.connect(host=os.environ['PG_HOST'], port=os.environ["PG_PORT"], database=os.environ['PG_DB'], user=os.environ['PG_USER'], password=os.environ['PG_PASS'])
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(sql , (device_name, sensor.light))
conn.commit()
export PG_HOST=データベースホスト名またはIP
export PG_PORT=データベースのポート番号(※通常5432)
export PG_DB=データベース名
export PG_USER=ユーザ名
export PG_PASS=パスワード
python3 record_grove_light_sensor.py
sudo mkdir -p /opt/glabels
cd /opt/glabels
sudo wget https://github.com/jimevins/glabels-qt/releases/download/glabels-3.99-master564/glabels-3.99-master564-x86_64.AppImage
sudo chmod +x glabels-3.99-master564-x86_64.AppImage
cat << EOF | sudo tee /usr/share/applications/glabels.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/glabels/glabels-3.99-master564-x86_64.AppImage
Name=gLabes
Categories=Office;
EOF
wget http://www.geogebra.net/linux/rpm/x86_64/geogebra5-5.0.636.0-2670.x86_64.rpm
sudo dnf -y install ./geogebra5-5.0.636.0-2670.x86_64.rpm
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/dht11_mqtt
cd ~/dht11_mqtt
pipenv --python 3
pipenv install paho-mqtt dht11
pipenv shell
import paho.mqtt.client as mqtt
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received: {}".format(msg.topic))
print(str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(host, port, secs_keep_alive)
client.loop_forever()
python3 mosquitto_sub_dht11.py
import paho.mqtt.publish as publish
import RPi.GPIO as GPIO
import dht11
# initialize...
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
def read_dht11():
data = ""
while True:
instance = dht11.DHT11(pin=14)
result = instance.read()
if result.is_valid():
data = "{},{}".format(result.temperature, result.humidity)
break
return data
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
val = read_dht11()
publish.single(topic, "dht11:{}".format(val), hostname=host, port=port, keepalive=secs_keep_alive)
python3 mosquitto_pub_dht11.py
SHAFT_DIAMETER=3;
SHAFT_DISTANCE=5;
SHAFT_HEIGHT=3;
CUBE_H=10;
NUM_SHAFT_W=4;
NUM_SHAFT_D=2;
OFFSET=1;
translate([0, 0, 0])
linear_extrude(height=CUBE_H){
square([NUM_SHAFT_W*SHAFT_DISTANCE, NUM_SHAFT_D*SHAFT_DISTANCE]);
}
for( lw = [0 : NUM_SHAFT_W-1] ){
for( ld = [0 : NUM_SHAFT_D-1] ){
translate([SHAFT_DISTANCE*lw+SHAFT_DIAMETER/2+OFFSET, SHAFT_DISTANCE*ld+SHAFT_DIAMETER/2+OFFSET, CUBE_H])
linear_extrude(height=SHAFT_HEIGHT){
circle(SHAFT_DIAMETER/2, $fn=50);
}
}
}
wget https://downloads.vivaldi.com/stable/vivaldi-stable-3.7.2218.52-1.x86_64.rpm
sudo dnf -y install vivaldi-stable-3.7.2218.52-1.x86_64.rpm
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/dht11_flask
cd ~/dht11_flask
pipenv --python 3
pipenv install dht11 flask
pipenv shell
from flask import Flask, jsonify, request
import RPi.GPIO as GPIO
import dht11
# initialize...
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
app = Flask(__name__)
@app.route('/dht11')
def get_dht11():
data = {}
while True:
instance = dht11.DHT11(pin=14)
result = instance.read()
if result.is_valid():
data = {"temperature":result.temperature, "humidity":result.humidity}
break
return jsonify(data)
export FLASK_APP=app.py
flask run -h 0.0.0.0
sudo mkdir -p /opt/freecad
cd /opt/freecad
sudo dnf -y install libXScrnSaver
sudo wget https://github.com/FreeCAD/FreeCAD/releases/download/0.19.1/FreeCAD_0.19-24276-Linux-Conda_glibc2.12-x86_64.AppImage
sudo chmod +x FreeCAD_0.19-24276-Linux-Conda_glibc2.12-x86_64.AppImage
cat << EOF | sudo tee /usr/share/applications/freecad.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/freecad/FreeCAD_0.19-24276-Linux-Conda_glibc2.12-x86_64.AppImage
Name=FreeCAD
Categories=Development;
EOF
create table dht11_sensor
(
device_name varchar(30) not null,
data_ts timestamp not null,
temperature float,
humidity float,
constraint pk_dht11_sensor primary key (device_name, data_ts)
);
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
sudo apt-get -y install libpq-dev
mkdir -p ~/dht11_pg
cd ~/dht11_pg
pipenv --python 3
pipenv install dht11 psycopg2-binary
pipenv shell
import os
import psycopg2
import psycopg2.extras
import RPi.GPIO as GPIO
import dht11
# initialize...
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
while True:
instance = dht11.DHT11(pin=14)
result = instance.read()
if result.is_valid():
print("Temperature: {:.1f}(C)".format(result.temperature))
print("Humidity: {:.1f}(%)".format(result.humidity))
device_name = 'test device'
sql = """insert into dht11_sensor values (%s, current_timestamp, %s, %s)"""
conn = psycopg2.connect(host=os.environ['PG_HOST'], port=os.environ["PG_PORT"], database=os.environ['PG_DB'], user=os.environ['PG_USER'], password=os.environ['PG_PASS'])
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(sql , (device_name, result.temperature, result.humidity))
conn.commit()
break
GPIO.cleanup()
export PG_HOST=データベースホスト名またはIP
export PG_PORT=データベースのポート番号(※通常5432)
export PG_DB=データベース名
export PG_USER=ユーザ名
export PG_PASS=パスワード
python record_dht11.py
cd /opt
sudo wget https://ftp.nluug.nl/pub/graphics/blender/release/Blender2.92/blender-2.92.0-linux64.tar.xz
sudo tar Jxfv blender-2.92.0-linux64.tar.xz
cat << EOF | sudo tee /usr/share/applications/blender.desktop
[Desktop Entry]
Type=Application
Version=1.0
Name=Blender
Icon=/opt/blender-2.92.0-linux64/blender.svg
Exec=/opt/blender-2.92.0-linux64/blender
Categories=Graphics;
EOF
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/dht11
cd ~/dht11
pipenv --python 3
pipenv install dht11
pipenv shell
import RPi.GPIO as GPIO
import dht11
# initialize...
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
# read data using pin 14
instance = dht11.DHT11(pin=14)
result = instance.read()
if result.is_valid():
print("Temperature: {:.1f}(C)".format(result.temperature))
print("Humidity: {:.1f}(%)".format(result.humidity))
GPIO.cleanup()
python3 get_temp_humidity.py
sudo mkdir -p /opt/rawtherapee
cd /opt/rawtherapee
sudo wget https://rawtherapee.com/shared/builds/linux/RawTherapee_5.8.AppImage
sudo chmod +x RawTherapee_5.8.AppImage
cat << EOF | sudo tee /usr/share/applications/rawtherapee.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/rawtherapee/RawTherapee_5.8.AppImage
Name=RawTherapee
Categories=Graphics;
EOF
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/smbus_flask_mcp3425
cd ~/smbus_flask_mcp3425
pipenv --python 3
pipenv install flask smbus
pipenv shell
from flask import Flask, jsonify, request
import smbus
import time
i2c = smbus.SMBus(1)
addr_mcp3425=0x68
FIELD_PGA_GAIN_1X = 0x00 # gain 1X
FIELD_SAMPLE_RATE_15SPS_16BIT = 0x08 # 15SPS 16bit sampling
FIELD_CONV_MODE = 0x00 # one-shot
FIELD_READY = 0x80
def read_cds():
i2c.write_byte(addr_mcp3425, FIELD_PGA_GAIN_1X | FIELD_SAMPLE_RATE_15SPS_16BIT | FIELD_CONV_MODE| FIELD_READY)
time.sleep(0.15)
dat = i2c.read_i2c_block_data(addr_mcp3425, 0x00, 3)
val = (dat[0] << 8) | dat[1]
return val
app = Flask(__name__)
@app.route('/lightness')
def get_lightness():
val = read_cds()
return jsonify({"lightness":val})
export FLASK_APP=app.py
flask run -h 0.0.0.0
sudo yum -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install https://flathub.org/repo/appstream/org.bluej.BlueJ.flatpakref
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/smbus_mqtt
cd ~/smbus_mqtt
pipenv --python 3
pipenv install paho-mqtt smbus
pipenv shell
import paho.mqtt.client as mqtt
import time
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received: {}".format(msg.topic))
print(str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(host, port, secs_keep_alive)
client.loop_forever()
python3 mosquitto_sub_cds.py
import paho.mqtt.publish as publish
import smbus
import time
i2c = smbus.SMBus(1)
addr_mcp3425=0x68
FIELD_PGA_GAIN_1X = 0x00 # gain 1X
FIELD_SAMPLE_RATE_15SPS_16BIT = 0x08 # 15SPS 16bit sampling
FIELD_CONV_MODE = 0x00 # one-shot
FIELD_READY = 0x80
def read_cds():
i2c.write_byte(addr_mcp3425, FIELD_PGA_GAIN_1X | FIELD_SAMPLE_RATE_15SPS_16BIT | FIELD_CONV_MODE| FIELD_READY)
time.sleep(0.15)
dat = i2c.read_i2c_block_data(addr_mcp3425, 0x00, 3)
val = (dat[0] << 8) | dat[1]
return val
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
val = read_cds()
publish.single(topic, "cds:{}".format(val), hostname=host, port=port, keepalive=secs_keep_alive)
python3 mosquitto_pub_cds.py
import time
from machine import Pin
from ir_rx.nec import NEC_8
# オプトサプライ赤外線リモコンのデータと対応するボタンのメッセージ
keydata = {
0xD8:"Power button",
0xF8:"A button",
0x78:"B button",
0x58:"C button",
0xB1:"Upper left button",
0xA0:"Up button",
0x21:"Upper right button",
0x10:"Left button",
0x20:"Center button",
0x80:"Right button",
0x11:"Bottom left button",
0x00:"Down button",
0x81:"Bottom right button",
0xFF:"N/A"
}
last_code=0xFF
# 赤外線の信号を受信時に呼び出されるコールバック関数
def callback(data, addr, ctrl):
global last_code
if data < 0: # repeat code -> 同じキーが繰り返しが押されたときの処理
print(keydata[last_code])
else:
last_code = data
print(keydata[data]) # キーデータに対応する文字列を表示します
# 2番ピンを使用するようにして、NEC 8bitクラスを初期化。上記のcallback関数を登録します。
ir = NEC_8(Pin(2, Pin.IN), callback)
# 無限ループ、信号を受信するとcallback関数が呼ばれます。
while True:
time.sleep_ms(1000)
import time
from machine import Pin
from ir_rx.nec import NEC_8
from machine import PWM
# オプトサプライ赤外線リモコンのデータと対応するボタンのメッセージ
keydata = {
0xD8:"Power button",
0xF8:"A button",
0x78:"B button",
0x58:"C button",
0xB1:"Upper left button",
0xA0:"Up button",
0x21:"Upper right button",
0x10:"Left button",
0x20:"Center button",
0x80:"Right button",
0x11:"Bottom left button",
0x00:"Down button",
0x81:"Bottom right button",
0xFF:"N/A"
}
last_code=0xFF
# 赤外線の信号を受信時に呼び出されるコールバック関数
def callback(data, addr, ctrl):
global last_code
if data < 0: # repeat code -> 同じキーが繰り返しが押されたときの処理
print(keydata[last_code])
else:
last_code = data
print(keydata[data]) # キーデータに対応する文字列を表示します
pwm = PWM(machine.Pin(16, machine.Pin.OUT))
pwm.freq(1000)
#led1 = machine.PWM( machine.Pin(16, machine.Pin.OUT))
led2 = machine.Pin(17, machine.Pin.OUT)
led3 = machine.Pin(18, machine.Pin.OUT)
# 2番ピンを使用するようにして、NEC 8bitクラスを初期化。上記のcallback関数を登録します。
ir = NEC_8(Pin(2, Pin.IN), callback)
state_b = False
cnt = 0
# 無限ループ、信号を受信するとcallback関数が呼ばれます。
while True:
time.sleep_ms(1)
cnt = cnt + 1
if last_code == 0x58:
pwm.duty_u16(65535)
elif last_code == 0xD8:
pwm.duty_u16(0)
if last_code == 0xF8:
led3.value(1)
elif last_code == 0xD8:
led3.value(0)
# last_codeはグルーバル変数でcallback関数にいつでも書き換えられるので、値をlocal_last_codeに保持
#local_last_code = last_code
#while local_last_code == 0x78:
if last_code == 0x78:
state_b = True
elif last_code == 0xD8:
state_b = False
led2.value(0)
if state_b == True:
if cnt % 1000 < 500:
led2.value(1)
else:
led2.value(0)
import time
from machine import Pin
from ir_rx.nec import NEC_8
from machine import PWM
# オプトサプライ赤外線リモコンのデータと対応するボタンのメッセージ
keydata = {
0xD8:"Power button",
0xF8:"A button",
0x78:"B button",
0x58:"C button",
0xB1:"Upper left button",
0xA0:"Up button",
0x21:"Upper right button",
0x10:"Left button",
0x20:"Center button",
0x80:"Right button",
0x11:"Bottom left button",
0x00:"Down button",
0x81:"Bottom right button",
0xFF:"N/A"
}
last_code=0xFF
last_ticks = time.ticks_ms()
# 赤外線の信号を受信時に呼び出されるコールバック関数
def callback(data, addr, ctrl):
global last_code
global last_ticks
last_ticks = time.ticks_ms() # callback関数が呼ばれた最後の時間を保存
if data < 0: # repeat code -> 同じキーが繰り返しが押されたときの処理
print(keydata[last_code])
else:
last_code = data
#print(keydata[data]) # キーデータに対応する文字列を表示します
pwm = PWM(machine.Pin(16, machine.Pin.OUT))
pwm.freq(1000)
#led1 = machine.PWM( machine.Pin(16, machine.Pin.OUT))
led2 = machine.Pin(17, machine.Pin.OUT)
led3 = machine.Pin(18, machine.Pin.OUT)
# 2番ピンを使用するようにして、NEC 8bitクラスを初期化。上記のcallback関数を登録します。
ir = NEC_8(Pin(2, Pin.IN), callback)
# 無限ループ、信号を受信するとcallback関数が呼ばれます。
state = False
state_cnt = 0
threshold = 400 # コールバック関数が最後に呼ばれて400ms経つと消灯処理を行います
while True:
time.sleep_ms(100)
# Bボタン
if last_code == 0x78 and time.ticks_ms() - last_ticks < threshold:
state_cnt = state_cnt + 1
if state_cnt >= 10:
state_cnt = 0
if state:
pwm.duty_u16(0)
state = False
else:
pwm.duty_u16(65535)
state = True
# Aボタン
elif last_code == 0xF8 and time.ticks_ms() - last_ticks < threshold:
led2.value(1)
# Cボタン
elif last_code == 0x58 and time.ticks_ms() - last_ticks < threshold:
led3.value(1)
# 一定時間たったら消灯処理
if time.ticks_ms() - last_ticks >= threshold:
pwm.duty_u16(0)
led2.value(0)
led3.value(0)
import time
from machine import Pin
from ir_rx.nec import NEC_8
from machine import PWM
# オプトサプライ赤外線リモコンのデータと対応するボタンのメッセージ
keydata = {
0xD8:"Power button",
0xF8:"A button",
0x78:"B button",
0x58:"C button",
0xB1:"Upper left button",
0xA0:"Up button",
0x21:"Upper right button",
0x10:"Left button",
0x20:"Center button",
0x80:"Right button",
0x11:"Bottom left button",
0x00:"Down button",
0x81:"Bottom right button",
0xFF:"N/A"
}
last_code=0xFF
last_ticks = time.ticks_ms()
# 赤外線の信号を受信時に呼び出されるコールバック関数
def callback(data, addr, ctrl):
global last_code
global last_ticks
last_ticks = time.ticks_ms()
if data < 0: # repeat code -> 同じキーが繰り返しが押されたときの処理
print(keydata[last_code])
else:
last_code = data
#print(keydata[data]) # キーデータに対応する文字列を表示します
pwm = PWM(machine.Pin(16, machine.Pin.OUT))
pwm.freq(1000)
#led1 = machine.PWM( machine.Pin(16, machine.Pin.OUT))
led2 = machine.Pin(17, machine.Pin.OUT)
led3 = machine.Pin(18, machine.Pin.OUT)
# 2番ピンを使用するようにして、NEC 8bitクラスを初期化。上記のcallback関数を登録します。
ir = NEC_8(Pin(2, Pin.IN), callback)
# 無限ループ、信号を受信するとcallback関数が呼ばれます。
state = False
state_cnt = 0
threshold = 400
state_a = False
while True:
time.sleep_ms(100)
# Bボタン
if last_code == 0x78 and time.ticks_ms() - last_ticks < threshold:
state_cnt = state_cnt + 1
if state_cnt >= 10:
state_cnt = 0
if state:
pwm.duty_u16(0)
state = False
else:
pwm.duty_u16(65535)
state = True
# Aボタン
elif last_code == 0xF8 and time.ticks_ms() - last_ticks >= 200:
# トグル動作
if state_a == True:
led2.value(1)
state_a = False
else:
led2.value(0)
state_a = True
# Cボタン
elif last_code == 0x58 and time.ticks_ms() - last_ticks < threshold:
led3.value(1)
# 一定時間たったら消灯
if time.ticks_ms() - last_ticks >= threshold:
pwm.duty_u16(0)
led3.value(0)
last_code = 0xFF
import time
from machine import Pin
from ir_rx.nec import NEC_8
from machine import PWM
# オプトサプライ赤外線リモコンのデータと対応するボタンのメッセージ
keydata = {
0xD8:"Power button",
0xF8:"A button",
0x78:"B button",
0x58:"C button",
0xB1:"Upper left button",
0xA0:"Up button",
0x21:"Upper right button",
0x10:"Left button",
0x20:"Center button",
0x80:"Right button",
0x11:"Bottom left button",
0x00:"Down button",
0x81:"Bottom right button",
0xFF:"N/A"
}
last_code=0xFF
last_ticks = time.ticks_ms()
# 赤外線の信号を受信時に呼び出されるコールバック関数
def callback(data, addr, ctrl):
global last_code
global last_ticks
last_ticks = time.ticks_ms()
if data < 0: # repeat code -> 同じキーが繰り返しが押されたときの処理
print(keydata[last_code])
else:
last_code = data
#print(keydata[data]) # キーデータに対応する文字列を表示します
pwm = PWM(machine.Pin(16, machine.Pin.OUT))
pwm.freq(1000)
# 2番ピンを使用するようにして、NEC 8bitクラスを初期化。上記のcallback関数を登録します。
ir = NEC_8(Pin(2, Pin.IN), callback)
# 無限ループ、信号を受信するとcallback関数が呼ばれます。
threshold = 400
half_light=False
while True:
time.sleep_ms(100)
# Bボタン:押している間は最大点灯
if last_code == 0x78 and time.ticks_ms() - last_ticks < threshold:
pwm.duty_u16(65535)
# Aボタン
if last_code == 0xF8 and time.ticks_ms() - last_ticks >= 200:
# トグル動作
if half_light == True:
half_light = False
last_code = 0xff
else:
half_light = True # 暗く光るようにフラグ設定
last_code = 0xff
# 一定時間たったらクリア
if time.ticks_ms() - last_ticks >= threshold:
if half_light == True:
pwm.duty_u16(5000) # 消灯時に暗く光るように設定
else:
pwm.duty_u16(0)
wget https://github.com/jgraph/drawio-desktop/releases/download/v14.5.1/drawio-x86_64-14.5.1.rpm
sudo dnf -y install ./drawio-x86_64-14.5.1.rpm
create table cds_sensor
(
device_name varchar(30) not null,
data_ts timestamp not null,
cds_value float,
constraint pk_cds_sensor primary key (device_name, data_ts)
);
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
sudo apt-get -y install libpq-dev
mkdir -p ~/smbus_pg
cd ~/smbus_pg
pipenv --python 3
pipenv install psycopg2-binary smbus
pipenv shell
import os
import psycopg2
import psycopg2.extras
import smbus
import time
i2c = smbus.SMBus(1)
addr_mcp3425=0x68
FIELD_PGA_GAIN_1X = 0x00 # gain 1X
FIELD_SAMPLE_RATE_15SPS_16BIT = 0x08 # 15SPS 16bit sampling
FIELD_CONV_MODE = 0x00 # one-shot
FIELD_READY = 0x80
def read_cds():
i2c.write_byte(addr_mcp3425, FIELD_PGA_GAIN_1X | FIELD_SAMPLE_RATE_15SPS_16BIT | FIELD_CONV_MODE| FIELD_READY)
time.sleep(0.15)
dat = i2c.read_i2c_block_data(addr_mcp3425, 0x00, 3)
val = (dat[0] << 8) | dat[1]
return val
while True:
val= read_cds()
print("cds:{}".format(val))
device_name = 'mcp3425'
sql = """insert into cds_sensor values (%s, current_timestamp, %s)"""
conn = psycopg2.connect(host=os.environ['PG_HOST'], port=os.environ["PG_PORT"], database=os.environ['PG_DB'], user=os.environ['PG_USER'], password=os.environ['PG_PASS'])
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(sql , (device_name, val))
conn.commit()
time.sleep(1)
python3 record_cds.py
sudo mkdir -p /opt/krita
cd /opt/krita
sudo wget https://download.kde.org/stable/krita/4.4.3/krita-4.4.3-x86_64.appimage
sudo chmod +x krita-4.4.3-x86_64.appimage
cat << EOF | sudo tee -a /usr/share/applications/krita.desktop
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/krita/krita-4.4.3-x86_64.appimage
Name=Krita
Categories=Development;
EOF
i2cdetect -y -1
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/smbus
cd ~/smbus
pipenv --python 3
pipenv install smbus
pipenv shell
import smbus
import time
i2c = smbus.SMBus(1)
addr_mcp3425=0x68
FIELD_PGA_GAIN_1X = 0x00 # gain 1X
FIELD_SAMPLE_RATE_15SPS_16BIT = 0x08 # 15SPS 16bit sampling
FIELD_CONV_MODE = 0x00 # one-shot
FIELD_READY = 0x80
# Initialize
def read_cds():
i2c.write_byte(addr_mcp3425, FIELD_PGA_GAIN_1X | FIELD_SAMPLE_RATE_15SPS_16BIT | FIELD_CONV_MODE| FIELD_READY)
time.sleep(0.15)
dat = i2c.read_i2c_block_data(addr_mcp3425, 0x00, 3)
val = (dat[0] << 8) | dat[1]
return val
while True:
val= read_cds()
print("cds:{}".format(val))
time.sleep(1)
python3 test_mcp3425.py
sudo yum -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install flathub org.inkscape.Inkscape
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/smbus_mqtt
cd ~/smbus_mqtt
pipenv --python 3
pipenv install paho-mqtt smbus
pipenv shell
import paho.mqtt.client as mqtt
import time
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print("received: {}".format(msg.topic))
print(str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(host, port, secs_keep_alive)
client.loop_forever()
python3 mosquitto_sub_lux.py
import paho.mqtt.publish as publish
import smbus
import time
i2c = smbus.SMBus(1)
addr_tsl25721=0x39
FIELD_COMMAND = 0x80 # Write
FIELD_TYPE = 0x20 # Auto-increment protocol transaction
REG_CONTROL = 0x0F # Control Register
VAL_CONTROL_RESET = 0x00 # Reset Value for Control Register
REG_CONFIG = 0x0D # Config Register
VAL_CONFIG_RESET = 0x00 # Reset Value for Config Register
REG_ATIME = 0x01 # ATIME(ALS time) Register
VAL_ATIME_C64 = 0xC0 # INTEG_CYCLE=64, Time=175ms
REG_ENABLE = 0x00 # Enable Register
VAL_ENABLE_PON = 0x01 # Power ON
VAL_ENABLE_AEN = 0x02 # ALS Enable
VAL_ENABLE = VAL_ENABLE_PON | VAL_ENABLE_AEN
REG_C0DATA = 0x14 # CH0 ADC low data register
# Initialize
# Reset Control Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONTROL, VAL_CONTROL_RESET)
# Reset Config Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONFIG, VAL_CONFIG_RESET)
# Set ALS time
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ATIME, VAL_ATIME_C64)
# Power on and enable ALS
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ENABLE, VAL_ENABLE)
def read_lux():
atime = 0xC0 # 192
gain = 1.0
dat = i2c.read_i2c_block_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_C0DATA, 4)
adc0 = (dat[1] << 8) | dat[0]
adc1 = (dat[3] << 8) | dat[2]
cpl = (2.73 * (256 - atime) * gain)/(60.0)
lux1 = ((adc0 * 1.00) - (adc1 * 1.87)) / cpl
lux2 = ((adc0 * 0.63) - (adc1 * 1.00)) / cpl
lux = 0
if ((lux1 <= 0) and (lux2 <= 0)) :
lux = 0
if (lux1 > lux2) :
lux = lux1
elif (lux1 < lux2) :
lux = lux2
return lux
topic = "mosquitto/test"
host = "localhost"
port = 1883
secs_keep_alive=60
lux= read_lux()
publish.single(topic, "lux:{:.1f}".format(lux), hostname=host, port=port, keepalive=secs_keep_alive)
python3 mosquitto_pub_lux.py
wget 'https://www.zotero.org/download/client/dl?channel=release&platform=linux-x86_64&version=5.0.96' -O Zotero-5.0.96_linux-x86_64.tar.bz2
tar jxvf Zotero-5.0.96_linux-x86_64.tar.bz2
sudo mv Zotero_linux-x86_64 /opt
cat << EOF | sudo tee /usr/share/applications/zotero.desktop
[Desktop Entry]
Name=Zotero
Exec=/opt/Zotero_linux-x86_64/zotero
Type=Application
Terminal=false
Categories=Office;
MimeType=text/plain
EOF
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
mkdir -p ~/smbus_flask
cd ~/smbus_flask
pipenv --python 3
pipenv install flask smbus
pipenv shell
from flask import Flask, jsonify, request
import smbus
import time
i2c = smbus.SMBus(1)
addr_tsl25721=0x39
FIELD_COMMAND = 0x80 # Write
FIELD_TYPE = 0x20 # Auto-increment protocol transaction
REG_CONTROL = 0x0F # Control Register
VAL_CONTROL_RESET = 0x00 # Reset Value for Control Register
REG_CONFIG = 0x0D # Config Register
VAL_CONFIG_RESET = 0x00 # Reset Value for Config Register
REG_ATIME = 0x01 # ATIME(ALS time) Register
VAL_ATIME_C64 = 0xC0 # INTEG_CYCLE=64, Time=175ms
REG_ENABLE = 0x00 # Enable Register
VAL_ENABLE_PON = 0x01 # Power ON
VAL_ENABLE_AEN = 0x02 # ALS Enable
VAL_ENABLE = VAL_ENABLE_PON | VAL_ENABLE_AEN
REG_C0DATA = 0x14 # CH0 ADC low data register
# Initialize
# Reset Control Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONTROL, VAL_CONTROL_RESET)
# Reset Config Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONFIG, VAL_CONFIG_RESET)
# Set ALS time
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ATIME, VAL_ATIME_C64)
# Power on and enable ALS
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ENABLE, VAL_ENABLE)
def read_lux():
atime = 0xC0 # 192
gain = 1.0
dat = i2c.read_i2c_block_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_C0DATA, 4)
adc0 = (dat[1] << 8) | dat[0]
adc1 = (dat[3] << 8) | dat[2]
cpl = (2.73 * (256 - atime) * gain)/(60.0)
lux1 = ((adc0 * 1.00) - (adc1 * 1.87)) / cpl
lux2 = ((adc0 * 0.63) - (adc1 * 1.00)) / cpl
lux = 0
if ((lux1 <= 0) and (lux2 <= 0)) :
lux = 0
if (lux1 > lux2) :
lux = lux1
elif (lux1 < lux2) :
lux = lux2
return lux
app = Flask(__name__)
@app.route('/lux')
def get_lux():
lux = read_lux()
return jsonify({"lux":lux})
export FLASK_APP=app.py
flask run -h 0.0.0.0
sudo dnf -y install flatpak
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
sudo flatpak -y install flathub org.gottcode.FocusWriter
create table lux_sensor
(
device_name varchar(30) not null,
data_ts timestamp not null,
lux float,
constraint pk_lux_sensor primary key (device_name, data_ts)
);
sudo apt-get update
sudo apt-get -y install python3-pip python3-distutils python3-dev
sudo pip3 install --upgrade pip
sudo pip3 install --upgrade setuptools
sudo pip3 install pipenv
echo "export PIPENV_VENV_IN_PROJECT=true" >> ~/.bashrc
source ~/.bashrc
sudo apt-get -y install libpq-dev
mkdir -p ~/smbus_pg
cd ~/smbus_pg
pipenv --python 3
pipenv install psycopg2-binary smbus
pipenv shell
import os
import psycopg2
import psycopg2.extras
import smbus
import time
i2c = smbus.SMBus(1)
addr_tsl25721=0x39
FIELD_COMMAND = 0x80 # Write
FIELD_TYPE = 0x20 # Auto-increment protocol transaction
REG_CONTROL = 0x0F # Control Register
VAL_CONTROL_RESET = 0x00 # Reset Value for Control Register
REG_CONFIG = 0x0D # Config Register
VAL_CONFIG_RESET = 0x00 # Reset Value for Config Register
REG_ATIME = 0x01 # ATIME(ALS time) Register
VAL_ATIME_C64 = 0xC0 # INTEG_CYCLE=64, Time=175ms
REG_ENABLE = 0x00 # Enable Register
VAL_ENABLE_PON = 0x01 # Power ON
VAL_ENABLE_AEN = 0x02 # ALS Enable
VAL_ENABLE = VAL_ENABLE_PON | VAL_ENABLE_AEN
REG_C0DATA = 0x14 # CH0 ADC low data register
# Initialize
# Reset Control Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONTROL, VAL_CONTROL_RESET)
# Reset Config Register
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_CONFIG, VAL_CONFIG_RESET)
# Set ALS time
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ATIME, VAL_ATIME_C64)
# Power on and enable ALS
i2c.write_byte_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_ENABLE, VAL_ENABLE)
def read_lux():
atime = 0xC0 # 192
gain = 1.0
dat = i2c.read_i2c_block_data(addr_tsl25721, FIELD_COMMAND | FIELD_TYPE | REG_C0DATA, 4)
adc0 = (dat[1] << 8) | dat[0]
adc1 = (dat[3] << 8) | dat[2]
cpl = (2.73 * (256 - atime) * gain)/(60.0)
lux1 = ((adc0 * 1.00) - (adc1 * 1.87)) / cpl
lux2 = ((adc0 * 0.63) - (adc1 * 1.00)) / cpl
lux = 0
if ((lux1 <= 0) and (lux2 <= 0)) :
lux = 0
if (lux1 > lux2) :
lux = lux1
elif (lux1 < lux2) :
lux = lux2
return lux
while True:
lux= read_lux()
print("lux:{:.1f}".format(lux))
device_name = 'tsl25721'
sql = """insert into lux_sensor values (%s, current_timestamp, %s)"""
conn = psycopg2.connect(host=os.environ['PG_HOST'], port=os.environ["PG_PORT"], database=os.environ['PG_DB'], user=os.environ['PG_USER'], password=os.environ['PG_PASS'])
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute(sql , (device_name, lux))
conn.commit()
time.sleep(1)
export PG_HOST=データベースホスト名またはIP
export PG_PORT=データベースのポート番号(※通常5432)
export PG_DB=データベース名
export PG_USER=ユーザ名
export PG_PASS=パスワード
python3 record_lux.py