========================================================
参考の記事
http://kuc-arc-f.com/agri/?blog=blog-2
========================================================
前回、Android 側のpush受信機能の、
送信側の仕組みになります。
http://knaka0209.blogspot.jp/2015/04/agri-blog2-1.html
モバイル-push通知機能で
parse - push- APIを利用し、
python側から定期配信する仕組みとなります。
水分センサ値が既定値より下の判定の場合、pushされます。(水分が不足の為)
code:
https://github.com/kuc-arc-f/python-push-parse
# main - Loop
タイマ2種類、で監視
センサ値の送信、pushの送信
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
ser=serial.Serial(mDevice ,9600) | |
clsConst = com_appConst.appConstClass() | |
clsParam = com_getparam.getparamClass() | |
clsCom = com_func.funcClass() | |
clsParse =com_putParse.putParseClass() | |
clsLog = com_logging2.loggingClass() | |
clsPush =com_parsePush.parsePushClass() | |
from datetime import datetime | |
tmBef = datetime.now() | |
tmBefPush = datetime.now() | |
while True: | |
val=ser.readline() | |
bFrom = clsParam.Is_fromMC(val) | |
if bFrom==True: | |
dic= clsParam.getDict(val) | |
sTime = datetime.now().strftime("%Y%m%d%H%M%S") | |
tmNow = datetime.now() | |
if is_validTime(tmBefPush, tmNow, clsConst.mTimePush): | |
tmBefPush = datetime.now() | |
try: | |
clsPush.send_push(dic) | |
except: | |
print "--------------------------------------------" | |
print traceback.format_exc(sys.exc_info()[2]) | |
print "--------------------------------------------" | |
clsLog.debug( traceback.format_exc(sys.exc_info()[2]) ) | |
if is_validTime(tmBef, tmNow, clsConst.mTimeSensor): | |
tmBef = datetime.now() | |
try: | |
clsParse.send_parse(dic, sTime) | |
except: | |
print "--------------------------------------------" | |
print traceback.format_exc(sys.exc_info()[2]) | |
print "--------------------------------------------" | |
clsLog.debug( traceback.format_exc(sys.exc_info()[2]) ) |
# REST -API で, pushします
モバイルの通知バーの、文字設定など。
詳細の各センサ値は、アプリ起動時に表示されます。
モバイルの通知バーの、文字設定など。
詳細の各センサ値は、アプリ起動時に表示されます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headers = { | |
"X-Parse-Application-Id": clsConst.mParse_APP_ID , | |
"X-Parse-REST-API-Key": clsConst.mParse_REST_ID , | |
"Content-Type": "application/json" | |
} | |
from datetime import datetime | |
sTime = datetime.now().strftime("%m-%d %H:%M") | |
nMc = int(dict["mc_id"]) | |
sMsg="Water require, MC="+ str(nMc) + " [" +sTime+ "]" | |
dtParam = {} | |
dtParam["where"] ={'objectId': {"$exists": True } } | |
dtParam["data"] ={'alert': sMsg } | |
r = requests.post('https://api.parse.com/1/push', headers=headers , data=json.dumps(dtParam), timeout=30) | |
print r.status_code | |
print r.json() |
*) 開発者向けのまとめ記事
0 件のコメント:
コメントを投稿