32 lines
874 B
Python
32 lines
874 B
Python
from http_client import HTTPClient
|
|
from device_info import DeviceInfo
|
|
import json
|
|
|
|
|
|
class GrowSystemApi:
|
|
|
|
http_client = HTTPClient()
|
|
|
|
device_info = DeviceInfo()
|
|
|
|
base_url = ''
|
|
|
|
def __init__(self):
|
|
self.base_url = self.device_info.server_url
|
|
|
|
def say_hello(self):
|
|
response = self.http_client.post(self.base_url + "/api/device", self._get_device_data())
|
|
print(response.text)
|
|
jsonResult = json.loads(response.text)
|
|
print(jsonResult)
|
|
return jsonResult;
|
|
|
|
def send_measurements(self, device_id, data):
|
|
url = self.base_url + "/api/device/" + str(device_id) + "/sensor-log"
|
|
response = self.http_client.post(url, data)
|
|
return json.loads(response.text)
|
|
|
|
def _get_device_data(self):
|
|
return self.device_info.get_all_device_infos()
|
|
|