-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
porting to v2 #6
base: master
Are you sure you want to change the base?
Changes from 32 commits
9ab73b1
2b4768b
e145710
ba17e43
a2fe8a6
51a8e0f
14b45a9
0a21efd
eac7f6f
de1c6fc
1ed5a1d
6685398
01a0ebc
3062640
c04c0b9
6b1279b
2c592d3
96316f8
c4202f0
ccca985
c8648ba
a77500a
6710f33
d9ce9bf
5f5a444
6eef292
8b67017
bed5122
85f4428
78855e5
1905f6b
3e7830d
6ba89ef
3697a7e
daa2fa4
17fa97f
77f31f2
d015e3c
c411403
93fcec8
c60a712
35a00bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## 2023-04-20 | ||
|
||
### Added | ||
|
||
- 讓使用者自定要使用V1版本還是V2版本 (#eac7f6f) | ||
- 新增常數`IOTTALK_VERSION` (#0a21efd) | ||
|
||
## 2023-04-18 | ||
|
||
### Changed | ||
|
||
- tablename的命名方式,改成只刪除-O,不刪後面的數字 (#14b45a9) | ||
|
||
## 2023-04-12 | ||
|
||
### Changed | ||
|
||
- IoTtalk-v2可使用的dashboard(dynamic) (#a2fe8a6) | ||
|
||
## 2023-04-10 | ||
|
||
### Added | ||
|
||
- IoTtalk-v2可使用的dashboard(static)(#9ab73b1) | ||
|
||
### Changed | ||
|
||
- rename `app0330.py` to `app.py` (#e145710) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CHANGELOG 的對象是最後要使用系統的人,像這種開發訊息就不需要放在 CHANGELOG 了, |
||
|
||
## Rule | ||
每一個軟體的版本必須: | ||
* 標明日期(要用上面說過的規範) | ||
* 標明分類(採用英文)。規範如下: | ||
* 'Added' 添加的新功能 | ||
* 'Changed' 功能變更 | ||
* 'Deprecated' 不建議使用,未來會刪掉 | ||
* 'Removed' 之前不建議使用的功能,這次真的刪掉了 | ||
* 'Fixed' 修正的 bug | ||
* 'Security' 修正了安全相關的 bug |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,12 @@ | |
|
||
# IoTtalk server's 'IP' or 'DomainName' only, without any protocol 'http://' or 'https://'. | ||
# ex: '8.8.8.8' or 'google.com', | ||
# if you want to use IoTtalk V1 : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CSM_HOST 的註解應該跟 IOTTALK_VERSION 分開,因為不管 v1還是 v2 都需要 CSM_HOST。 IOTTALK_VERSION 的說明,應該是指出使用者連接的 CSM 所使用的 IoTtalk version,然後說明接受的值為 1 或 2,default 為 1 這樣 |
||
CSM_HOST = '127.0.0.1:9999' | ||
IOTTALK_VERSION = 1 | ||
# if you want to use IoTtalk V2 : | ||
#CSM_HOST = 'https://iottalk2.tw/csm' | ||
#IOTTALK_VERSION = 2 | ||
|
||
# For the demo page without login | ||
# The data format is '<Field Name>':'<token>', examples are shown as follows. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import time | ||
import logging | ||
import re | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from datetime import datetime | ||
from db import db | ||
from iottalkpy.dai import module_to_sa | ||
from config import CSM_HOST as host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const 的參數就不要用 alias name 了,大寫才會知道是 const,不然會誤會成一般變數 |
||
|
||
log = logging.getLogger("\033[1;35m[DA]: \033[0m") | ||
|
||
|
||
def on_register(dan): | ||
print('register successfully') | ||
|
||
|
||
class SaClass: | ||
def __init__(self, host, field, field_id, profile={}, odf_list=[], | ||
alert_range={}, device_addr=None, **kwargs): | ||
self.host = host | ||
self.field = field | ||
self.field_id = field_id | ||
self.profile = profile | ||
self.odf_list = odf_list | ||
self.alert_range = alert_range | ||
self.device_addr = device_addr | ||
self.device_name = field.name + '_DataServer' | ||
self.api_url = host # get from config CSM_HOST | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 這句怪怪的,host 這樣不就衝突了嗎?到底是要 CSM_HOST 的 host 還是 init 參數中的 host,然後如果確定變數是用在 api_url 的話,那第19行就不需要存成 host了,init 參數的 host 也可以改成 api_URL |
||
self.device_model = 'DataServer' | ||
self.push_interval = 10 | ||
self.interval = {'Dummy_Sensor': 3, } | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.kwargs = kwargs | ||
|
||
for k, v in kwargs.items(): | ||
setattr(self, k, v) | ||
|
||
for odf in odf_list: | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
odf = re.sub(r'-', r'_', odf) | ||
setattr(self, odf, lambda data, odf=odf: self.run(data, odf)) | ||
|
||
def run(self, data: list, odf): | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
session = db.get_session() | ||
if data: | ||
value = float(data[0]) | ||
odf_class = getattr(db.models, re.sub(r"[-_]O", "", odf)) | ||
new_record = odf_class(timestamp=datetime.now(), | ||
field=self.field_id, | ||
value=value) | ||
session.add(new_record) | ||
session.commit() | ||
|
||
except KeyboardInterrupt: | ||
log.info(self.field, ': exit') | ||
except Exception as e: | ||
log.error('[ERROR]:', str(e)) | ||
if str(e).find('mac_addr not found:') != -1: | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
log.error('Reg_addr is not found. Try to re-register...') | ||
else: | ||
log.error('Connection failed due to unknow reasons.') | ||
time.sleep(1) | ||
jasmine8988 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
finally: | ||
session.close() | ||
|
||
|
||
def main(): | ||
db.connect() | ||
processes = [] | ||
|
||
session = db.get_session() | ||
|
||
for field in (session.query(db.models.field).all()): | ||
profile = {'d_name': field.name + '_DataServer', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不需要 profile了吧,這是 v1 的用法,應該可以直接建立各個變數塞進 SaClass 中 |
||
'dm_name': 'DataServer', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'odf_list': [], | ||
'is_sim': False} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
alert_range = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
query_df = (session.query(db.models.field_sensor) | ||
.select_from(db.models.field_sensor) | ||
.join(db.models.sensor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 只取 |
||
.filter(db.models.field_sensor.field == field.id) | ||
.all()) | ||
for df in query_df: | ||
profile['odf_list'].append(df.df_name) | ||
alert_range[df.df_name] = {'min': df.alert_min, | ||
'max': df.alert_max} | ||
sa = SaClass(host, field, field.id, | ||
profile=profile, | ||
odf_list=profile['odf_list'], | ||
aler_range=alert_range) | ||
|
||
process = module_to_sa(sa) | ||
process.daemon = True | ||
process.start() | ||
processes.append(process) | ||
|
||
session.close() | ||
|
||
for process in processes: | ||
process.join() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ pymysql~=0.10.1 | |
tzlocal~=2.1 | ||
|
||
MarkupSafe==2.0.1 | ||
|
||
iottalk-py==2.3.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,10 @@ def _start_server(): | |
|
||
|
||
def _start_da(): | ||
from da.DAI import main as da | ||
if config.IOTTALK_VERSION == 1: | ||
from da.DAI import main as da | ||
elif config.IOTTALK_VERSION == 2: | ||
from da.app import main as da | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是 da.app.main 還是 da.sa.main? |
||
da() | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這句是什麼意思?CHANGELOG 裡儘量放明確一點的文字,最好是能一看就知道意思。
然後如果是過程中的變動,不是最後結果的就不用放了,
比如這句 dynamic 跟下面的 static,這是在做一樣的事,最後的結果是 dynamic 的話,那 static 就不需要放了。