<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://nearbus.xyz/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Power_Monitor</id>
		<title>Power Monitor - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://nearbus.xyz/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Power_Monitor"/>
		<link rel="alternate" type="text/html" href="https://nearbus.xyz/mediawiki/index.php?title=Power_Monitor&amp;action=history"/>
		<updated>2026-05-21T00:17:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://nearbus.xyz/mediawiki/index.php?title=Power_Monitor&amp;diff=133&amp;oldid=prev</id>
		<title>Nearwiki: Created page with &quot;This example shows how to implement a real time Power Monitor in JavaScript for a mobile device. This implementation require an Xively account (www.xively.com) in order to get...&quot;</title>
		<link rel="alternate" type="text/html" href="https://nearbus.xyz/mediawiki/index.php?title=Power_Monitor&amp;diff=133&amp;oldid=prev"/>
				<updated>2018-03-29T20:56:17Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;This example shows how to implement a real time Power Monitor in JavaScript for a mobile device. This implementation require an Xively account (www.xively.com) in order to get...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This example shows how to implement a real time Power Monitor in JavaScript for a mobile device. This implementation require an Xively account (www.xively.com) in order to get the historical data sequence in a chart format. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
[[File:mobile_power_meter.png|160px]]&lt;br /&gt;
&lt;br /&gt;
smartphone interface example&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===System Implementation===&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This implementation works in manual mode asking the remote agent (Arduino) the power reading in a periodic way. The system use the Cosm Connector to send the reading to Xively in order to show it in a graphical way. On the other hand a independently javascript code running from a mobile device ask to the NearBus system in a periodic way the last power reading to show it on the mobile device.  &lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
Only two hadware components are needed to implement this real time Power Monitor: An Arduino Board (Ethernet / WiFi) and an AC Current Sensor [http://www.seeedstudio.com/wiki/Non-invasive_AC_current_sensor%2830A_max%29] as showed in the following picture.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
[[File:arduino_power_monitor.png]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The AC Current Sensor is connected to the A0 analog inpur on the Arduino board.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
 '''IMPORTANT: the current sensor only should be installed on only one power wire (of two). If you place both power wires into the sensor,'''&lt;br /&gt;
 '''then the reading will be 0 (zero)'''.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Configuring the Manual Mode===&lt;br /&gt;
&lt;br /&gt;
In order to get samples from the sensor in a continous way, you should configure the '''RMS_INPUT''' service in manual mode for the selected channel (the port in which the sensor will be connected). In this example we will use the Channel 0 (A0 3 in an Arduino platform). The following picture shows this configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:manual_mode_power.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
===Xively Configuration (formerly Cosm)===&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
This screen allows you send to Xively (www.xively.com) the values received from or transmitted to the remote device over each channel.&lt;br /&gt;
&lt;br /&gt;
[[File:xively_config_power.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''Stream ID: ''' This field allows you to set the Xvely's (Cosm) datastream where you want to send the signal.&lt;br /&gt;
&lt;br /&gt;
* '''IN / OUT:''' This option allows you to indicate if you want to send a readed value (input) from the remote device or the written value (output) to the remote device for each channel.&lt;br /&gt;
&lt;br /&gt;
* '''Constant and Offset:''' The main advantage of this feature is that it allows you to apply a basic transfer function to your signal before sending it to Xively (Cosm):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     f(x) = x * K + offset&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''ON: ''' This option allows you to turn on or off the data feed to Xively (Cosm).&lt;br /&gt;
&lt;br /&gt;
* '''Xively Feed and API Key:''' This option allows you to configure the required parameters to connect succesfully to www.xively.com.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
In this example we use a constant factor of 6.6. This factor is obtained in the following way:&lt;br /&gt;
&lt;br /&gt;
*'''Power Line tension:''' 220 Vac&lt;br /&gt;
*'''Current Sensor Ratio:''' 30:1 (30Aac= 1Vac)&lt;br /&gt;
*'''RMS_INPUT scale''': mV (RMS)&lt;br /&gt;
&lt;br /&gt;
 K = 220 * 30 / 1000  = 6.6 [W/mV]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note:''' this is a calibration example. In order to calibrate your Power Monitor you should use a well-known resistive load (and adjust the K factor to match its value).&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The following picture shows a real system power chart (Xively). It is important to remark the amount of information that can be obtained from it. In this example the chart represents a measure of our lab enviroment, where an electric heater (about 1400W) and a small refrigerator (about 175 W) are working together, each with its own power fingerprint, as indicated in red on the Xively  output chart (note that a residual power consumption of 196W is always present).&lt;br /&gt;
 &lt;br /&gt;
[[File:xively_power_chart.png|600px]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Javascript Code===&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The following code will allow you to display the sensed power in a graphical way from a mobile device or desktop computer. In order to run this example, download the following file in you mobile device or computer, change the parameters indicated with &amp;quot;****&amp;quot; and execute it. Double click onto the downloaded &amp;quot;html&amp;quot; file in order to run it on your default browser.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example is calibrated to use a 30A AC Current Sensor [http://www.seeedstudio.com/wiki/Non-invasive_AC_current_sensor%2830A_max%29] but you can use any other current sensor sensor that you want (you only should change conversion factor). In this example a conversion factor of 6.6 is used.&lt;br /&gt;
 &lt;br /&gt;
'''Note:''' that the Xively transfer function '''does not affect''' the value read with the RMS_INPUT service.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 '''Download:''' Power_Monitor_0v1.zip [http://www.nearbus.net/downloads/js_apps/Power_Monitor_0v1.zip]&lt;br /&gt;
 &lt;br /&gt;
 In order to run this example you should edit it (eg. notepad) and replace the following parameters:&lt;br /&gt;
 var device_id  = &amp;quot;NB100xxx&amp;quot;;		// You NearBus Device ID&lt;br /&gt;
 var user       = &amp;quot;****&amp;quot;;            	// Your NearBus Web user&lt;br /&gt;
 var pass       = &amp;quot;****&amp;quot;;            	// Your NearBus Web password&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;        &lt;br /&gt;
&amp;lt;!-- ****************************************************************************************************************************** --&amp;gt;  &lt;br /&gt;
&amp;lt;!-- * NEARBUS JAVASCRIPT EXAMPLE - www.nearbus.net                                                                               * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- * Description: This simple code shows how to implement a power monitor on a Smartphone                                       * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- * This example requires an Xively account (www.xively.com) in order to record the power registers in a historical way        * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- * The system is configured to work with a AC Current Sensor                                                                  * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- * Support: info@nearbus.net                                                                                                  * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- ****************************************************************************************************************************** --&amp;gt;  &lt;br /&gt;
&amp;lt;!-- * REVISION HISTORY                                                                                                           * --&amp;gt;&lt;br /&gt;
&amp;lt;!-- * v0.1 - 28-11-13 - Initial Release                                                                                          * --&amp;gt; &lt;br /&gt;
&amp;lt;!-- ****************************************************************************************************************************** --&amp;gt; &lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;http://code.jquery.com/jquery-1.9.1.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;PAGE&amp;quot; &amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type='text/javascript' src='http://nearbus.net/downloads/js_apps/nearapi_v05.js'&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
// +--------------------------------------------------------------------+&lt;br /&gt;
// | To run this example you should replace the following parameters    |&lt;br /&gt;
// | device_id         Your device ID, or.. devices ID :)               |&lt;br /&gt;
// | user              Your NearBus Web user                            |&lt;br /&gt;
// | pass              Your NearBus Web password                        |&lt;br /&gt;
// +--------------------------------------------------------------------+&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
// MAIN CONFIGURATION&lt;br /&gt;
//////////////////////////////////&lt;br /&gt;
var device_id     = &amp;quot;NB100xxx&amp;quot;;     // Your device ID&lt;br /&gt;
var user          = &amp;quot;****&amp;quot;;         // Your NearBus Web user&lt;br /&gt;
var pass          = &amp;quot;****&amp;quot;;         // Your NearBus Web password&lt;br /&gt;
var LOOP_DELAY    = 2000;&lt;br /&gt;
var power         = 0;&lt;br /&gt;
    &lt;br /&gt;
    window.onload = function ()&lt;br /&gt;
    {&lt;br /&gt;
        ///////////////////////////////////&lt;br /&gt;
        // Function: Main Loop&lt;br /&gt;
        ///////////////////////////////////&lt;br /&gt;
        setInterval( function()&lt;br /&gt;
        {&lt;br /&gt;
            ret = NearAPIjs( &amp;quot;RMS_INPUT&amp;quot;, device_id , 0, 0, &amp;quot;RONLY&amp;quot; );&lt;br /&gt;
            if( ret != &amp;quot;WAIT&amp;quot; &amp;amp;&amp;amp; !isNaN(ret) ) {&lt;br /&gt;
                power = Math.round( ret * 6.6 ); &lt;br /&gt;
                $('#field_1').text( power.toString() );    &lt;br /&gt;
            }&lt;br /&gt;
        }, LOOP_DELAY );                &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body bgcolor=&amp;quot;#000&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;div style=&amp;quot;text-align:center; width:950px&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://nearbus.net/images/logo_nearbus.png&amp;quot; width=&amp;quot;140&amp;quot; heisgth=&amp;quot;78&amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;div style=&amp;quot;text-align:center; width:950px; font: bold 60px Arial; color:orange;&amp;quot;&amp;gt;POWER MONITOR&amp;lt;/div&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- this line embed a 750 x 400px feed chart form www.xively.com (former cosm.com) --&amp;gt; &lt;br /&gt;
&amp;lt;!-- you should replace the &amp;quot;feed&amp;quot; and the &amp;quot;zone&amp;quot; in order to get the chart from www.xively.com  --&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;div_temp_chart_cm&amp;quot;&amp;gt; &amp;lt;img src=&amp;quot;https://api.cosm.com/v2/feeds/****YOUR_FEED_ID_HERE****/datastreams/****YOUR_CHANNEL_NAME_HERE****.png?width=750&amp;amp;height=400&amp;amp;colour=%23f15a24&amp;amp;duration=3hours&amp;amp;show_axis_labels=true&amp;amp;detailed_grid=true&amp;amp;timezone=****YOUR_ZONE_HERE****&amp;quot; &amp;gt; &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;div style=&amp;quot;text-align:center; width:950px; font: bold 60px Arial; color:orange;&amp;quot;&amp;gt;watts&amp;lt;/div&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;div id=&amp;quot;field_1&amp;quot; style=&amp;quot;text-align:center; width:950px; font: bold 300px Arial; color:orange;&amp;quot;&amp;gt;. . . .&amp;lt;/div&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Nearwiki</name></author>	</entry>

	</feed>