[ { "serialNumber": "121440006252", "lastReportDate": 1484971459, "devType": 1, "lastReportWatts": 172, "maxReportWatts": 255 }, { "serialNumber": "121440009848", "lastReportDate": 1484971423, "devType": 1, "lastReportWatts": 220, "maxReportWatts": 251 },
etc for each of my systems Inverters. I wish to simply run a html file on my browser and
display the results in a eash to read format and show the totals of energy currently produced and the maximum.
A friend wrote the necessary .html with java script and tested it on the format of file that I provided, but when I try to do it I can't pass the authentication protocol the Enphase unit expects.
If I use a standard $.get or $.getJSON on the URL – no matter how I try and pass authentication details it fails, CORS errors, Network error 00000efd0, across all browser – Firefox, Edge, Chrome. I have tried this both running the file directly from the browser and via starting a Python webserver on my html drive and calling the html file from 127.0.0.1:8000/enphase.html
When I switch to using $.getScript – I get successful return codes (success, 200, but the data passed is undefined). Possibly becuase this call is asynchronous and data hasn't yet been returned when I tried and wirte it to console.log or parse it. When I investigate the headers and parameters and returned result using the browser in debug mode – all the data for my 31 inverters is present in the memory log under 192.168.0.12/api/v1/production/inverters.
I did try re-structuring the code to execute the GetScript first – which toggles the Enphase Envoy-s unit to ask for authentication via a pop up window in the browser running the html file. Once these details are passed the call progresses – but with the returned data being classed as undefined and failing the string parsing.
But I then added a second GetJSON call immediately after the GetScript call to see if the Authentication details created for the Get Script call where inherited by the subsequent GetJSON call – unfortunately they are not and a CORS error is recorded, buts its a 401 error – failed authentication.
In firefox Debugger – it appears the GetScript call is a JS call type – which fails with a 401 – but the credentials when entered into the pop up Window that appears then immediately causes the Envoy to return the correct data with a 200 status code.
When the GetJSON call is launched it is a JS XHR request and it doesn't trigger the credentials logic the GetScript call does, so it doesn't get the required authentication token / credentials and it simply fails with a 401 status.
* * * * * *I wonder if there is any way to have the GetJSON call trigger the Envoy to ask / launch the credentials pop up window the GetScript did – so it too could pass authentication?
Code from my friend with my attempts at getting the authentication to work is attached. The main issue I have is either having $.getJSON realise in the data field it has passed back all the correct results - and beilng able to parse this currently labelled undefined data, or getting the #.getJSON call to either pass the credentials correctly or trigger the Enphase to pop up the supply user name and password window that the $.getScript command does so that I can enter the name and password and have the formatting cod work!
var url = "http://192.168.0.12/api/v1/production/inverters?locale=en&user=envoy&password=012345";
$.getScript ( url, function( data, textStatus, jqxhr ) {
//
// Log the calls status – success, 200, undefined, Load was performed
//
console.log( textStatus );
console.log( jqxhr.status );
console.log( data );
console.log("Load was performed");
returns success, 200 status and in the debugger I can see the data is all there, but the data field is marked undefined - so its frustratingly unusable. Whereas
$.getJSON("http://192.168.0.12/api/v1/production/inverters?locale=en&user=envoy&password=011842", function(data) {
console.log(JSON.stringify(data));
console.log( textStatus );
console.log( jqxhr.status );
console.log( data );
console.log("Load was performed for getJSON");
})
.done(function() { console.log('getJSON request succeeded!'); })
.fail(function(jqXHR, textStatus, errorThrown) { console.log('getJSON request failed! ' + textStatus); })
.always(function() { console.log('getJSON request ended!'); });
Fails on a 401 - acess credentials weren't supplied error. Even trying to send the acess credentials prior to the getJSON call with a beforeSend command hasn't helped so far.
Many thanks if anyone can point in the right firection or get me further down the path. My googling JQuery lead me to this forum and documentation that seems to say getScript returns undefined data.
Matthew