cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

ESP8266 Communicate with Thingworx

Telles
11-Garnet

ESP8266 Communicate with Thingworx

Hi, Team!

  I work with these sketch but the TW don´t receive any data.
  Follow two printscreens.

#include "ESP8266WiFi.h"
#include<ESP8266HTTPClient.h>

const char* ssid = "InfoAxis_NET1";
const char* password = "InfoNet1";

char server[] = "xxxx";
char appKey[] = "xxxx";


// ThingWorx details
char thingName[] = "Box";
char serviceName[] = "setValue"; //optional
char property1[]="pressao";
char property2[]="temperatura";

#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 ="{\"pressao\":\"40\"}";
int a=t.length();
Serial.println("TELLES");
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="{\"temperatura\":\"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(1000);
}
}

Perhaps I´m skipping some steps.

RT_10003402_0-1631645496209.pngRT_10003402_1-1631645508293.png

Regards.
Telles.

 

4 REPLIES 4

I see a couple issues:

1. You are not using the HTTPS library. This library is required for making https connections to the free trial servers

2. You are sending a string value in  your JSON to a Number type property

 

 

Hi, Rick.
Now I´m using these libs:
 
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoHttpClient.h>
#include <WiFiClientSecureBearSSL.h>
 
Follow printscreen, and changed the Properties to String.

RT_10003402_2-1631716590363.pngRT_10003402_3-1631716610353.png

But the TW still off.

Maybe I need a specicly library. Do you any URL for it?

Regards.
Telles.

 

Did you ever get the code here to work:

https://developer.thingworx.com/en/resources/guides/connect-adafruit-feather/set-arduino-ide-and-boa...

 

If that code does not work, you will not be able to get your code to work.

 

It looks like you are missing these lines:

std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
https.begin(*client,URL);

These code of link works as very well!
But it created a Thing em GET the informations.
I try to PUT too.

When I creating a Thing by MCU I acepte the risk to all my Thing depends of power supply and not of TW. My Mashups has to online! Just the informations can be off.

Announcements