投稿者「mars」のアーカイブ

Weather Stationの室外データを rtl_433, influxDB, grafanaで可視化

(myenv) mars@pi4Bu:~ $ cat weather-influx.py
#coding: utf-8
# encoding: utf-8

import sys
import subprocess
import json
import struct
from influxdb import InfluxDBClient

client = InfluxDBClient(host='XXX.XXX.XXX.XXX', port=8086,
                        username='root', password='XXXXX', database='iot01')
measurement = 'weather-station'
tags = {'place': 'leaf-weather', 'host': 'weather'}

cmd = [
    "rtl_433",
    "-F", "json"
]

process = subprocess.Popen(
    cmd,
    stdout=subprocess.PIPE,
    universal_newlines=True
)

for line in iter(process.stdout.readline, ''):
    if "time" in line:
        data = json.loads(line)
        temp = round((float(data["temperature_F"])-32)/1.8,1)
        humi = data["humidity"]
        wspd = round(float(data["wind_avg_km_h"])/3600,1)
        wdir = data["wind_dir_deg"]
        rain = data["rain_mm"]
    json_body = [
        {
        'measurement': measurement,
        'tags': tags,
        'fields': {'temp': temp, 'humi': humi, 'wdir': wdir, 'wspd':wspd}
        }
    ]
    client.write_points(json_body)
    print(json_body)

Install RTL_SDR Support

https://gist.github.com/derme302/a702e421b7cd133753e5ab87101a01c4

https://github.com/merbanan/rtl_433/tree/master

データの取得例

$ rtl_433  2>/dev/null
[SDR] Using device 0: Realtek, RTL2838UHIDIR, SN: 00000001, "Generic RTL2832U OEM"
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
time      : 2024-11-12 21:58:45
model     : Emax-W6      id        : dd9
Channel   : 4            Battery_OK: 1             Temperature: 59.3 F       Humidity  : 81 %
Wind avg speed: 0.0 km/h Wind Direction: 228       Total rainfall: 0.2 mm    UV Index  : 1             Lux       : 0
Integrity : CHECKSUM
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
time      : 2024-11-12 21:59:15
model     : Emax-W6      id        : dd9
Channel   : 4            Battery_OK: 1             Temperature: 59.1 F       Humidity  : 80 %
Wind avg speed: 0.0 km/h Wind Direction: 229       Total rainfall: 0.2 mm    UV Index  : 1             Lux       : 0
Integrity : CHECKSUM

$ rtl_433 2>/dev/null | python t.py

$ cat t.py
#!/usr/bin/python
import sys
for line in sys.stdin:
    #print(line.strip())
    res=line.split()
    if len(res) == 34:
        TT=round((float(res[6])-32)/1.8,1)
        HH=res[10]
        WS=round(float(res[15])/3600,1)
        WD=res[19]
        RR=res[22]
        UV=res[27]
        UL=res[30]
        print(TT,HH,WS,WD,RR,UV,UL)
mars@pi4Bu:~/rtl_433 $ rtl_433   2>/dev/null |python t.py
18.4 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0
18.5 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0
18.4 69 0.0 229 0.2 1 0

Apache2 の設定を確認する

  • Ubuntuでのapache2の設定確認方法について説明します:基本的な設定確認コマンド
    構文チェックbash
    sudo apachectl -t
    またはbash
    sudo apache2ctl configtest
  • 詳細な設定確認
    sudo apachectl -S # 仮想ホストの設定確認
  • sudo apachectl -M # 読み込まれているモジュールの確認

Let’s Encrypt の証明書をブラウザ上で簡単取得

参照サイト

証明書の確認 cat cert.pem |openssl x509 -text -noout

実際に取得するサイト

 Let’s Encrypt へ登録

Emailを入力して、署名鍵を取得

2. チャレンジトークンの取得

3. ドメイン名の所有確認

4. 証明書発行申請

5. 発行された証明書

cert.pem (サーバ証明書)、chain.pem (中間証明書)、fullchain.pem (サーバ証明書 + 中間証明書)と、STEP4で取得した秘密鍵をサーバーへ設置する

/etc/letsencrypt/archive/live/b17.ddns.net/

インストールの確認

$cat cert.pem |openssl x509 -text -noout

Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number:
            04:85:92:51:53:66:49:fe:d6:7a:17:6a:1a:9f:aa:ab:c2:4c
        Signature Algorithm: sha256WithRSAEncryption
        Issuer: C = US, O = Let's Encrypt, CN = R11
        Validity
            Not Before: Jan  8 00:12:59 2025 GMT
            Not After : Apr  8 00:12:58 2025 GMT
        Subject: CN = rfsec.ddns.net