Hello All :),
I would like use OpenEMS to monitor a PV device via Rest APIs. I’m not able to find satisfactory documentation about the setup and use of the controllers available. Specifically:
How do I start the API service? [Is it running by default/ do I make a change in the config files]
When I save a controller in the Apache ConfigManager, I get webSocket errors.
In general, are there any code samples/Documentation/Guides for how to use the various components? How do I go about getting familiar with the OpenEMS environment?
Hello,
no there are not so many documentations out, yet. Cause most of us are full with workload :D.
just start the alphabeticSchedular and the “Rest Api”, than you can talk to openems by rest.
I am trying to use the REST-Api controller to get data from my system, as documented here
I am unable to get authentication to work. The documentation mentions using admin or user as passwords but neither work. We do actually have a user authentication system with users/passwords but none of those work either.
If I remove x:user and send http://192.168.1.10:8084/rest/channel/_sum/EssSoC
Talend sends the command and Edge responds
{“jsonrpc”:“2.0”,“id”:“00000000-0000-0000-0000-000000000000”,“error”:{“code”:1003,“message”:“Authentication failed”,“data”:}}
Using a web browser to send the request http://x:user@192.168.1.10:8084/rest/channel/_sum/EssSoC
gets the same response as above
{“jsonrpc”:“2.0”,“id”:“00000000-0000-0000-0000-000000000000”,“error”:{“code”:1003,“message”:“Authentication failed”,“data”:}}
In conclusion:
Talend doesn’t work at all if I put in the x:user
Using a browser sends the command to Edge but authentication fails.
Please, how do I get this to work? How do I authenticate with the REST-Api controller
I’m not at all technical so these are just guesses, please let me know how far wrong I am.
What does the "x:user " relate to? it kinda looks like a file path but also doesn’t and I don’t think a file path has a place in a command like this.
I believe that the authentication we use is only on the backend whereas the REST API is in edge. So I don’t see that it will be the same authentication system/credentials.
Which leaves me to question:
*What authentication is the API looking for?
*Where is the API verifying the data for authentication ?
If we can find that maybe we can begin to understand the issue?
Hi,
You should add an HTTP Basic Auth header with the username and password to your request. The HTTP standard has changed and putting the password and user directly in the URL won’t work anymore.
Send the request to http://192.168.1.10:8084/rest/channel/_sum/EssSoC with the Basic Auth header.
Additionally, here is some python code I wrote to set a value and read it back. I read it back as the response to the POST gives no indication that it was successful. Also note that “name”: “power” is not documented anywhere I could find. All the channels revealed on the display are Read Only (eg _PropertyPower). I guessed at the word ‘power’ by looking at the debug example and looking in the code.
I hope this helps someone…
import requests
from requests.auth import HTTPBasicAuth
import time
url = "http://192.168.2.12:8084"
getEndpoint = "/rest/channel/ctrlFixActivePowerRESTapi/_PropertyPower"
postEndpoint = "/jsonrpc"
auth = HTTPBasicAuth('x', 'admin')
headers = {
'Content-Type': 'application/json'
}
#power in watts
power_W = 12345
print (power_W)
data = {
"method": "updateComponentConfig",
"params": {
"componentId": "ctrlFixActivePowerRESTapi",
"properties": [{
"name": "power",
"value": power_W
}]
}
}
postresponse = requests.post(url+postEndpoint, headers=headers, json=data, auth=auth)
print(postresponse.status_code)
print(postresponse.json())
#need a small delay before sending the next request, this for OEMS to process the power setting request
time.sleep(1)
getresponse = requests.get(url+getEndpoint, auth=auth)
print (getresponse.status_code)
print (getresponse.json())