SmartCover API with Ignition

Has anyone done API integration between SmartCover and Ignition? Any info would be greatly appreciated. Thank you!

Never heard of them. Links?

25014SD REV D API Documentation.pdf (373.7 KB)

They have an API, so Ignition can talk to it with scripted system.net.httpClient().

1 Like

Looks very doable - they even have a Python example in the docs:

import requests
import csv
# variable to store the location id of interest
location_id = 'LOCATION_ID'
# variable to store the JWT token
token = 'TOKEN'
# set the authorization header
headers = {'Authorization': 'Bearer ' + token}
# set the request parameters
params = {
 'location': location_id,
 'start_time': '2020-07-01 00:00',
 'end_time': '2020-07-10 00:00',
 'data_type': '2' }
# make the GET request
response = requests.get('https://www.mysmartcover.com/api/locations/data.php',
params = params, headers = headers)
# store the response code
response_code = response.json()['response_code']
# store the data from the response
data = response.json()['data'][0]
# write the output to a CSV file
with open('output.csv', mode = 'w') as output_file:
 output_writer = csv.writer(output_file, delimiter = ',')
 output_writer.writerow(['datetime', 'level']) # write the column headers
 for row in data:
 output_writer.writerow(row)

In your case, importing the requests library will probably be unnecessary because of the built-in system.net.httpClient, system.net.httpGet and system.net.httpPost functions.

If you already have a token, you should be able to do something like this (off the top of my head):

client = system.net.httpClient()
url = "https://www.mysmartcover.com/api/locations/list.php"
headers = {
    "Authorization": "Bearer <YOUR_TOKEN_HERE>"
}
res = client.get(url, headers=headers)

if res.good:
    print res.json
1 Like