Jump to content


Photo

Simplest way to display local IP JSON data as a spreadsheet / html page on my PC?


  • Please log in to reply
24 replies to this topic

#21 g__day

g__day

    Champion

  • Hero
  • 7,838 posts

Posted 15 February 2017 - 08:27 PM

Many thanks so it's still a $.getJSON("URL?" Just add the ? At the end.

Is there any call you can make to the URLs to get it to tell you what authentication protocol it expects for its user id and password?

Otherwise it's try many different protocol modified URLs strings, tokens etc to attempt to see which is the correct method.

I have pinged a message to Enphase to see if they will reveal the correct method.

I will also try experimenting with the original type in the URL from a browser and try and add the user id and password in the call to see if I can find what structure of call works. Normally from a browser I enter the URL then it brings up a window asking for user id and password - enter the correct details and everything then works fine when you continually press refresh until you close the browser - so I guess it creates a session token or cookie somewhere that expires once the session closes? Wish there was a way is seeing exactly what happens and what it therefore expects!

Cheers,
Matt

Edited by g__day, 15 February 2017 - 10:37 PM.

Talent + Integrity = Atomic!

#22 g__day

g__day

    Champion

  • Hero
  • 7,838 posts

Posted 21 February 2017 - 07:58 AM

Still waiting Enphase's response...

 

Reading up on different means to pass credentials I came across this... what do you think - should this be merged into your code somehow?

 

