Here is my code without quotes. I used quote because i didn’t want to afraid people with my code. I looked your links thank you @glv . It was interresting to see your setup.
import http.requests.*;
import processing.net.*;
import processing.serial.*;
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 = "127.0.0.1";
String appKey = "140d461e-90cf-4c7c-9258-25da3838c36a";
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 :8080/Thingworx/Things/" + thingName + "/Services/" + serviceName + " appKey:" + appKey;
String myHost = "Host: " + myServer;
String myContent = "Content-type: text/html\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);
myClient = new Client(this, myServer, 8080);
}
int idx = SENSORCOUNT + 2;
void draw() {
if (myPort.available() > 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) && (idx < 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
myClient.write(myURI);
for (int index = 0; index < SENSORCOUNT; index++)
{
myClient.write(sensorNames[index] + "=" + trim(sensorValues[index])+"");
}
myClient.write(" HTTP/1.1\n");
myClient.write(myHost + '\n');
myClient.write(myContent + '\n');
println("Sending this REST call:");
print(myURI);
for (int index = 0; index < SENSORCOUNT; index++)
{
print(" " + sensorNames[index] + "=" + trim(sensorValues[index] + " "));
}
print(" HTTP/1.1\n");
print(myHost + '\n');
print(myContent + '\n');
print('\n');
idx = SENSORCOUNT + 2;
}
}
}