Streaming energy consumption to plotly

I have asked plotly for guidance on how to stream the output of the energy monitor I'm building and they've sent me a link to the temperature streaming project:

I haven't done a lot of coding so I'm not sure what to modify here in order to get a graph W=f(t).

Please move it to the programming section.

cipri92:
Please move it to the programming section.

Why?
If it were a programming question, there'd be code.

This is the example from the Yun specific library from plotly:

#include <PlotlyYun.h>
#include <YunMessenger.h>
#include <Bridge.h>
#include <Console.h>

// Initialize plotly "plotters" with your stream tokens.
// Find your stream tokens in your plotly account here: https://plot.ly/settings
// Initialize as many plotters as you want! Each plotter will send
// data to the same plot as a separate line.
// Make sure that you place these exact-same stream tokens in your `config.json` file
// on the Linino.

plotly plotter1("put_your_10_character_stream_token_here");
plotly plotter2("put_another_token_here");

void setup() {

    // start-up the bridge
    Bridge.begin();

    ////
    // Uncomment the following 3 lines to start the
    // Plotly-Python program on the Linino
    // from the Arduino

    // Process p;
    // p.runShellCommand("/root/run_plotly.sh");
    // while (p.running()){ ; } // do nothing until process finishes

    delay(2000);
    Console.begin();
    while (!Console) {
      ; // wait for Console port to connect.
    }

    Console.buffer(64);
    delay(2000);

    plotter1.timezone = "America/Montreal";
    plotter2.timezone = "America/Montreal";
}

void loop() {
    // Graph data! Place the "y" value that you want to plot
    // the "x" value will automatically be a time-stamped value
    // Each "plotter" will send data to the same plot as separate lines
    plotter1.plot( analogRead(A0) );
    plotter2.plot( analogRead(A1) );

    // You can also set the "x" value manually
    // by placing a pair of points in the plot function:
//    plotter1.plot( millis(), analogRead(A0) );
//    plotter2.plot( millis(), analogRead(A1) );
    delay(100);
}

There are a few things I don't understand. First, why doesn't the program contain login credential lines? Shouldn't I be the only one with the streamed info?

Second: what's with the Linino? Is that a copy of the original Yun?

Third: what's with the json file?

Fourth: what's with the uncommenting the 3 lines from the first part of the code?]

And last, for now: what's with the timezones?

AWOL:
Why?
If it were a programming question, there'd be code.

Now you can move it.

First off, I don't have any personal experience with plotly, but I've used other data services, so the experience may carry over.

cipri92:
First, why doesn't the program contain login credential lines? Shouldn't I be the only one with the streamed info?

It doesn't include them for security reasons. Instead of login credentials, which if intercepted can be used for many different purposes, it includes a unique stream token. That token is tied to your account, and the only thing that it can be used for is to write data to your stream. If it were compromised (by posting code or intercepting the communications) while it could be used to inject false data into the stream, that's all you will be able to do. If the full login credentials were included, besides injecting data into the stream, you would be able to read the past data from the stream, change account settings, etc. A much higher risk.

Second: what's with the Linino? Is that a copy of the original Yun?

That's the old name for the Linux side of the Yun. It is now based solely on OpenWRT. Generally, wherever someone/something makes reference to Linino, you can usually safely pretend it says OpenWRT (or even Linux.)

Third: what's with the json file?

Good question. It's hard to say without seeing the file, or the corresponding Linux code that references it.

Fourth: what's with the uncommenting the 3 lines from the first part of the code?

Uncommenting those lines will cause the Linux side to run the run_plotly.sh script. It's impossible to say what that accomplishes without seeing that script file (and whatever other files it references.)

And last, for now: what's with the timezones?

The plotly servers probably store all data in a common time reference, like UTC. You specify the time zone so that when samples are sent to plotly, the server will know how to adjust the sample's timestamp to get it to the common time reference. That way, you can have sensors all around the world sending in samples, and still be able to correlate the data. (That being said, I don't see where a time stamp is included in the sample -- maybe they took the cheap and easy way in this code and just used millis() instead of a timestamp?)

cipri92:
Now you can move it.

I agree with AWOL, why move it? While there is programming involved, many of the questions you ask seem to be specific to the Yun. I think this is the forum where you will get the best answers. (For example, no other Arduino has the Process class or a process to run under Linux.)

Datalogger and D3.js plot at Yun.

http://forum.arduino.cc/index.php?topic=309600.0

With a little more perseverance, I found a detailed guide on how to stream data from the Yun. Problem is the code used to upload the files is Terminal specific and I'm using Win 7.

Link: arduino-api/README.md at master · plotly/arduino-api · GitHub

Is there a way to upload these without Terminal? I'm not familiar with Linux.

