<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [POST request] Client got end of stream in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618242#M37530</link>
    <description>&lt;P&gt;Have you tried looking at the application log and adding some logger statements to the services you are calling to help with the troubleshooting?&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2019 17:25:15 GMT</pubDate>
    <dc:creator>PaiChung</dc:creator>
    <dc:date>2019-07-16T17:25:15Z</dc:date>
    <item>
      <title>[POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618181#M37521</link>
      <description>&lt;P&gt;I want to send sensor value from a arduino mega to Thingworx.&lt;BR /&gt;I have a thing and a service created however I got an Client got end of stream when I execute my processing program.When I am using HTTPIE (&lt;EM&gt;that I have found on REST API tutorial&lt;/EM&gt;) to make a single post request it is working however when i use my processing program. I am not able to make it work.&lt;BR /&gt;Is there conditions to make multiple post request each time I get my data ?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Is there a way to see what happen on thingworx when I make a POST request ? Thanks in advance&lt;/P&gt;
&lt;P&gt;I have follow this tutorial.&lt;BR /&gt;&lt;A href="https://eacpds.com/thingworx-using-an-arduino-uno-and-serial-connection/" target="_blank" rel="noopener"&gt;https://eacpds.com/thingworx-using-an-arduino-uno-and-serial-connection/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;My code :&lt;/P&gt;
&lt;PRE&gt;import http.requests.*;
import processing.net.*; //librarie for post request to the server
import processing.serial.*; //serial connexion to arduino
//import java.net.SocketException; //add for client end of stream (socket)

Client myClient;                     // Client object

Serial myPort;                       // The serial port

final int SENSORCOUNT = 12;           // This value must match SENSORCOUNT in your Arduino Code

String sensorValues[] = new String[SENSORCOUNT];
String junk;
String beginString = "begin";
//String myServer = "localhost";
String myServer = "127.0.0.1";//server IP, warning don't put port number here
String appKey = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // xxxx are remplace in my code by my application key for admin that you have created on thingworx
String thingName = "myArduinoThing";
String serviceName = "myArduinoService";
String myURI = "http -v -j POST :8080/Thingworx/Things/" + thingName + "/Services/" + serviceName + " appKey:" + appKey;
//meme erreur 
//String myURI = "POST/Thingworx/Things/" + thingName + "/Services/" + serviceName + " appKey:" + appKey;
String myHost = "Host: " + myServer;
//String myContent = "Content-type: text/html\n"; we need to send json type
String myContent = "Content-type: application/json\n";
String sensorNames[] = {
  "value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9", "value10", "value11", "value12"
};  //Enter your variable names (these must match the inputs in your Service)

void setup() {

  // Print a list of the serial ports, for debugging purposes:
  println(Serial.list());

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
  //myPort = new Serial(this, "COM14", 9600); //Port number for serial to arduino

  myClient = new Client(this, myServer, 8080);
  print("my client: ",myClient);
}

int idx = SENSORCOUNT + 2;

void draw() {

  if (myPort.available() &amp;gt; 0)
  {
    junk = null;
    junk = myPort.readStringUntil('\n');

    // look for the initial “begin” string that Arduino sends
    if (junk != null)
    { 
      if (beginString.equals(trim(junk)))
      {
        junk = null;
        idx=0;
      }
    }
    
    //Read each sensor value
    if ((junk != null) &amp;amp;&amp;amp; (idx &amp;lt; SENSORCOUNT))
    {
      sensorValues[idx] = junk;
      junk = null;
      idx++;
    }

    //When all sensor values have been read, send the info to ThingWorx
    if (idx == SENSORCOUNT)
    {
      // myURI=trim(myURI);// ajout
      print("my URI : ",myURI);
      myClient.write(myURI);

      for (int index = 0; index &amp;lt; SENSORCOUNT; index++)
      {
        //myClient.write("" + sensorNames[index] + "=" + trim(sensorValues[index] + " "));
        myClient.write(sensorNames[index] + "=" + trim(sensorValues[index])+"");
      }
     
      //myClient.write(" HTTP/1.1\r\n");
      print("send http");
      myClient.write(myHost + "\r\n");
      myClient.write(myContent + "\r\n");

      println("Sending this REST call:");
      print(myURI);
      for (int index = 0; index &amp;lt; SENSORCOUNT; index++)
      {
        print(" " + sensorNames[index] + "=" + trim(sensorValues[index] + " "));
      }
      print(" HTTP/1.1\n");
      print(myHost + '\n');
      print(myContent + '\n');
      print('\n');

      idx = SENSORCOUNT + 2;
    }
  }
}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 14:04:39 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618181#M37521</guid>
      <dc:creator>Clement_D</dc:creator>
      <dc:date>2019-07-16T14:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: [POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618242#M37530</link>
      <description>&lt;P&gt;Have you tried looking at the application log and adding some logger statements to the services you are calling to help with the troubleshooting?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2019 17:25:15 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618242#M37530</guid>
      <dc:creator>PaiChung</dc:creator>
      <dc:date>2019-07-16T17:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: [POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618317#M37538</link>
      <description>&lt;P&gt;Yes, I am looking for some help to troubleshoot my POST request.&lt;/P&gt;
&lt;P&gt;I am new to API and post request.&lt;BR /&gt;When I check my application log I have only log about my thingworx metrics that i have used for some test but I no longer need it.&lt;BR /&gt;Is there a way to see all the request POST that happen on my server ? I didn't find how I sould use logger. Is this something I had to put on my service in the javascript code ?&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="log_application.JPG" style="width: 918px;"&gt;&lt;img src="https://www.ptcusercommunity.com/t5/image/serverpage/image-id/17863i88AF8A31BF94CFC0/image-size/large?v=v2&amp;amp;px=999" role="button" title="log_application.JPG" alt="log_application.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 07:57:30 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618317#M37538</guid>
      <dc:creator>Clement_D</dc:creator>
      <dc:date>2019-07-17T07:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: [POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618323#M37539</link>
      <description>&lt;P&gt;When I add logger.info(); on my code I have this error :&lt;BR /&gt;&lt;BR /&gt;Error executing service myArduinoService. Message :: La méthode 'ch.qos.logback.classic.Logger.info()' est introuvable - See Script Error Log for more details.&lt;BR /&gt;&lt;BR /&gt;Is there a way to enable the logger ? Or is there an error on my code.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 08:25:05 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618323#M37539</guid>
      <dc:creator>Clement_D</dc:creator>
      <dc:date>2019-07-17T08:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: [POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618365#M37543</link>
      <description>&lt;P&gt;Are you putting this in the Thingworx service?&lt;/P&gt;
&lt;P&gt;I'm not familiar with the edge agent code so I'm not sure how to enable that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 13:12:55 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618365#M37543</guid>
      <dc:creator>PaiChung</dc:creator>
      <dc:date>2019-07-17T13:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: [POST request] Client got end of stream</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618374#M37546</link>
      <description>&lt;P&gt;I wasn't very clear the code that I posted is for my API on processing.&lt;BR /&gt;And I try to put the logger on my service code below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;me.value1=parseFloat(value1);
me.value2=parseFloat(value2);
me.value3=parseFloat(value3);
me.value4=parseFloat(value4);
me.value5=parseFloat(value5);
me.value6=parseFloat(value6);
me.value7=parseFloat(value7);
me.value8=parseFloat(value8);
me.value9=parseFloat(value9);
me.value10=parseFloat(value10);
me.value11=parseFloat(value11);
me.value12=parseFloat(value12);&lt;BR /&gt;logger.info();

var result = me.value1+me.value2+me.value3+me.value4+me.value5+me.value6+me.value7+me.value8+me.value9+me.value10+me.value11+me.value12 ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2019 13:48:55 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/POST-request-Client-got-end-of-stream/m-p/618374#M37546</guid>
      <dc:creator>Clement_D</dc:creator>
      <dc:date>2019-07-17T13:48:55Z</dc:date>
    </item>
  </channel>
</rss>

