Enviro+

Enviro+ćÆć•ć¾ć–ć¾ćŖć‚æć‚¤ćƒ—ć®ć‚»ćƒ³ć‚µćƒ¼ć‚’å†…č”µć—ćŸRaspberry Piē”Øć®ę–°ć—ć„ę‹”å¼µćƒœćƒ¼ćƒ‰ć§ć™ć€‚å‘Øč¾ŗē’°å¢ƒć®ć‚悉悆悋ē’°å¢ƒćƒ‡ćƒ¼ć‚æć‚’åŽé›†ć™ć‚‹ćŸć‚ć«ä½æē”Øć§ćć¾ć™ć€‚

č©³ē“°ćÆ恓恔悉怂https://shop.pimoroni.com/products/enviro-plus

ć“ć‚Œć‹ć‚‰ä½œć‚‹ć‚‚ć®

今ꗄćÆ光ćØčæ‘ꎄ悒ꤜēŸ„恙悋恓ćØć§ć€å®¶ć‚’å®ˆć‚‹č¶…ćƒć‚¤ćƒ†ć‚ÆćŖć‚½ćƒŖćƒ„ćƒ¼ć‚·ćƒ§ćƒ³ć‚’ä½œć£ć¦ćæć¾ć™ć€‚ć“ć®ć‚¢ć‚¤ćƒ‡ć‚¢ćÆē§ć®å®¶ćøć®å…„ć‚Šå£ćŒę˜¼é–“ć§ć‚‚éžåøø恫ꚗ恄ćØ恄恆ē‚¹ć‹ć‚‰ę„ć¦ć„ć¾ć™ć€‚ć¤ć¾ć‚Šć€å…‰ć®å¤‰åŒ–ćÆćƒ‰ć‚¢ćŒé–‹ć‹ć‚ŒćŸć“ćØ悒ē¤ŗć™ć‚‚ć®ć§ć‚ć‚Šć€č·é›¢ć‚»ćƒ³ć‚µćƒ¼ć®å¤‰åŒ–ćÆčŖ°ć‹ć€ć¾ćŸćÆä½•ć‹ļ¼ˆšŸ»ļ¼‰ćŒć‚»ćƒ³ć‚µćƒ¼ć«čæ‘恄恄恟恋通悊過恎恟恓ćØę„å‘³ć™ć‚‹ć‹ć‚‰ć§ć™ć€‚

ćƒ‡ćƒ¼ć‚æćÆFirebase DB恫送悊态Reactć®ćƒ•ćƒ­ćƒ³ćƒˆć‚Øćƒ³ćƒ‰ć‹ć‚‰ē›£č¦–ć—ć¾ć™ć€‚

å®Œęˆć—ćŸć‚µćƒ³ćƒ—ćƒ«ćÆć“ć“ć«ć‚ć‚Šć¾ć™ć€‚

https://tender-lamarr-33eddc.netlify.com

ę³Øꄏļ¼šć“ć®ć‚¢ć‚¤ćƒ‡ć‚¢ćÆ꘎悉恋恋恤非åøøć«åˆę­©ēš„ćŖč§£ę±ŗē­–ć§ć™ć€‚å®Ÿéš›ć®ćƒ›ćƒ¼ćƒ ć‚»ć‚­ćƒ„ćƒŖćƒ†ć‚£ć§ć®ä½æē”ØćÆ恗ćŖ恄恧恏恠恕恄怂

悂恆äø€ć¤ę³Øꄏļ¼šć“ć®ćƒ—ćƒ­ć‚ø悧ć‚Æ惈ćÆRaspbian litećŒć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć•ć‚ŒćŸć‚¤ćƒ³ć‚æćƒ¼ćƒćƒƒćƒˆć«ęŽ„ē¶šć§ćć‚‹Raspberry PićŒę—¢ć«ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—ć•ć‚Œć¦ć„ć‚‹ć“ćØć‚’å‰ęćØć—ć¦ć„ć¾ć™ć€‚

ć‚¹ć‚æćƒ¼ćƒˆć‚¢ćƒƒćƒ—ć‚¬ć‚¤ćƒ‰