You can use WinSCP to copy the files. This will make your Yun's files appear in an explorer style window, allowing you to easily drag and drop files in either direction. That takes care of steps 3 and 4 of the setup Linino portion.

For step 5, you can use PuTTY. It is a general purpose serial or network communications terminal program.

I use both WinSCP and PuTTY frequently with my Yun. You will find plenty of future uses for them, not just for this one project. (PuTTY also makes a much better Serial Monitor than the one in the Arduino IDE, you just have to make sure you close out PuTTY before trying to upload code over the USB port, as it won't automatically close like the Serial Monitor window does.)

There are, of course, other methods, but these work for me.

cipri92:
::::SNIP::::

There are a few things I don't understand. First, why doesn't the program contain login credential lines? Shouldn't I be the only one with the streamed info?

Second: what's with the Linino? Is that a copy of the original Yun?

Third: what's with the json file?

Fourth: what's with the uncommenting the 3 lines from the first part of the code?]

And last, for now: what's with the timezones?

FIRST, I want to note the link in the Original Post was using the UNO, not the YUN. So many of these instruction are intended to run on a Laptop or Desktop running Linux, NOT the Linux part of the YUN.

The remaining response are general.

On question #1, ShapeShifter has it.
On question #2, ShapeShifter again
#3, JSON is new way to store configuration information. Much of the industry is moving toward it because it is generic enough for most scripting engines. Expect to see more JSON in the future.
#4 ShapeShifter has it. Let me add - it likely runs some python code, which is how the JSON gets read and used.
#5 Timezones are used as ShapeShifter says. But I suspect it is also used for security. Some security protocols are time-based. I suspect this is the case here as well. Along with SS said.

Upload files as suggested by ShapeShifter.

Jesse

Thanks for the info Jesse!

ShapeShifter, I've succeeded on copying the files thorugh WinSCP. Thanks!

But now I'm stuck when using PuTTY. I keep getting "access denied" when trying to login. Tried different users (Yun, Energino - name I gave to the board) and the default password. Nothing.

cipri92:
I keep getting "access denied" when trying to login.

Username: root
Password: whatever_you_gave_during_setup

I'm surprised you didn't have trouble authenticating with WinSCP, it should use the same login credentials?

Ok, now I see.

There are a 2 things I'm not getting:

-when I hover the cursor on the network icon in Windows, I am connected to the Yun but it says "Internet access". It doesn't.

-how can I update if the notebook isn't connected to the web? I'm either on one wi-fi AP - my router or the Yun. The ethernet port from the notebook is useless if the WLAN is used. Should I connect a LAN port from the router to the Yun?

cipri92:
-when I hover the cursor on the network icon in Windows, I am connected to the Yun but it says "Internet access". It doesn't.

Windows says that when it has a valid network configuration, whether that network can actually access the Internet or not. It makes the silly assumption that all networks can get to the Internet, and assumes that people are too stupid to realize the difference if it gave a more meaningful name.

Should I connect a LAN port from the router to the Yun?

When the Yun is acting as an access point, and you are connecting your computer to it, that ability is there primarily to make it easy to set up. Normally, during that initial setup, you configure the Yun to connect to your main network WiFi access point so that it is accessible from your network, and it can get to the Internet. WiFi is the most common way, but if you can hook up an Ethernet wire between your router and Yun, that will be more reliable.

I use a wired connection whenever possible. People think I'm nuts when I tell them I spent the first week in my new house pulling thousands of feet of Ethernet wire through the walls to every room. They wonder why I don't just set up a wireless router? Well, my network does have a wireless access point for the portable devices that require it, but whenever possible I still use a hard wired connection. It's faster, and just plain more reliable. A little bit of work up front to make the connection potentially saves a lot of headaches down the road.

So for the python installation to work, I should connect the LAN to the web and after that, through wi-fi, I will be able to update it?

cipri92:
I should connect the LAN to the web and after that, through wi-fi

I can't quite follow that.

The assumption is that you have some sort of connection to the Internet. Your computer is connected to a local network, using WiFi or Ethernet, and that local network is somehow connected to the Internet.

If you now connect your Yun to the same local network, by Ethernet and/or WiFi, then you can access your Yun from your computer, and your Yun can get to the Internet, and everything should work.

The Yun is connected (by WLAN) to the same network I am (WLAN as well). As you can guess the network has web access but when commanding "opkg update" it fails. Says it's unavailabe.

Just to verify internet connectivity, from the Yun command line, try these commands. Do they both show successful pings?

ping -c5 8.8.8.8
ping -c5 downloads.arduino.cc

Problem solved. I connected the board to a USB charger and succeeded in installing python via PuTTY.

Plotly interfacing is a success. I don't know if unplugging the board from the power source and after a while plugging it back will continue the stream.

How do I cross the monitoring program with the streaming one?