head

2015年4月28日火曜日

[blog-2] Parse.com -push機能を起動する、pythonサービス


========================================================
参考の記事
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の送信

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]) )
view raw gistfile1.txt hosted with ❤ by GitHub

# REST -API で, pushします
モバイルの通知バーの、文字設定など。
詳細の各センサ値は、アプリ起動時に表示されます。


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()
view raw gistfile1.txt hosted with ❤ by GitHub
*) 開発者向けのまとめ記事

0 件のコメント:

コメントを投稿

google colaboratory お試し編 、GPUも使える機械学習の環境構築

前回続き、機械学習の関連となります。 開発環境まわりの内容となり。先人様の情報を元に調査しました。 google colab(google colaboratory) を試してみました。機械学習系の いくつかのライブラリがインストール済みで、 クラウド上で、ある程度機械学...

AD-parts

Shop
Bluetooth搭載
ベース基板

Social