ć¾ćšRaspberry Pić«ćƒ­ć‚°ć‚¤ćƒ³ć—ć€PimoronićŒęä¾›ć™ć‚‹ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć‚¹ć‚ÆćƒŖćƒ—ćƒˆć‚’å®Ÿč”Œć—ć¾ć™ć€‚

恓悌ćÆć€ä¾å­˜é–¢äæ‚ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć™ć‚‹ćŸć‚ć«ęœ€ć‚‚ē°”å˜ć§ęŽØå„Øć§ćć‚‹ę–¹ę³•ć§ć™ćŒć€ę¬”ć®readme恧ćÆä»–ć«ć‚‚ć•ć¾ć–ć¾ćŖę–¹ę³•ćŒčŖ¬ę˜Žć•ć‚Œć¦ć„ć¾ć™ć€‚https://github.com/pimoroni/enviroplus-python

curl -sSL https://get.pimoroni.com/enviroplus | bash

ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć‚’ēµ‚ćˆćŸć‚‰ć€ć•ć‚‰ć«ć„ćć¤ć‹ć®ä¾å­˜é–¢äæ‚ć‚’ę‰‹å‹•ć§čæ½åŠ ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

sudo apt install python-pip
pip install configparser
pip3 install RPi.GPIO
pip3 install spidev

ć‚³ćƒ¼ćƒ‰ć®å®Ÿč”Œ

ć“ć‚Œć§ć™ć¹ć¦ć®ä¾å­˜é–¢äæ‚ćŒć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć•ć‚ŒćŸć®ć§ć€ä»Šåŗ¦ćÆć‚³ćƒ¼ćƒ‰ć‚’ę›øć„ć¦č”Œćć¾ć™ć€‚

ć‚¹ć‚æćƒ¼ć‚æćƒ¼ćƒ»ćƒ—ćƒ­ć‚ø悧ć‚Æ惈ļ¼ˆhttps://github.com/makeupsomething/entrance-monitorļ¼‰ć‚’ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć€feature/step-1ć®ćƒ–ćƒ©ćƒ³ćƒć‚’ćƒć‚§ćƒƒć‚Æć‚¢ć‚¦ćƒˆć—ć¦ć€ć‚µćƒ³ćƒ—ćƒ«ć‚’å®Ÿč”Œć—ć¾ć™ć€‚

git clone https://github.com/makeupsomething/entrance-monitor.git
cd entrance-monitor
git checkout feature/step-1
python3 entrance-monitor/index.py

ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćŒčµ·å‹•ć—ć€LCDē”»é¢ć«ćƒ©ć‚¤ćƒˆćØčæ‘ęŽ„ć®å€¤ćŒč”Øē¤ŗć•ć‚Œć¾ć™ć€‚ćƒ©ć‚¤ćƒˆć‚»ćƒ³ć‚µćƒ¼ć‚’č¦†ć£ć¦ć€å€¤ćŒå¤‰åŒ–ć™ć‚‹ć“ćØ悒ē¢ŗčŖć—ć¦ćć ć•ć„ć€‚

ę¬”ć«ć‚³ćƒ¼ćƒ‰ć®äø€éƒØ悒見恦ćæć¾ć—ć‚‡ć†ć€‚

ć‚­ćƒ£ćƒ³ćƒć‚¹ćØćƒ•ć‚©ćƒ³ćƒˆć®ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—

#/New canvas to draw on./
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
path = os.path.dirname(os.path.realpath(__file__))
#/Set up canvas and font/
font_size = 15
font = ImageFont.truetype("entrance-monitor/fonts/Asap/Asap-Bold.ttf", font_size)
text_colour = (255, 255, 255)
back_colour = (170, 0, 170)
message = ""

恓恓恧ćÆ态Pillowćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ悒ä½æē”Øć—ć¦ę–°ć—ć„ć‚¤ćƒ”ćƒ¼ć‚øć‚’ä½œęˆć—ć€ę¬”ć«ćƒ•ć‚©ćƒ³ćƒˆćØćƒ†ć‚­ć‚¹ćƒˆć®ćƒ‡ćƒ•ć‚©ćƒ«ćƒˆć‚’čØ­å®šć—ć¦ć„ćć¾ć™ć€‚ćƒ†ć‚­ć‚¹ćƒˆć‚„čƒŒę™Æč‰²ć‚’č‡Ŗ分ćŖ悊恫ē·Ø集恗恦ćæć¦ćć ć•ć„ć€‚

