Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C by kemo ( 6 years ago )
/*******************   Libraries *************************/
#include <ESP8266WiFi>


/******************   WiFi Setup   *********************************/
const char* ssid = "AHMED";
const char* password = "hamada1234";

const char* host = "https://academic.cloud.thingworx.com/Thingworx/Composer/"; // ThingWorx Server IP Address
const int httpsPort = 8443;


WiFiClient client;
String rfid_read = "4276Ee667";

void setup() {
  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());;


}

void loop() {  
  internet();
  delay(1000);
}



void internet(void)
{
// Use WiFiClientSecure class to create TLS connection
  Serial.println(host);
  if (!client.connect(host, httpsPort)) {
    Serial.println("connection failed");
    return;
  }else{
    Serial.println("Connected to ThingWorx.");
  }

  String url = "/Thingworx/Things/AssemblyLine_Graduation/Properties/ali";
  Serial.print("requesting URL: ");
  Serial.println(url);

  String strPUTReqVal = "{\"rfid_read\":\"" + rfid_read + "\"}";
  Serial.print("PUT Value: ");
  Serial.println(strPUTReqVal);

  client.print(String("PUT ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "appKey:<my>" + "\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(strPUTReqVal.length()) + "\r\n\r\n" +
               strPUTReqVal+ "\r\n\r\n");
    
  while (client.connected()) {
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  client.stop();

  // Run this every 5 seconds
  delay(5000);

}

 

Revise this Paste

Your Name: Code Language: