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://.
Python examples
Get voltage, current and power
Example:
import requests
base_url = "http://localhost/api/power/1.0/"
# For tokens see http://noreya-nexus.local/nexuscontrolui/system/settings#access-token
login = ("token","")
resp = requests.get(base_url, auth=login)
if resp.status_code == requests.codes.ok:
response = resp.json()
for device in response['devices']:
print("Voltage, current and power values for Power Module on slot " + str(device['slot_number']) + ":")
resp = requests.get(base_url + str(device['slot_number']) + "/stats", auth=login)
if resp.status_code == requests.codes.ok:
response = resp.json()
voltage_3v3 = round(response['voltage_3v3']/1000,3)
voltage_5v0 = round(response['voltage_5v0']/1000,3)
voltage_12v = round(response['voltage_12v']/1000,3)
current_3v3 = round(response['current_3v3']/1000,3)
current_5v0 = round(response['current_5v0']/1000,3)
current_12v = round(response['current_12v']/1000,3)
power_3v3 = round(voltage_3v3*current_3v3,3)
power_5v0 = round(voltage_5v0*current_5v0,3)
power_12v = round(voltage_12v*current_12v,3)
print("3V3 rail voltage/current/power: " + str(voltage_3v3) + "V * " + str(current_3v3) + "A = " + str(power_3v3) + "W")
print("5V0 rail voltage/current/power: " + str(voltage_5v0) + "V * " + str(current_5v0) + "A = " + str(power_5v0) + "W")
print("12V rail voltage/current/power: " + str(voltage_12v) + "V * " + str(current_12v) + "A = " + str(power_12v) + "W")
else:
print("Error response for slot " + str(device['slot_number']))
else:
print("Error response")
Output:
Voltage, current and power values for Power Module on slot 1:
3V3 rail voltage/current/power: 3.302V * 0.585A = 1.932W
5V0 rail voltage/current/power: 4.938V * 0.397A = 1.96W
12V rail voltage/current/power: 11.945V * 0.002A = 0.024W
Fan control
Example:
import requests
import time
base_url = "http://localhost/api/power/1.0/"
# For tokens see http://noreya-nexus.local/nexuscontrolui/system/settings#access-token
login = ("token","")
def check_fan(slot_number):
response = requests.get(base_url + str(slot_number) + "/fan", auth=login)
if response.status_code == requests.codes.ok:
response = response.json()
if response['fan_forced']:
print("Fan is controlled by the driver")
else:
print("Fan is controlled by the firmware")
print("Fan speed is: " + str(response['fan_current_mode']) + '%')
print("Fan setting is: " + str(response['fan_setting_mode']) + '%')
if (response['fan_current_mode'] != response['fan_setting_mode']) and response['fan_forced']:
print ("Fan setting is going to be applied within 10 seconds")
return True
elif response['fan_forced']:
print ("Fan setting applied!")
print ("")
return False
else:
raise RuntimeError("Could not get fan status")
response = requests.get(base_url, auth=("", ""))
if response.status_code == requests.codes.ok:
response = response.json()
for device in response['devices']:
slot_number = device['slot_number']
print("Fan control for Power Module on slot " + str(slot_number) + ":")
response = requests.get(base_url + 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 = {"measurement_enabled": True}
response = requests.post(base_url + str(slot_number) + "/fan/rpm", json=request, auth=login)
if response.status_code == requests.codes.ok:
print("Fan rpm measurement enabled")
else:
print("Enabling RPM measurement failed")
check_fan(slot_number)
print("")
request = {"fan_forced": True, "fan_mode": 100}
response = requests.post(base_url + str(slot_number) + "/fan", json=request, auth=login)
if response.status_code == requests.codes.ok:
print("Fan speed set to 100%")
while check_fan(slot_number): # Worst case it can take 10 seconds until the mode changes!
time.sleep(1)
else:
print("Could not set fan mode")
time.sleep(2) # It takes at least a second before the RPM value is available
response = requests.get(base_url + str(slot_number) + "/fan/rpm", auth=login)
if response.status_code == requests.codes.ok:
response = response.json()
print("Fan rounds-per-minutes: " + str(response['rpm']))
else:
print("Could not get fan rpm value")
response = requests.get(base_url + str(slot_number) + "/reset", auth=login)
if response.status_code == requests.codes.ok:
print("Successfully reset device")
else:
print("Error response")
Output:
Fan control for Power Module on slot 1:
Successfully reset device
Fan rpm measurement enabled
Fan is controlled by the firmware
Fan speed is: 0%
Fan setting is: 100%
Fan speed set to 100%
Fan is controlled by the driver
Fan speed is: 0%
Fan setting is: 100%
Fan setting is going to be applied within 10 seconds
Fan is controlled by the driver
Fan speed is: 0%
Fan setting is: 100%
Fan setting is going to be applied within 10 seconds
Fan is controlled by the driver
Fan speed is: 0%
Fan setting is: 100%
Fan setting is going to be applied within 10 seconds
Fan is controlled by the driver
Fan speed is: 100%
Fan setting is: 100%
Fan setting applied!
Fan rounds-per-minutes: 4500
Successfully reset device