try:
    while True:
        lux = ltr559.get_lux()
        prox = ltr559.get_proximity()
        message = """Light: {:05.02f} Lux
        Proximity: {:05.02f}
        """.format(lux, prox)
        
        #/Calculate text position/
        size_x, size_y = draw.textsize(message, font)
        x = (WIDTH - size_x) / 2
        y = (HEIGHT / 2) - (size_y / 2)
        
        draw.rectangle((0, 0, 255, 80), back_colour)
        draw.text((x, y), message, font=font, fill=text_colour)
        disp.display(img)
        time.sleep(1.0)
except KeyboardInterrupt:
    pass

ć“ć“ćŒć“ć®ć‚³ćƒ¼ćƒ‰ć®ćƒ”ć‚¤ćƒ³ćØćŖć‚Šć¾ć™ć€‚

ltr559ćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ悒ä½æē”Øć—ć¦å…‰ć‚»ćƒ³ć‚µćƒ¼ć‹ć‚‰č¼åŗ¦ć€čæ‘ęŽ„ć‚»ćƒ³ć‚µć‹ć‚‰čæ‘ęŽ„å€¤ć‚’å–å¾—ć—ć¦ć„ć¾ć™ć€‚

ę¬”ć«ć€ć“ć‚Œć‚‰ć‚’ę–‡å­—åˆ—ć«ćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆć—ć€å…ˆć«čØ­å®šć—ćŸē©ŗćƒ”ćƒƒć‚»ćƒ¼ć‚øć«å‰²ć‚Šå½“ć¦ć¾ć™ć€‚ę–‡å­—åˆ—ć®é•·ć•ć«åŸŗ恄恄恦悵悤ć‚ŗ悒č؈ē®—恗态ē”»é¢ć®äø­å¤®ć«é…ē½®ć—ć¾ć™ć€‚

ęœ€å¾Œć«ć€é•·ę–¹å½¢ć‚’ęē”»ć—态Pillowćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ悒ä½æē”Øć—ć¦ćƒ†ć‚­ć‚¹ćƒˆć‚’čæ½åŠ ć—å®Œęˆć—ćŸć‚¤ćƒ”ćƒ¼ć‚ø悒č”Øē¤ŗć•ć›ć¾ć™ć€‚ćć®å¾Œ0.5ē§’ć‚¹ćƒŖćƒ¼ćƒ—ć•ć›ć¦ć‹ć‚‰ćƒ«ćƒ¼ćƒ—ć•ć›ć¦ć„ć¾ć™ć€‚

Firebase

FirebasećØćÆGooglećŒę‰€ęœ‰ć™ć‚‹ćƒ¢ćƒć‚¤ćƒ«ćØć‚¦ć‚§ćƒ–ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³é–‹ē™ŗćƒ—ćƒ©ćƒƒćƒˆćƒ•ć‚©ćƒ¼ćƒ ć§ć™ć€‚

https://firebase.google.com/?hl=ja

Firebaseć®ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’ä½œć‚‹

Firebaseć‚¢ć‚«ć‚¦ćƒ³ćƒˆć‚’ęŒć£ć¦ć„ćŖć„å “åˆćÆć€ä½œęˆć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ć‚¢ć‚«ć‚¦ćƒ³ćƒˆć®ä½œęˆćÆē„”ꖙ恧态ä½æē”Øć™ć‚‹ćŸć‚ć«ę”Æę‰•ć„ęƒ…å ±ć‚’å…„åŠ›ć™ć‚‹åæ…要ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ćƒ­ć‚°ć‚¤ćƒ³ć—ćŸć‚‰ć€ [惗惭ć‚ø悧ć‚Æ惈恮čæ½åŠ ] 惜ć‚æćƒ³ć‚’ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚

