I've been trying to communicate to my inverter to get access to lots of goodies. I have the direct HTTP which will return JSON data in a browser so I thought I'd simply add the calls into a Device Driver but things aren't working as expected. I'm not experienced but blundering my way through trial and error!
So to access in a browser I first type in:-
http://m.ginlong.com/cpro/login/validateLogin.json?userName=xxxxxxxx@yahoo.co.uk&password=xxxxxxx&lan=2&domain=m.ginlong.com&userType=C
This seems to set up a session and returns a confirmed login in JSON format then I call the next in my browser and it shows LOADS of JSON information which is just what I need:-
http://m.ginlong.com/cpro/epc/plantDetail/showPlantDetailAjax.json?plantId=xxxxxx&APP_ID=xxxxxxxxxxxxxxx&APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
So I looked at how other people had done stuff and thought I'd try to just start with the bare minimum to extract the information and then I can probably work out the rest later. Below is what I have created and it seems to do the Login part without any problems but then comes up with an error:-
Something went wrong: groovyx.net.http.HttpResponseException: Not Found
I'd appreciate some guidance please, as I'm way out of my depth!!
metadata {
definition (name: "aaa solar prototype", namespace: "Ginlong API", author: "") {
capability "Refresh"
capability "Sensor"
command "getStatus"
attribute "voltage", "number"
attribute "current", "number"
}
}
def getSolarData() {
def params = [
uri: "http://m.ginlong.com/cpro/epc/plantDetail/showPlantDetailAjax.json?plantId=xxxxxx&APP_ID=xxxxxxxxxxxxxxx&APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
headers: [
'Accept': '/',
'DNT': '1',
'Cache' : 'false',
'dataType': 'json',
'Accept-Encoding': 'plain',
'Connection': 'keep-alive',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36']
]
try {
httpGet(params) { responseGD ->
log.info "Stage 2 done, $responseGD.data"}
}
catch (e) {log.warn "Error: $er"}
}
def refresh() {
login()
getSolarData()}
def login() {
def params = [
uri: 'http://m.ginlong.com/cpro/login/validateLogin.json?userName=xxxxxxxx@yahoo.co.uk&password=xxxxxxx&lan=2&domain=m.ginlong.com&userType=C',
headers: [
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json, text/javascript, /; q=0.01', // */
'Accept-Encoding': 'sdch',
'DNT': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36'
] ]
try {
httpGet(params) { responseLI ->
logDebug "Stage1 done, $responseLI.data"
}}
catch (e) {log.warn "Error: $er "
}
}