<commit_before>#!/usr/bin/env python3
# coding: utf-8

################################################################################
# BLE Logger
#
# iot_exp_press_udp_bleやiot_exp_sensorShield-evk_bleが送信するビーコンを受信し
# ビーコンに含まれる、温度センサ値と気圧センサ値を表示します。
#
#                                               Copyright (c) 2019 <NAME>
################################################################################

#【インストール方法】
#   bluepy (Bluetooth LE interface for Python)をインストールしてください
#       sudo pip3 install bluepy
#
#【実行方法】
#   実行するときは sudoを付与してください
#       sudo ./ble_logger_sens_scan.py &
#
#【参考文献】
#   本プログラムを作成するにあたり下記を参考にしました
#   https://ianharvey.github.io/bluepy-doc/scanner.html

interval = 1.01 # 動作間隔

from bluepy import btle
from sys import argv
import getpass
from time import sleep

def payval(num, bytes=1, sign=False):
    global val
    a = 0
    if num < 2 or len(val) < (num - 2 + bytes) * 2:
        print('ERROR: data length',len(val))
        return 0
    for i in range(0, bytes):
        a += (256 ** i) * int(val[(num - 2 + i) * 2 : (num - 1 + i) * 2],16)
    if sign:
        if a >= 2 ** (bytes * 8 - 1):
            a -= 2 ** (bytes * 8)
    return a

scanner = btle.Scanner()
while True:
    # BLE受信処理
    try:
        devices = scanner.scan(interval)
    except Exception as e:
        print("ERROR",e)
        if getpass.getuser() != 'root':
            print('使用方法: sudo', argv[0])
            exit()
        sleep(interval)
        continue

    # 受信データについてBLEデバイス毎の処理
    for dev in devices:
        print("\nDevice %s (%s), RSSI=%d dB, Connectable=%s" % (dev.addr, dev.addrType, dev.rssi, dev.connectable))
        isRohmMedal = False
        sensors = dict()
        for (adtype, desc, val) in dev.getScanData():
            print("  %3d %s = %s" % (adtype, desc, val))
            if adtype == 9 and val[0:4] == 'esp_':
                isRohmMedal = True
            if isRohmMedal and desc == 'Manufacturer':
                if len(val) >= 17 * 2:
                    # センサ値を辞書型変数sensorsへ代入
                    sensors['ID'] = hex(payval(2,2))
                    sensors['Temperature'] = payval(4,1) / 4 - 15
                    sensors['Pressure'] = payval(5,1,True) + 1027
                    sensors['Illuminance'] = payval(6,2) / 1.2
                    sensors['Proximity'] = payval(8,1)
                    sensors['Color R'] = payval(9,1) / 256 * 100
                    sensors['Color B'] = payval(10,1) / 256 * 100
                    sensors['Color G'] = payval(11,1) / 256 * 100
                    sensors['Color IR'] = 100 - sensors['Color R']\
                                              - sensors['Color G']\
                                              - sensors['Color B']
                    if sensors['Color IR'] < 0:
                        sensors['Color IR'] = 0
                    sensors['Accelerometer X'] = payval(12,1,True) / 64<commit_msg>デバイス名の変更<commit_after>#!/usr/bin/env python3
# coding: utf-8

################################################################################
# BLE Logger
#
# iot_exp_press_udp_bleやiot_exp_sensorShield-evk_bleが送信するビーコンを受信し
# ビーコンに含まれる、温度センサ値と気圧センサ値を表示します。
#
#                                               Copyright (c) 2019 <NAME>
################################################################################

#【インストール方法】
#   bluepy (Bluetooth LE interface for Python)をインストールしてください
#       sudo pip3 install bluepy
#
#【実行方法】
#   実行するときは sudoを付与してください
#       sudo ./ble_logger_sens_scan.py &
#
#【参考文献】
#   本プログラムを作成するにあたり下記を参考にしました
#   https://ianharvey.github.io/bluepy-doc/scanner.html

interval = 1.01 # 動作間隔

from bluepy import btle
from sys import argv
import getpass
from time import sleep

def payval(num, bytes=1, sign=False):
    global val
    a = 0
    if num < 2 or len(val) < (num - 2 + bytes) * 2:
        print('ERROR: data length',len(val))
        return 0
    for i in range(0, bytes):
        a += (256 ** i) * int(val[(num - 2 + i) * 2 : (num - 1 + i) * 2],16)
    if sign:
        if a >= 2 ** (bytes * 8 - 1):
            a -= 2 ** (bytes * 8)
    return a

scanner = btle.Scanner()
while True:
    # BLE受信処理
    try:
        devices = scanner.scan(interval)
    except Exception as e:
        print("ERROR",e)
        if getpass.getuser() != 'root':
            print('使用方法: sudo', argv[0])
            exit()
        sleep(interval)
        continue

    # 受信データについてBLEデバイス毎の処理
    for dev in devices:
        print("\nDevice %s (%s), RSSI=%d dB, Connectable=%s" % (dev.addr, dev.addrType, dev.rssi, dev.connectable))
        isRohmMedal = False
        sensors = dict()
        for (adtype, desc, val) in dev.getScanData():
            print("  %3d %s = %s" % (adtype, desc, val))
            if adtype == 9 and val[0:7] == 'espRohm':
                isRohmMedal = True
            if isRohmMedal and desc == 'Manufacturer':
                if len(val) >= 17 * 2:
                    # センサ値を辞書型変数sensorsへ代入
                    sensors['ID'] = hex(payval(2,2))
                    sensors['Temperature'] = payval(4,1) / 4 - 15
                    sensors['Pressure'] = payval(5,1,True) + 1027
                    sensors['Illuminance'] = payval(6,2) / 1.2
                    sensors['Proximity'] = payval(8,1)
                    sensors['Color R'] = payval(9,1) / 256 * 100
                    sensors['Color B'] = payval(10,1) / 256 * 100
                    sensors['Color G'] = payval(11,1) / 256 * 100
                    sensors['Color IR'] = 100 - sensors['Color R']\
                                              - sensors['Color G']\
                                              - sensors['Color B']
                    if sensors['Color IR'] < 0:
                        sensors['Color IR'] = 0
                    sensors['Accelerometer X'] = payval(12,1,True) / 64
{'fraction_non_alphanumeric': 0.17950481430536452, 'fraction_numerical': 0.032324621733149934, 'mean_word_length': 1.8169491525423729, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7374350', 'n_tokens_mistral': 2162, 'n_tokens_neox': 1963, 'n_words': 441}