惗惭ć‚ø悧ć‚Æćƒˆć«åå‰ć‚’ä»˜ć‘ć€ [ē¶šč”Œ] 悒ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚Google analytics悒惗惭ć‚ø悧ć‚Æ惈恫čæ½åŠ ć™ć‚‹ć«ćÆ ć€Œä»ŠćÆ恗ćŖ恄怍 悒éøęŠžć—ć€ęœ€å¾Œć« 怌惗惭ć‚ø悧ć‚Æćƒˆć‚’ä½œęˆć€ 悒ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚

ć‚µćƒ¼ćƒć®ćƒ—ćƒ­ćƒ“ć‚øćƒ§ćƒ‹ćƒ³ć‚°ć«ćÆę•°åˆ†ć‹ć‹ć‚‹å “åˆćŒć‚ć‚Šć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ćØćƒ«ćƒ¼ćƒ«ć®ć‚»ćƒƒćƒˆć‚¢ćƒƒćƒ—

Firebase恫ćÆ2ć¤ć®ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚½ćƒŖćƒ„ćƒ¼ć‚·ćƒ§ćƒ³ćŒć‚ć‚Šć¾ć™ć€‚

ć“ć®ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚’ä½æē”Ø恙悋際恫ćÆ恻ćØ悓恩Cloud Firestore恌ęŽØå„Øć•ć‚Œć¦ć„ć¾ć™ćŒć€ä»Šå›žä½æē”Ø恙悋Pythonćƒ©ć‚¤ćƒ–ćƒ©ćƒŖćÆć‚µćƒćƒ¼ćƒˆć•ć‚Œć¦ć„ćŖ恄恟悁态Realtime Database悒ä½æē”Øć—ć¾ć™ć€‚ä»Šå›žć®ä½æć„ę–¹ćÆ非åøøć«å˜ē“”ćŖ恮恧違恄ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

Firebaseć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć®ć‚µć‚¤ćƒ‰ćƒćƒ¼ć«č”Œćć€ 怌開ē™ŗ>database怍 悒ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚

ęœ€åˆć«ć€ŒCloud Firestoreć‚’ęœ‰åŠ¹ć«ć™ć‚‹ć‹ć©ć†ć‹ć€ć®ć‚Ŗćƒ—ć‚·ćƒ§ćƒ³ćŒč”Øē¤ŗć•ć‚Œć¾ć™ć€‚

ć—ć‹ć—ä»Šå›žć®ćƒ—ćƒ­ć‚ø悧ć‚Æ惈恧ćÆä½æē”Øć—ć¾ć›ć‚“ć®ć§ć€ćƒšćƒ¼ć‚øć‚’å°‘ć—äø‹ć«ć‚¹ć‚Æćƒ­ćƒ¼ćƒ«ć—ć¦ć€Realtime Datebaseć®ć€Œćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚’ä½œęˆć€ć‚’ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć®ćƒ«ćƒ¼ćƒ«ć‚’čØ­å®šć™ć‚‹ćƒćƒƒćƒ—ć‚¢ćƒƒćƒ—ćŒč”Øē¤ŗć•ć‚Œć‚‹ć®ć§ć€ ć€Œćƒ†ć‚¹ćƒˆćƒ¢ćƒ¼ćƒ‰ć§é–‹å§‹ć€ć‚’éøęŠžć—ć€ć€Œęœ‰åŠ¹ć«ć™ć‚‹ć€ 悒ć‚ÆćƒŖ惃ć‚Æć—ć¾ć™ć€‚ć“ć‚ŒćÆ态ē§ćŸć”ć®ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ćŒčŖčØ¼ć‚’ęŒćŸćŖ恄恓ćØć‚’ę„å‘³ć—ć¾ć™ć€‚ć“ć®čØ­å®šćŒå®Ÿéš›ć®ć‚¢ćƒ—ćƒŖ恠ćØć—ćŸć‚‰å•é”ŒćŒć‚ć‚Šć¾ć™ćŒć€ä»Šå›žćÆćƒ†ć‚¹ćƒˆē›®ēš„恧恮ä½æē”Øć™ć‚‹ćŸć‚ä»Šć®ćØć“ć‚ę°—ć«ē•™ć‚ć‚‹åæ…要ćÆć‚ć‚Šć¾ć›ć‚“ć€‚