$,getJSON({ 'url' : 'http://host.com/action' 'othersettings' : 'othervalues ', 'beforesend' : function(xhr) {

// May need to use the string Authorization instead of Authentication

  xhr, setRequestHeader("Authentication", "Basic " + encodeBase64(username + ":" + password)},

  success: Function(result) { alert('done'); } });

 

Its mind boggling that it is so challenging to pass the user name and password to a URL when it's not all executed in a browser.

 

If I execute the URL from Chrome and press debug - will I see how it invokes and confirms the credentials - or will this be hidden server side code?

 

Cheers,

  Matt


Talent + Integrity = Atomic!

#23 g__day

g__day

    Champion

  • Hero
  • 7,838 posts

Posted 12 June 2017 - 10:30 AM

Been revisiting this code and trying it on latest versions of Chrome, Firefox and Edge and trying to clear the error messages.  Most of which related to not specifying the doc type? rather than CORS issues from the browser not allowing localhost on my machine to talk to 192.168.0.12.

 

Now its complaining about not being able to load the style sheet - so no authentication issus reported - under Edge thankfully, but to die on the Stylesheet seems like ignomious defeat!

 

My protocol is to use Admin CMD prompt to start a Python http web server in the directory with the Enphase.html script - so elevated CMD, CD to Solar directory, python -m http.server to startrt a 127.0.0.1:8000 webserver

 

Then under my Broswers in debug mode I try to run 127.0.0.1:8000/enphase.html

 

The error code in Edge is

 

GET http://127.0.0.1:8000/Enphase.html [HTTP/1.0 200 OK 52ms]
GET https://maxcdn.boots...otstrap.min.css [HTTP/2.0 304 Not Modified 177ms]
GET https://code.jquery....ry-3.1.1.min.js [HTTP/2.0 304 Not Modified 181ms]
Error in parsing value for '-webkit-text-size-adjust'.  Declaration dropped.  bootstrap.min.css:5:132
Unknown pseudo-class or pseudo-element '-webkit-inner-spin-button'.  Ruleset ignored due to bad selector.  bootstrap.min.css:5:1544
Unknown pseudo-class or pseudo-element '-webkit-search-cancel-button'.  Ruleset ignored due to bad selector.  bootstrap.min.css:5:1778
Unknown property 'orphans'.  Declaration dropped.  bootstrap.min.css:5:2691
Unknown property 'widows'.  Declaration dropped.  bootstrap.min.css:5:2700
Unknown property '-moz-osx-font-smoothing'.  Declaration dropped.  bootstrap.min.css:5:3676
Expected colour but found 'auto'.  Expected colour but found '-webkit-focus-ring-color'.  Expected end of value but found '-webkit-focus-ring-color'.  Error in parsing value for 'outline'.  Declaration dropped.  bootstrap.min.css:5:15689
Error in parsing value for 'margin-top'.  Declaration dropped.  bootstrap.min.css:5:35720
Expected colour but found 'auto'.  Expected colour but found '-webkit-focus-ring-color'.  Expected end of value but found '-webkit-focus-ring-color'.  Error in parsing value for 'outline'.  Declaration dropped.  bootstrap.min.css:5:35947
Unknown pseudo-class or pseudo-element '-ms-input-placeholder'.  Ruleset ignored due to bad selector.  bootstrap.min.css:5:36878
Unknown pseudo-class or pseudo-element '-webkit-input-placeholder'.  Ruleset ignored due to bad selector.  bootstrap.min.css:5:36926
Unknown pseudo-class or pseudo-element '-ms-expand'.  Ruleset ignored due to bad selector.  bootstrap.min.css:5:36978
Expected media feature name but found '-webkit-min-device-pixel-ratio'.  bootstrap.min.css:5:37312
Error in parsing value for 'margin-top'.  Declaration dropped.  bootstrap.min.css:5:38425
Unknown property 'user-select'.  Declaration dropped.  bootstrap.min.css:5:45471
Expected colour but found 'auto'.  Expected colour but found '-webkit-focus-ring-color'.  Expected end of value but found '-webkit-focus-ring-color'.  Error in parsing value for 'outline'.  Declaration dropped.  bootstrap.min.css:5:45652
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:45998
Expected colour but found 'solid\9 '.  Expected end of value but found 'solid\9 '.  Error in parsing value for 'border-top'.  Declaration dropped.  bootstrap.min.css:5:54924
Expected 'none', URL, or filter function but found 'progid'.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:56291
Expected colour but found 'solid\9 '.  Expected end of value but found 'solid\9 '.  Error in parsing value for 'border-bottom'.  Declaration dropped.  bootstrap.min.css:5:56836
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:85213
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:86118
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:86744
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:87376
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:88006
Unknown property 'zoom'.  Declaration dropped.  bootstrap.min.css:5:88442
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:105685
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:105794
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:107003
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:107056
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:108206
Unknown property 'line-break'.  Declaration dropped.  bootstrap.min.css:5:108243
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:108268
Unknown property 'line-break'.  Declaration dropped.  bootstrap.min.css:5:110250
Expected media feature name but found 'transform-3d'.  bootstrap.min.css:5:112088
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:113425
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:113581
Expected 'none', URL, or filter function but found 'progid'.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:113840
Error in parsing value for 'background-image'.  Declaration dropped.  bootstrap.min.css:5:114124
Expected 'none', URL, or filter function but found 'progid'.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:114383
Expected 'none', URL, or filter function but found 'alpha('.  Error in parsing value for 'filter'.  Declaration dropped.  bootstrap.min.css:5:114608
Expected colour but found '#\30 00\9 '.  Error in parsing value for 'background-color'.  Declaration dropped.  bootstrap.min.css:5:115557
GET https://maxcdn.boots...otstrap.min.css [HTTP/2.0 200 OK 0ms]
GET https://maxcdn.boots...rap.min.css.map

 

The latest code is

[code=auto:0]

 <!DOCTYPE html>
   <html>
        <head>
            <link rel="stylesheet"  type="text/css" media="screen" charset="UTF-8" href="https://maxcdn.boots...otstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
            <script src="https://code.jquery....ry-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
            <style>
                table td.box {
                    width: 250px;
                    border-left: 1px solid #000000;
                    border-right: 1px solid #000000;
                }
                table td.box div {
                    background-color: #0000FF;
                }
            </style>
        </head>
        <body>
            <div id="results"></div>
            <script>            
                $(function() {
                    $.getJSON("envoy:011842@http://envoy:011842@...ction/inverters", function(data) {                    
                        var table = $("<table><tr><th>Serial Number</th><th>Last Report Date</th><th>Status</th><th>Last</th><th>Max</th></tr></table>").addClass("table table-striped");
                        $.each(data, function(index, item) {                                                
                            var percent = ((item.lastReportWatts / item.maxReportWatts) * 100);                      
                            var row = $("<tr></tr>").html("<td>" + item.serialNumber + "</td><td>" + new Date(item.lastReportDate) + "</td><td class='box'><div style='width: " + percent + "%'>&nbsp;</div></td><td>" + item.lastReportWatts + "</td><td>" + item.maxReportWatts+ "</td>");
                            table.append(row);                       
                        });                                       
                        $("#results").append(table);
                    })
                });
            </script>
        </body>
    </html>

[\code]


Talent + Integrity = Atomic!

#24 g__day

g__day

    Champion

  • Hero
  • 7,838 posts

Posted 14 June 2017 - 01:49 PM

Getting closer!  Found that the correct structure to pass the command is 

 

$.getJSON("http://192.168.0.12/api/v1/production/inverters?locale=en&user=envoy&password=011842", function(data) { 

 

So now In edge I am receiving SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd. Which I believe is Edge won't link to a Localhost domain?  At least in one browser I seem to have progressed past the authentication status - so that is a big step forward!


Edited by g__day, 14 June 2017 - 01:49 PM.

Talent + Integrity = Atomic!

#25 g__day

g__day

    Champion

  • Hero
  • 7,838 posts

Posted 17 June 2017 - 12:21 AM

So tenacity... I recieved more and more arcane issues with this then I tried just running the IP in the browser with debug on - and watched how it sent and recieved the headers.  They I googled a simple how to call a web address from JSON and they provided a sample using $.getSCRIPT rather than $.getJSON - and this script worked - in that it returned success and I could see the inverter data in the debug window list returned - so now I just have to understand how to use the formatting code supplied with the $.getJSON to $.getSCRIPT

 

Huge success.  I tried simply changing the word JSON to SCRIPT - but on the screen it just handed me the title line and the total power line as 0 0 - so it didn't process any of inverter enteries.  But at least now the inverter enteries are being passed!

 

Off now to research how to use $.getSCRIPT to format a list the way it was suggested it should be!

 

Next challenge - I can't find a way to authenticate successfuly using $.get variants other than $.getScript - which launches a window ask for user name and password (which it remembers) then on ok it returns all the results - but doesn't assocaite these results with the Data field!

 

So tantalisingly close - the data is actually there - but hard to reach!

 

In the code below my issue now is console.log( data ); returns undefined - whilst I can see in the debugger call stack the data is actually returned and just waiting for parsing.  I have to find some way to connect the return data to my data variable so the $.each (data, function(index, item) {  line can process it!

     <script>            
                $(function() {
            var url = "http://192.168.0.12/api/v1/production/inverters?locale=en&user=envoy&password=011842";
            
            $.getScript ( url, function( data, textStatus, jqxhr ) {
            console.log( data );
            console.log( textStatus );
            console.log(jqxhr.status );
            console.log("Load was performed");
                            
                        var table = $("<table><tr><th>Serial Number</th><th>Last Report Date</th><th>Status</th><th>Last</th><th>Max</th></tr></table>").addClass("table table-striped");
                        var totalLastReportWatts = 0;
                        var totalMaxReportWatts = 0;

                     $.each( data, function(index, item) {  
            console.log( index );                                              
                        totalLastReportWatts += item.lastReportWatts;
                        totalMaxReportWatts += item.maxReportWatts;

                        var percent = ((item.lastReportWatts / item.maxReportWatts) * 100);                      
                        var row = $("<tr></tr>").html("<td>" + item.serialNumber + "</td><td>" + new Date(item.lastReportDate) + "</td><td class='box'><div style='width: " + percent + "%'>&nbsp;</div></td><td>" + item.lastReportWatts + "</td><td>" + item.maxReportWatts+ "</td>");
                        table.append(row);                       
                       });
                                   
                    var totalsRow = $("<tr></tr>").html("<td colspan='3'></td><td>" + totalLastReportWatts + "</td><td>" + totalMaxReportWatts + "</td>");
                    table.append(totalsRow);                       
                    $("#results").append(table);
            });

Edited by g__day, 17 June 2017 - 02:59 AM.

Talent + Integrity = Atomic!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users