Solved! Some sample code for future researchers, you want to change wifi parameters and your Thingworx platform parameters. Here you just sending ++number to the first property (one )and getting another from the second (otvet1) they both have type number. Contents of service u can find in the screenshot below.
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <SimpleTimer.h>
// Wi-Fi parameters
char ssid[] = "MTSRouter-302000";
char pass[] = "zxcqwe123";
#define IOT_UPDATE_TIME 2000
SimpleTimer timer_iot;
// Thingworx parameters
char iot_server[] = "academic.cloud.thingworx.com";
IPAddress iot_address(52, 71, 6, 169);
char thingName[] = "thing123";
char serviceName[] = "service1";
char appKey[] = "xxxxxxxx";
// Sensors
char sensorNames[] = "one";
float sensorValues = 0;
// Max timeout
#define IOT_TIMEOUT1 1000
#define IOT_TIMEOUT2 100
long timer_iot_timeout = 0;
#define BUFF_LENGTH 256
int led_control = 0;
// buffer
char buff[BUFF_LENGTH] = "";
void setup()
{
Serial.begin(115200);
delay(512);
// Init .Wi-Fi
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
timer_iot.setInterval(IOT_UPDATE_TIME, sendDataIot);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
timer_iot.run();
}
void sendDataIot()
{
// Server connect
WiFiClientSecure client;
Serial.println("Connecting to IoT server...");
if (client.connect(iot_address, 443))
{
// Checking connection
if (client.connected())
{
// POST request
Serial.println("Sending data to IoT server...\n");
Serial.print("POST /Thingworx/Things/");
client.print("POST /Thingworx/Things/");
Serial.print(thingName);
client.print(thingName);
Serial.print("/Services/");
client.print("/Services/");
Serial.print(serviceName);
client.print(serviceName);
Serial.print("?appKey=");
client.print("?appKey=");
Serial.print(appKey);
client.print(appKey);
Serial.print("&method=post&x-thingworx-session=true");
client.print("&method=post&x-thingworx-session=true");
// Data from sensors
Serial.print("&");
client.print("&");
Serial.print(sensorNames);
client.print(sensorNames);
Serial.print("=");
client.print("=");
Serial.print(sensorValues++);
client.print(sensorValues++);
// Close packet
Serial.println(" HTTP/1.1");
client.println(" HTTP/1.1");
Serial.println("Accept: application/json");
client.println("Accept: application/json");
Serial.print("Host: ");
client.print("Host: ");
Serial.println(iot_server);
client.println(iot_server);
Serial.println("Content-Type: application/json");
client.println("Content-Type: application/json");
Serial.println();
client.println();
// Waiting response
timer_iot_timeout = millis();
while ((client.available() == 0) && (millis() < timer_iot_timeout + IOT_TIMEOUT1));
// Show response or dc if connection lost
int iii = 0;
bool currentLineIsBlank = true;
bool flagJSON = false;
timer_iot_timeout = millis();
while ((millis() < timer_iot_timeout + IOT_TIMEOUT2) && (client.connected()))
{
while (client.available() > 0)
{
char symb = client.read();
Serial.print(symb);
if (symb == '{')
{
flagJSON = true;
}
else if (symb == '}')
{
flagJSON = false;
}
if (flagJSON == true)
{
buff[iii] = symb;
iii ++;
}
timer_iot_timeout = millis();
}
}
buff[iii] = '}';
buff[iii + 1] = '\0';
Serial.println(buff);
// Close connection
client.stop();
// Parsing response
StaticJsonBuffer<BUFF_LENGTH> jsonBuffer;
JsonObject& json_array = jsonBuffer.parseObject(buff);
if (json_array.success())
{
led_control = json_array["otvet1"];
Serial.println("OTVET1: " + String(led_control));
Serial.println();
}
else
{
Serial.println("Fail to parse packet from Thingworx!");
Serial.println();
}
led();
Serial.println("Packet successfully sent!");
Serial.println();
}
}
}
void led()
{
if (led_control == 0){
digitalWrite(LED_BUILTIN, HIGH);
}
else{
digitalWrite(LED_BUILTIN, LOW);
}
}