Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution achieved, finally, was like this:</p> <p>I did it with a jQuery statement and reusing the javascript code of <strong>Google Charts</strong>.</p> <p>First I added javascript and jQuery tags in the html file:</p> <pre><code>&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type='text/javascript' src='https://www.google.com/jsapi'&gt;&lt;/script&gt; </code></pre> <p>Then I merged jquery code and javascript code that I had in one script:</p> <pre><code>&lt;script type='text/javascript'&gt; // Needed this var so that I could use it in other places of the code var t; jQuery.get('http://url_to_my_rpi/file_to_download.txt',function(data){ console.log(data) t=data; },'text'); google.load('visualization', '1', {packages:['gauge']}); google.setOnLoadCallback(drawChart); function drawChart() { t=eval(t); var data = google.visualization.arrayToDataTable([ ['Label', 'Value'], ['Temp', t],]); // (... more javascript with Google Charts options, display parameters..) &lt;/script&gt; </code></pre> <p>Finally, and even if it's not listed as the main question, be sure to enable *mod_headers* on your apache and add <em>Header set</em> to <em>apache2.conf</em> file (In my case: <em>/etc/apache2/apache2.conf</em>)</p> <p><strong>1) Enable the module:</strong></p> <p>a2enmod headers</p> <p><strong>2) Add the line on your configuration file</strong></p> <p>Header set Access-Control-Allow-Origin "*"</p> <p><strong>3) Restart apache 2</strong></p> <p><strong>4) In case the 3 steps above didn't work</strong>, follow the instrcutions by entering in <a href="http://harthur.wordpress.com/2009/10/15/configure-apache-to-accept-cross-site-xmlhttprequests-on-ubuntu/" rel="nofollow">this website</a> or reinstall apache2.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI think it's darn cool of you to actually follow up and post your solution including the configuration steps needed! For future readers I'd like to point out that you have solved the difficult part (accessing the logfile outside of your hosting-root) by simply placing a short file containing the value you need inside your www root (as you have commented on my answer).
      singulars
    2. COHowever (realizing you are new to javascript), I 'must' object against the use of `eval` (or *evil* as javascripters commonly call it) to convert a text-string (representing a number) to a number. Not because it is unsafe (you hardcoded the file link to a file you control) but eval also has a massive overhead (of cloning your variable scope etc.) whilst a simple `Number(stringVariable)` or `parseFloat(stringVariable, 10)` (10 for a decimal base/radix) is the correct way.
      singulars
    3. COOr even simpler, using `+` operator: `+stringVariable`. Advice: never visit/read/copy anything ever again from the source where you got your code: `t=eval(t);`. Lastly I setup an [example on jsfiddle](http://jsfiddle.net/XkxSb/) for you, demonstrating a more reliable (event-driven, think of loading-time vs decencies) and flexible (one/more temperature gauge objects that can be `refresh()`ed (even at an interval, etc) without reloading the page, reaping the benefits of ajax) method. Just to get you started! Hope that helps!
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload