Properties not refreshing from service
I have a ESP8266 NodeMCU module making POST request to a Service connected to a Thing but the properties aren't getting refreshed. The properties are updated only when the module is first plugged in.
Here is the code to send trigger the service from the NodeMCU.
#include <DHT.h>
#define DHTTYPE DHT11
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#define dht_dpin 0
DHT dht(dht_dpin, DHTTYPE);
const char* ssid = "Cl";
const char* password = "xxx";
const char* host = "PP-1804050928FD.devportal.ptc.io";
const int httpsPort = 8080;
WiFiClient client;
void setup() {
dht.begin();
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());;
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}else{
Serial.println("Connected to ThingWorx.");
}
Serial.println("Humidity and temperature\n\n");
delay(700);
}
void loop() {
// put your main code here, to run repeatedly:
//Getting Temp and Humidity
int h = dht.readHumidity();
int t = dht.readTemperature();
String tem = String(t);
String hum = String(h);
Serial.print("Current humidity = ");
Serial.print(h);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(t);
Serial.println("C ");
// Setting service
String thvals = "{\"Temp\":\"" + tem + "\", \"Humid\":\"" + hum + "\"}";
String tourl = "http://PP-1804050928FD.devportal.ptc.io:8080/Thingworx/Things/DHT11Thing/Services/setTempAndHumid";
Serial.print("Setting Service url: ");
Serial.println(tourl);
client.print(String("POST ") + tourl + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"appKey: xxxx" + "\r\n" +
"x-thingworx-session: false" + "\r\n" +
"Accept: application/json" + "\r\n" +
"Connection: close" + "\r\n" +
"Content-Type: application/json" + "\r\n" +
"Content-Length: " + String(thvals.length()) + "\r\n\r\n" +
thvals + "\r\n\r\n");
while (client.connected()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
delay(1000);
}
I have a service that updates the properties but does not get refreshed periodically. Any help would be appreciated. Thanks.

