title: Proper POST request to stream data to plotly from Arduino
body: <p>I'm using an ESP8266 module in order push sensory data online. I set it up for thingspeak and used a simple GET request to send the values. </p>
  
  <p>Now I was trying to replicate the process with plotly data streaming service but I can't figure out what is wrong with my request. </p>
  
  <p>The traditionnal libraries (Wifi, Ethernet etc.) have a println() method which prints to the socket. I had to implement my own library for the ESP since I could not find anything reliable, and noticed that very often the device would put itself in a 'busy' state after sending something to the socket, which prevented me from sending the request chunk by chunk like such : </p>
  
  <pre class="lang-cc prettyprint-override"><code>client.println("POST / HTTP/1.1")
  client.println("Host: arduino.plot.ly")
  client.println("{\"x\":15, \"y\": 3, \"streamtoken\": \"urqcbfmjot\"\"}")
  </code></pre>
  
  <p>So I tried to write the request all at once. I found the parameters for the request by diving into plotly's arduino librarie which relies on Wifi to work (which is why I can't use it with the ESP). I have failed to push any data until now. Here is the chunk of code reponsible for sending the request : </p>
  
  <pre class="lang-cc prettyprint-override"><code>void pushData(String temp, String humid, String pres, String lum)
  {
      bool status = esp8266.openTCPConnection(IP, PORT);
  
      char call[] = "POST / HTTP/1.1\r\n";
      strcat(call, "Host: arduino.plot.ly\r\n");
      strcat(call, "User-Agent: Arduino\r\n");
      strcat(call, "Transfer-Encoding: chunked\r\n");
      strcat(call, "Connection: close\r\n");
      strcat(call, "\r\n");
      strcat(call, "\r\n{\"x\":15, \"y\": 3, \"streamtoken\": \"urqcbfmjot\"\"}\n\r\n");
  
      if (!status) return;
  
      esp8266.send(call);
  }
  
  void Esp8266::send(String content)
  {
      String cmd;
      String msg = "Sent : ";
      bool status;
  
      printDebug("Writing to TCP connection");
      printDebug("Content to write :");
      printDebug(content);
      cmd = "AT+CIPSEND=" + String(content.length());
      espSerial.println(cmd);
      printDebug("Sent : " + cmd);
  
      status = checkResponse("&gt;", 10);
      if (status)
      {
          espSerial.print(content);
          printDebug("Content sent");
  
          } else {
          printDebug("Cursor error");
          closeTCPConnection();
      }
  
  }
  </code></pre>
  
  <p>I might add that I've succesfully tested the request provided in their <a href="https://plot.ly/streaming/" rel="nofollow">documentation</a> with cUrl, but it failed too in my implementation. The request is :</p>
  
  <pre class="lang-html prettyprint-override"><code>POST  HTTP/1.1
  Host: stream.plot.ly
  plotly-streamtoken: urqcbfmjot
  
  { "x": 10, "y": 2 }
  </code></pre>
  
  <p>Any help would be greatly appreciated. For references, here is the <a href="https://github.com/amatelin/Connected-barometer-tutorial/tree/plot.ly" rel="nofollow">repository</a> of my project. </p>
  
  <p>Feel free to use my graph for testing purposes. The host is either stream.plot.ly (from the doc) or arduino.plot.ly (from the library). My stream token is <strong>urqcbfmjot</strong> and here is <a href="https://plot.ly/170/~amatelin/" rel="nofollow">the link to the plot</a></p>