ę³Øꄏļ¼šē¹°ć‚Ščæ”恗恫ćŖć‚Šć¾ć™ćŒć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚’ćƒ†ć‚¹ćƒˆćƒ¢ćƒ¼ćƒ‰ć«ć—ć¦ćŠćć®ćÆ危é™ŗć§ć™ć€‚ęœ¬ē•Ŗć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć§ćÆēµ¶åÆ¾ć«ć—ćŖ恄恧恏恠恕恄怂

ę¬”ć«ć€ćƒ—ćƒ­ć‚ø悧ć‚Æ惈APIć‚­ćƒ¼ćØ惗惭ć‚ø悧ć‚Æ惈IDć‚’å–å¾—ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚

ć‚µć‚¤ćƒ‰ćƒćƒ¼ć®ę­Æč»Šć‚¢ć‚¤ć‚³ćƒ³ć‚’ć‚ÆćƒŖ惃ć‚Æ恗态怌Project settings怍悒éøꊞ恙悋ćØć€ćć“ć«ćƒ—ćƒ­ć‚ø悧ć‚Æ惈IDćØapić‚­ćƒ¼ćŒč”Øē¤ŗć•ć‚Œć¾ć™ć€‚ć™ćć«åæ…要恫ćŖć‚‹ć®ć§ćƒ”ćƒ¢ć—ć¦ćŠć„ć¦ćć ć•ć„ć€‚

pyrebaseć®ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ćØfirebasećø恮ꎄē¶š

惗惭ć‚ø悧ć‚Æ惈悒Firebase恫Raspberry PiäøŠć§ēµ±åˆć™ć‚‹ć“ćØćŒć§ćć‚‹ć‚ˆć†ć«ćŖć‚Šć¾ć—ćŸć€‚

恓悌恋悉ē§ćŸć”ćÆpyrebase4悒ä½æć„ć¾ć™ć€‚ć“ć‚ŒćÆć‚ŖćƒŖć‚øćƒŠćƒ«ć®pyrebasećƒ©ć‚¤ćƒ–ćƒ©ćƒŖć‹ć‚‰ćƒ•ć‚©ćƒ¼ć‚Æć—ćŸć‚‚ć®ć§ć€python恋悉恮firebasećØäŗ’ć„ć«é€£ęŗć—ć¾ć™ć€‚

pyrebase4ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ć¾ć™ć€‚

pip3 install pyrebase4

ę¬”ć«ć€ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆćƒ•ć‚©ćƒ«ćƒ€å†…ć§feature/step-2悒惁悧惃ć‚Æć‚¢ć‚¦ćƒˆć—ć¾ć™ć€‚

git checkout feature/step-2

ä»Šć“ć‚Œć‚’å®Ÿč”Œć—ć‚ˆć†ćØ恙悋ćØ态ć‚Øćƒ©ćƒ¼ćŒč”Øē¤ŗć•ć‚Œć¾ć™ć€‚ć“ć‚ŒćÆ态Firebase惗惭ć‚ø悧ć‚Æćƒˆć«ęŽ„ē¶šć™ć‚‹ćŸć‚ć«ćƒ‡ćƒ¼ć‚æ悒čæ½åŠ ć™ć‚‹åæ…č¦ćŒć‚ć‚‹ćŸć‚ć§ć™ć€‚ć“ć®ćƒ—ćƒ­ć‚ø悧ć‚Æ惈ćÆē’°å¢ƒå¤‰ę•°ļ¼ˆAPI_KEYćŠć‚ˆć³PROJECT_IDļ¼‰ć‚’ę¤œē“¢ć™ć‚‹ćŸć‚ć€ć“ć‚Œć‚‰ć‚’čØ­å®šć—ć¾ć™ć€‚

ć“ć‚ŒćŒå…ˆć«ćƒ”ćƒ¢ć—ć¦ćŠć„ćŸFirebase APIć‚­ćƒ¼ćØ惗惭ć‚ø悧ć‚Æ惈ID恧恙怂

