Skip to content

Commit

Permalink
Add API-type class to controlled systems, #78
Browse files Browse the repository at this point in the history
  • Loading branch information
MBaranskiEBC committed May 11, 2020
1 parent 55ed200 commit 95fb370
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pyDMPC/ControlFramework/ControlledSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,47 @@ def close(self):
self.contr_sys.terminate()
self.contr_sys.freeInstance()
shutil.rmtree(self.unzipdir)

class API:

def __init__(self):
self.auth = Init.auth
self.project_id = Init.project_id
self.base_url = Init.base_url

def read(self, dataPointID):

import datetime
import requests

params = {'project_id': self.project_id,
'dataPointID': dataPointID,
'end': datetime.datetime.now(),
'max' : 1,
'short': False}

r = requests.get(f"{self.base_url}/timeseries", auth = self.auth, params=params)

val = (r.json())
val = val["data"]
val = val[0]
val = val["value"]

print(f"{dataPointID}: {val}")

return [val]

def write(self, dataPointID, val):

import requests

print(f"{dataPointID}: {val}")

params = {'dataPointID': dataPointID,
'project_id': self.project_id,
'value' : val,
'priority': 13,
'acked' : False,
'dryrun': False}

requests.post(f"{self.base_url}/setpoint", auth = self.auth, params = params)

0 comments on commit 95fb370

Please sign in to comment.