Snippets

Espec North America Examples of Web Controller rest api usage for SEL

Created by Myles Metzler
'''
Some basic examples using Espec North America's web controller RESTful API

requires the requests library: http://docs.python-requests.org/en/master/
'''
import requests, json, time

def pprint(data):
    print(json.dumps(data, sort_keys=True, indent=4))

uri = 'http://10.30.200.254/api/v1.0/chambers/1'
headers = {'Content-type': 'application/json'}

# 1) Turn on the environmental chamber.
print('\n\nRun constant mode:')
pprint(requests.post(uri + '/operations/constant').json())

# 2) Turn on humidity control.
data = [
    {'controller':1, 'N':2, 'enable':True}  #Humidity
]
pprint(requests.post(uri + '/loops', data=json.dumps(data), headers=headers).json())

# 3/4) Set the temperature/humidity set point
data = [
    {'controller':1, 'N':1, 'enable':True, 'setValue':45}, #Temperature
    {'controller':1, 'N':2, 'enable':True, 'setValue':55}  #Humidity
]
pprint(requests.post(uri + '/loops', data=json.dumps(data), headers=headers).json())

# 5/6) Read the temperature/humidity
print('Get control loop status')
pprint(requests.get(uri + '/loops').json())

# 7) Turn off the chamber.
print('\n\nStop operation for 10 seconds:')
pprint(requests.post(uri + '/operations/standby').json())

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.