export API_KEY="apiKey"
export PROJECT_ID="projectId"

恧ćÆ前回ćØåŒę§˜ć«ć‚³ćƒ¼ćƒ‰ć‚’čµ°ć‚‰ć›ć¦ćæć¾ć—ć‚‡ć†ć€‚

python3 entrance-monitor/index.py

ćƒ‡ćƒć‚¤ć‚¹ć¾ćŸćÆē«Æęœ«ć®å‡ŗåŠ›ć«ćÆ違恄ćÆć‚ć‚Šć¾ć›ć‚“ćŒć€Firebaseć‚³ćƒ³ć‚½ćƒ¼ćƒ«ć§ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚’ē¢ŗčŖć™ć‚‹ćØć€ćƒ‡ćƒ¼ć‚æćŒę›“ę–°ć•ć‚Œć¦ć„ć‚‹ćÆćšć§ć™ć€‚å…‰ć‚»ćƒ³ć‚µć‚’ę‰‹ć§č¦†ć£ć¦ćæć¦ćƒ‡ćƒ¼ć‚æćŒę›“ę–°ć•ć‚Œć‚‹ć‹ē¢ŗčŖć—恦ćæć¦ćć ć•ć„ć€‚

ć‚³ćƒ¼ćƒ‰ć‚’č¦‹ć¦ćæć¾ć—ć‚‡ć†ć€‚

Firebase恮čح定

Firebaseć®ć‚¤ćƒ³ć‚¹ć‚æćƒ³ć‚¹ć‚’ę¬”ć®ć‚ˆć†ć«čØ­å®šć—ć¦ęŽ„ē¶šć—ć¦ć„ć¾ć™ć€‚

