Created
March 5, 2021 19:02
-
-
Save Avotrix/8282972a925b76feee77fb54f0ed4574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ESP8266WiFi.h" | |
#include<ESP8266HTTPClient.h> | |
#include "DHT.h" | |
const char* ssid = "XXXXX"; | |
const char* password = "XXXXXXX"; | |
char server[] = "<<Your trial server URL>>"; | |
char appKey[] = "<<Your Application keys>>"; | |
// ThingWorx details | |
char thingName[] = "<<Your thing name>>"; | |
char serviceName[] = "setValue"; //optional | |
char property1[]="<<poperty name>>"; | |
char property2[]="<<poperty name>>"; | |
#define ACCEPT_TYPE "text/csv" | |
void setup() { | |
Serial.begin(115200); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(1000); | |
Serial.print("."); | |
} | |
} | |
void loop() { | |
if(WiFi.status() == WL_CONNECTED) | |
{ | |
HTTPClient http; | |
String t ="{\"temp\":\"40\"}"; | |
int a=t.length(); | |
Serial.println("raj"); | |
Serial.println(a); | |
String URL = String(server)+ "/Thingworx/Things/" + thingName +"/Properties/"+ property1 +"?appKey="+ String(appKey); | |
Serial.println(URL); | |
http.begin(URL); | |
http.addHeader("Accept",ACCEPT_TYPE,false,false); | |
int httpcode=http.sendRequest("PUT",t); | |
Serial.println(httpcode); | |
if(httpcode > 0) | |
{ | |
String payload = http.getString(); | |
Serial.println(payload); | |
String t1="{\"hum\":\"56\"}"; | |
int a1=t1.length(); | |
Serial.println(a1); | |
String URL = String(server) + "/Thingworx/Things/" + thingName +"/Properties/"+ property2 +"?appKey="+ String(appKey); | |
http.begin(URL); | |
http.addHeader("Accept",ACCEPT_TYPE,false,false); | |
http.addHeader("Content-Type","application/json",false,false); | |
int httpcode=http.sendRequest("PUT",t1); | |
if(httpcode > 0) | |
{ | |
String payload = http.getString(); | |
Serial.println(payload); | |
} | |
http.end(); | |
} | |
delay(30000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment