IO Module examples

Basic usage examples

These examples are meant to be run on the device!
If you want to run them from a remote computer, you need to change “localhost” to the IP/hostname.
You will also need to generate an access token and use the “auth basic” method.
You may also want to use the secure protocol https://.

Please ensure nothing is connected to the hardware before running this examples!

Python examples

Get input values for all connected modules

Example:

import requests   

# For tokens see http://noreya-nexus.local/nexuscontrolui/system/settings#access-token
login=("token", "")
hostname="localhost"

resp = requests.get("http://" + hostname + "/api/io/1.0/", auth=login)
if resp.status_code == requests.codes.ok:
  response = resp.json()
  for device in response['devices']:
    print("Input values for module on slot " + str(device['slot_number']) + ":")
    resp = requests.get("http://" + hostname + "/api/io/1.0/" + str(device['slot_number']) + "/input/values", auth=login)
    if resp.status_code == requests.codes.ok:
      response = resp.json()
      for pin in response['pins']:
        print(pin)
    else:
      print("Error response for slot " + str(device['slot_number']))
else:
  print("Error response")

Output:

Input values for module on slot 3 :
{'pin': 1, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 2, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 3, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 4, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 5, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 6, 'pin_type': 'voltage_millivolt', 'value': 0}
Input values for module on slot 4 :
{'pin': 1, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 2, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 3, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 4, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 5, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 6, 'pin_type': 'voltage_millivolt', 'value': 0}
Input values for module on slot 6 :
{'pin': 1, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 2, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 3, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 4, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 5, 'pin_type': 'voltage_millivolt', 'value': 0}
{'pin': 6, 'pin_type': 'voltage_millivolt', 'value': 0}

Configure the power management, turn an output on and check for notifications

Example:

import requests   

# For tokens see http://noreya-nexus.local/nexuscontrolui/system/settings#access-token
login=("token", "")
host_rest_api = "http://localhost/api/io/1.0/"

response = requests.get(host_rest_api, auth=login)
if response.status_code == requests.codes.ok:
    response = response.json()
    for device in response['devices']:
        slot_number = device['slot_number']
        print("Output config for module on slot " + str(slot_number) + ":")

        response = requests.get(host_rest_api + str(slot_number) + "/reset", auth=login)
        if response.status_code == requests.codes.ok:
            print("Successfully reset device")  # We do "write" requests so we need to get a defined state

        request = {"config": [  # Power config is always configured for all pins!
            {"rail": "5_volt", "current_milliampere": 10},
            {"rail": "5_volt", "current_milliampere": 11},
            {"rail": "5_volt", "current_milliampere": 12},
            {"rail": "5_volt", "current_milliampere": 13},
            {"rail": "5_volt", "current_milliampere": 14},
            {"rail": "5_volt", "current_milliampere": 15}
        ]
        }
        response = requests.post(host_rest_api + str(slot_number) + "/power-management", json=request, auth=login)
        if response.status_code == requests.codes.ok:
            print("Power management configured")
            request = {
                "pin": 1,
                "state": "high"
            }
            response = requests.post(host_rest_api + str(slot_number) + "/output/state", json=request, auth=login)
            if response.status_code == requests.codes.ok:
                print("Output 1 is set to HIGH")
            else:
                print("Failed changing output")

            response = requests.get(host_rest_api + str(slot_number) + "/input/values", auth=login)
            if response.status_code == requests.codes.ok:
                response = response.json()
                print("Voltage on output is: " + str(response['pins'][0]['value']) + " mV ")
            else:
                print("Failed getting values")

            response = requests.get(host_rest_api + str(slot_number) + "/notification/1", auth=login)
            if response.status_code == requests.codes.ok:
                response = response.json()
                print("Notification for pin: " + str(response))
            else:
                print("Failed getting notification")

            request = {"reset": "yes"}
            response = requests.post(host_rest_api + str(slot_number) + "/reset", json=request, auth=login)
            if response.status_code == requests.codes.ok:
                print("Successfully reset device after test")
            print("")
        else:
            print("Error response for slot " + str(device['slot_number']))
else:
    print("Error response")

Output:

Output config for module on slot 3:
Power management configured
Output 1 is set to HIGH
Voltage on output is: 4739 mV
Notification for pin: {'under_voltage_alert': False, 'high_voltage_alert': False, 'high_current_alert': False, 'custom_voltage_alert': False}
Successfully reset device after test

Output config for module on slot 4:
Power management configured
Output 1 is set to HIGH
Voltage on output is: 4739 mV
Notification for pin: {'under_voltage_alert': False, 'high_voltage_alert': False, 'high_current_alert': False, 'custom_voltage_alert': False}
Successfully reset device after test

Output config for module on slot 6:
Power management configured
Output 1 is set to HIGH
Voltage on output is: 4750 mV
Notification for pin: {'under_voltage_alert': False, 'high_voltage_alert': False, 'high_current_alert': False, 'custom_voltage_alert': False}
Successfully reset device after test