config = {
  "apiKey": os.getenv('API_KEY'),
  "authDomain": os.getenv('PROJECT_NAME')+".firebaseapp.com",
  "databaseURL": "https://"+os.getenv('PROJECT_NAME')+".firebaseio.com",
  "storageBucket": os.getenv('PROJECT_NAME')+"appspot.com",
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()

ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«ćƒ‡ćƒ¼ć‚æ悒送äæ”恙悋

ꬔ恫ē§ćŸć”ć®ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«ćƒ‡ćƒ¼ć‚æ悒送äæ”ć§ćć‚‹ć‚ˆć†ć«ć—ć€ē°”単ćŖćƒ«ćƒ¼ćƒ—ć‚’čæ½åŠ ć—ć¾ć™ć€‚

data = {"light": lux, "proximity": prox, "createdAt": str(datetime.datetime.now())} db.child("data").push(data)

Firebase realtime databasećÆJSONćƒ•ć‚©ćƒ¼ćƒžćƒƒćƒˆć§ćƒ‡ćƒ¼ć‚æć‚’å—ć‘å–ć‚‹ć®ć§ć€č¼åŗ¦ćØčæ‘ęŽ„å€¤ć€ćć—ć¦timestampć‚’å«ć‚€ć‚Ŗ惖ć‚ø悧ć‚Æćƒˆć‚’ä½œęˆć—ć¾ć™ć€‚ę¬”ć«ć€ćć‚Œć‚’dataćØć„ć†ćƒćƒ£ć‚¤ćƒ«ćƒ‰ć‚³ćƒ¬ć‚Æć‚·ćƒ§ćƒ³ć«ćƒ—ćƒƒć‚·ćƒ„ć—ć¾ć™ć€‚

恗恋恗态恓悌恧ćÆęƎē§’ćƒ‡ćƒ¼ć‚æ悒送äæ”恙悋恓ćØ恫ćŖ悊态ē§ćŸć”ć®ćƒ‡ćƒ¼ć‚æćÆFirebaseäøŠć§åˆ¶å¾”äøčƒ½ćØćŖ悊态ē„”ę–™ćƒ—ćƒ©ćƒ³ć§ć‚ć‚‹ļ¼‘ę—„恮ę›øćč¾¼ćæåˆ¶é™ć‚’ć‹ć‚‹ćč¶…ćˆć¦ć—ć¾ć„ć¾ć™ć€‚ē§ćŸć”ćŒęœ¬å½“ć«ć—ćŸć„ć®ćÆč¼åŗ¦ć‚„čæ‘ęŽ„å€¤ćŒåŠ‡ēš„ć«å¤‰åŒ–ć—ćŸć®ć‚’ę¤œå‡ŗ恗恟ćØćć ć‘ć§ć™ć€‚ćć‚Œä»„å¤–ć«ćÆ適当ćŖé–“éš”ć€ä¾‹ćˆć°60ē§’恔ćØć«ć‚¹ćƒ†ćƒ¼ć‚æć‚¹ę›“ę–°ć‚’é€äæ”ć§ćć‚Œć°å……åˆ†ć§ć™ć€‚

ć¾ćšč¼åŗ¦ćØčæ‘ęŽ„å€¤ć‚’čæ½č·”ć—ę¬”ć®å€¤ćŒå¤§å¹…ć«ē•°ćŖć‚‹ć‹ć©ć†ć‹ć‚’ę¤œå‡ŗ恙悋åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ć¾ćŸć€ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć«ęœ€å¾Œć«ćƒ‡ćƒ¼ć‚æ悒送äæ”恗恦恋悉恮ēµŒéŽę™‚é–“ć‚’čæ½č·”ć™ć‚‹ćŸć‚ć«count悂čæ½åŠ ć—ć¾ć™ć€‚60ē§’ć‚’č¶…ćˆć‚‹å “合ćÆ态ē¾åœØć®å€¤ć‚’é€äæ”ć—ć¾ć™ć€‚

whilećƒ«ćƒ¼ćƒ—ć®å¤–ć§å®£čØ€ć—ć¾ć™ć€‚

prev_lux = 0
prev_prox = 0
count = 0

ꬔ恫whilećƒ«ćƒ¼ćƒ—å†…ć§ć€č¼åŗ¦ćØčæ‘ęŽ„å€¤ć®ē¾åœØć®å€¤ćŒå‰ć®å€¤ć‚ˆć‚Šå¤§ćć„ć‹ć©ć†ć‹ć‚’ćƒć‚§ćƒƒć‚Æ恙悋åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ć‚‚ć—å€¤ćŒå¤§ćć‹ć£ćŸå “合ćÆć™ćć«ćƒ‡ćƒ¼ć‚æćƒ™ćƒ¼ć‚¹ć‚’ę›“ę–°ć—ć¾ć™ć€‚ć‚‚ć—č¼åŗ¦ćØčæ‘ęŽ„å€¤ć®ē¾åœØć®å€¤ćŒå‰ć®å€¤ć‚ˆć‚Šå°ć•ć‹ć£ćŸå “åˆć«ćÆć€ę–°ć—ć„å‰ć®å€¤ć‚’čØ­å®šć—ć‚«ć‚¦ćƒ³ćƒˆå€¤ć‚’å¢—ć‚„ć—ć¾ć™ć€‚

if(abs(prev_lux - lux) > 20 or abs(prev_prox - prev_prox) > 20 or count >= 60):
    data = {ā€œlightā€: lux, ā€œproximityā€: prox, ā€œcreatedAtā€: str(datetime.datetime.now())}
    db.child(ā€œdataā€).push(data)
    count = 0
prev_lux = lux
prev_prox = prox
count = count + 1

ć¤ć„ć«ćƒ‡ćƒ¼ć‚æ悒åÆč¦–åŒ–ć™ć‚‹ę™‚ćŒćć¾ć—ćŸć€‚

Reactć®ćƒ•ćƒ­ćƒ³ćƒˆć‚Øćƒ³ćƒ‰

React

ReactćÆćƒ¦ćƒ¼ć‚¶ć‚¤ćƒ³ć‚æćƒ•ć‚§ćƒ¼ć‚¹ć‚’ę§‹ēÆ‰ć™ć‚‹ćŸć‚ć®JavaScriptćƒ©ć‚¤ćƒ–ćƒ©ćƒŖ恧态FacebookćØå€‹ć€…ć®é–‹ē™ŗ者ćØä¼ę„­ć®ć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£ć«ć‚ˆć£ć¦ē¶­ęŒć•ć‚Œć¦ć„ć¾ć™ć€‚

惗惭ć‚ø悧ć‚Æćƒˆć®é–‹å§‹

ćƒŖ惝ć‚ø惈ćƒŖć‚’ćƒ•ć‚©ćƒ¼ć‚Æć—ć¦ćƒ€ć‚¦ćƒ³ćƒ­ćƒ¼ćƒ‰ć—ć¾ć™ć€‚

ćƒ•ćƒ­ćƒ³ćƒˆć‚Øćƒ³ćƒ‰ćŒć©ć®ć‚ˆć†ć«ę©Ÿčƒ½ć™ć‚‹ć‹ć«ć¤ć„ć¦ćÆ态恓恮čؘäŗ‹ć§ćÆč©³ć—ćčŖ¬ę˜Žć—ć¾ć›ć‚“ćŒē°”å˜ć«ę›ø恏ćØć€ćƒ‡ćƒć‚¤ć‚¹ć‹ć‚‰Firebasećƒ•ćƒ­ćƒ³ćƒˆć‚Øćƒ³ćƒ‰ć¾ć§ć®ćƒ‡ćƒ¼ć‚æ悒(恻ćØ悓恩)ćƒŖć‚¢ćƒ«ć‚æć‚¤ćƒ ć«å–å¾—ć§ćć‚‹ć‚‚ć®ć§ć™ć€‚

惗惭ć‚ø悧ć‚Æćƒˆć‚’å®Ÿč”Œć™ć‚‹ć«ćÆ态Firebase APIć‚­ćƒ¼ćØ惗惭ć‚ø悧ć‚Æ惈ID悒惗惭ć‚ø悧ć‚Æ惈恫čæ½åŠ ć™ć‚‹åæ…č¦ćŒć‚ć‚Šć¾ć™ć€‚ć“ć‚Œć‚‰ćÆ态python惗惭ć‚ø悧ć‚Æ惈恧ä½æē”Øć—ćŸć®ćØåŒć˜APIć‚­ćƒ¼ćØ惗惭ć‚ø悧ć‚Æ惈ID恧恙怂
.envćØć„ć†ćƒ•ć‚”ć‚¤ćƒ«ć‚’ä½œęˆć—ć€ę¬”ć®č”Œć‚’čæ½åŠ ć—ć¾ć™ć€‚

REACT_APP_API_KEY=apiKey
REACT_APP_PROJECT_ID=projectId

恧ćÆ依存関äæ‚ć‚’ć‚¤ćƒ³ć‚¹ćƒˆćƒ¼ćƒ«ć—ć€ę¬”ć®ć‚ˆć†ć«ćƒ—ćƒ­ć‚ø悧ć‚Æćƒˆć‚’å®Ÿč”Œć—ć¾ć—ć‚‡ć†ć€‚

npm install
npm run start

Raspberry PiäøŠć®ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ćŒć¾ć å®Ÿč”Œäø­ć§ć‚悋恓ćØ悒ē¢ŗčŖć™ć‚‹ć‹ć€ć‚¢ćƒ—ćƒŖć‚±ćƒ¼ć‚·ćƒ§ćƒ³ć‚’å†čµ·å‹•ć—ć€https://localhost:3000ć«ć‚¢ć‚Æć‚»ć‚¹ć—ć¦ćƒ©ć‚¤ćƒ–å‡ŗåŠ›ć‚’ē¢ŗčŖć—ć¾ć™ć€‚


1 Comment

ę¬²ć—ć„ć‚»ćƒ³ć‚µćƒ¼ć¦ć‚“ć“ē››ć‚ŠćŖEnviro+恮ē“¹ä»‹ – Isaax Camp · 2019-10-30 at 15:29

[…] Enviro+ ćØ FirebasešŸ”„ć§ćƒ›ćƒ¼ćƒ ć‚»ć‚­ćƒ„ćƒŖćƒ†ć‚£ć®ćƒ—ćƒ­ćƒˆć‚æ悤惗開ē™ŗ […]

Leave a Reply

Your email address will not be published. Required fields are marked *