Connecting Arduino to Plotly via Ethernet Shield

Hi All,

I have spent countless hours on many forums looking for the answer online, tried 'possible solutions' that way I don't waste anyones time. :slight_smile:

Thank you in advance for your time, help and expertise.

Aim:I want to plot data from my Arduino to Plotly.

I found and example which I feel is nearly there but just dies at the end.

For the purposes of prototyping I am just trying to plot two floats (as can be seen in the code) not live sensor data

#include <SPI.h>
#include <Ethernet.h>
#include "plotly_streaming_ethernet.h"
#define nTraces 2
char *tokens[nTraces] = {"zta46zircl", "e8oarnxk5e"};
// arguments: username, api key, streaming token, filename
plotly graph("xxxxxxx", "xxxxxxx", tokens, "Arduino_Test", nTraces);

float h, t;

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
byte my_ip[] = { 122, 193, 156, 77 }; // google will tell you: "public ip address"

void startEthernet(){
    Serial.println("... Initializing ethernet");
    if(Ethernet.begin(mac) == 0){
        Serial.println("... Failed to configure Ethernet using DHCP");
        // no point in carrying on, so do nothing forevermore:
        // try to congifure using IP address instead of DHCP:
        Ethernet.begin(mac, my_ip);
    }
    Serial.println("... Done initializing ethernet");
    delay(1000);
}


void setup() {
  graph.maxpoints = 30;
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  startEthernet();

  bool success;
  success = graph.init();
  if(!success){while(true){}}
  graph.openStream();
  
}

void loop() {
      h = 22.456;
      t = 55.16;
      graph.plot(millis(), t, tokens[0]);
      graph.plot(millis(), h, tokens[1]);
      
}

But I keep getting the following error:

... Initializing ethernet
... Done initializing ethernet
... Attempting to connect to plotly's REST servers
... Connected to plotly's REST servers
... Sending HTTP Post to plotly
POST /clientresp HTTP/1.1
Host: plot.ly:80
User-Agent: Arduino/0.6.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 344

version=2.3&origin=plot&platform=arduino&un=xxxxxx&key=xxxxxxxxx&args=[{"y": [], "x": [], "type": "scatter", "stream": {"token": "zta46zircl", "maxpoints": 30}}, {"y": [], "x": [], "type": "scatter", "stream": {"token": "e8oarnxk5e", "maxpoints": 30}}]&kwargs={"fileopt": "overwrite", "filename": "Arduino_Test", "world_readable": true}
... Sent message, waiting for plotly's response...
HTTP/1.1 200 OK
Cache-control: no-cache="set-cookie"
Content-Language: en
Content-Type: application/json
Date: Wed, 15 Feb 2017 11:59:45 GMT
Server: nginx
Set-Cookie: anoncsrf=uPgkrej4R9LUnQhJ73MFYXTws3LKn3Iz; expires=Thu, 16-Feb-2017 11:59:45 GMT; httponly; Max-Age=86400; Path=/
Set-Cookie: plotly_sess_pr=rpsw4zzbyxa3sbv78do1cdmagdlitmak; Domain=.plot.ly; expires=Wed, 01-Mar-2017 11:59:45 GMT; httponly; Max-Age=1209600; Path=/; secure
Set-Cookie: plotly_csrf_pr=sVqyFWbIHv7rXJ0KuXpyVPEi2RHryl02; Domain=.plot.ly; expires=Fri, 16-Feb-2018 11:59:45 GMT; Max-Age=31622400; Path=/; secure
Set-Cookie: AWSELB=296F2D2B16D851992A5FF5CDA5674849B81CD605B185E50F8D748F683EE2EB8178D7E2167181627C6CFA019B72D8B78DD8005E864F8FBB7CD57BC683345C082DE71B16C4DD;PATH=/
Vary: Accept-Encoding
Vary: Cookie, Accept-Language
x-content-type-options: nosniff
X-Frame-Options: SAMEORIGIN
x-xss-protection: 1; mode=block
Content-Length: 371
Connection: keep-alive

{"url": "", "message": "", "warning": "", "filename": "", "error": "Hm... Plotly had some trouble decoding your 'kwargs'. Are you sure your data or styling object is in the right format? Check out the examples at plot.ly/api for guidance.\n\nNeed help? Please try searching Plotly's <a href='http://stackoverflow.com/questions/tagged/plotly'>Stack Overflow channel</a>."}

I did notice the "Content-Length" didnt match but wasnt sure if that caused the issue.

Any suggestions would be much appreciated, I have attached the plotly_streaming_ethernet.cpp I am using in case it helps.

Also If there something free that I can use to plot temperature data from the Arduino via the Ethernet shield which someone has got working, that is not Plotly please feel free to suggest.

Thanks!

plotly_streaming_ethernet.cpp (10.4 KB)

Hi shankman,

look at line 53:

int contentLength = 126 + len_(username_) + len_(fileopt) + nTraces_*(87+len_(maxpoints)) + (nTraces_-1)*2 + len_(filename_);

and line 64:

// + 10  // api_key length

Set 126 to 136, since the API keys plotly generates for you have a length of 20 nowadays.

Greetings
KHS