Skip to content

Instantly share code, notes, and snippets.

@h-sakano
Last active November 7, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-sakano/fd7ebb738e0d18f10446f41edd9ae102 to your computer and use it in GitHub Desktop.
Save h-sakano/fd7ebb738e0d18f10446f41edd9ae102 to your computer and use it in GitHub Desktop.
センサのアナログ出力をA/D変換し、アラートをチャットアプリに飛ばす ref: http://qiita.com/h-sakano/items/a3cffbe460e64f9ed064
def setup(cs=11, clk=12, dio=13):
global ADC_CS, ADC_CLK, ADC_DIO
ADC_CS = cs
ADC_CLK = clk
ADC_DIO = dio
GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD) # Number GPIOs by its physical location
+ GPIO.setmode(GPIO.BCM)
GPIO.setup(ADC_CS, GPIO.OUT) # Set pins' mode is output
GPIO.setup(ADC_CLK, GPIO.OUT) # Set pins' mode is output
$ pip install line-bot-sdk
$ pip install requests
#!/usr/bin/env python
# coding: UTF-8
import ADC0832
import sys
import time
from datetime import datetime
import requests
APIKEY = 'API KEY'
ENDPOINT = 'https://api.chatwork.com/v2'
ROOMID = 'ROOM ID'
post_message_url = '{}/rooms/{}/messages'.format(ENDPOINT, ROOMID)
headers = {'X-ChatWorkToken': APIKEY}
params = {'body': 'エラーランプが点灯しました。'}
def init():
ADC0832.setup()
def loop():
error = False
while True:
res = ADC0832.getResult()
if res <= 10:
if not error:
resp = requests.post(post_message_url,
headers=headers,
params=params)
error = True
else:
error = False
time.sleep(0.4)
if __name__ == '__main__':
init()
try:
loop()
except KeyboardInterrupt:
ADC0832.destroy()
print 'The end !'
#!/usr/bin/env python
# coding: UTF-8
import ADC0832
import sys
import time
from datetime import datetime
from linebot import (
LineBotApi
)
from linebot.exceptions import (
InvalidSignatureError
)
from linebot.models import (
MessageEvent, TextMessage, TextSendMessage,
)
line_bot_api = LineBotApi('Access Token')
def init():
ADC0832.setup()
def loop():
error = False
while True:
res = ADC0832.getResult()
if res <= 10:
if not error:
line_bot_api.push_message("Your user ID", TextSendMessage(text='エラーランプが点灯しました。'))
error = True
else:
error = False
time.sleep(0.4)
if __name__ == '__main__':
init()
try:
loop()
except KeyboardInterrupt:
ADC0832.destroy()
print 'The end !'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment