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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Arduino weather app not updating the property values

vignesh1
1-Newbie

Arduino weather app not updating the property values

Dear all,

I have this issue while implementing my first arduino IOT program. after completion of all the steps successfully i haven't get the values in my thingworx server.

connected

POST /Thingworx/Things/AWAPP/Services/setTempAndHumid?appKey=4c294d42-d7b1-40f9-99da-7ae631143fd9&method=post&x-thingworx-session=true<&Temp=48.00&Humid=178.00> HTTP/1.1

Host: http://sona.cloud.thingworx.com

Content-Type: text/html

i am using thingworx 5.2.0.437.

I don't have anything in subsystem configurations

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Gopi,

I tested your code on my thingworx hosted instance and it worked nicely. Change your server variable from http://sona.cloud.thingworx.com "; to sona.cloud.thingworx.com. Http:// is not part of the server name.

Also I noticed that the rest call for your instance is no longer working in the browser

Did you delete the setTempAndHumid service on your AWAPP Thing ?

If so, please follow the tutorial to recreate it again and run the sketch with the changed value for your server variable. Let me know if this fixes the issue.

Best regards,

Veronica

View solution in original post

6 REPLIES 6

Hi,

Your Rest call is correct. I have tested it in the browser and the properties were set correctly. You don't need any additional configuration on ThingWorx 5.2 to allow rest calls. Are you connecting your board through an Ethernet shield or a WiFi shield? What code are you using for making the rest call?

Veronica

Hi Veronica,

I am using Arduino Ethernet Shield only.

this is my code

#include <Wire.h>

#include <SPI.h>

#include <Ethernet.h>

//How many values you will be pushing to ThingWorx

#define propertyCount 2

// Enter a MAC address and IP address for your controller below.

// The IP address will be dependent on your local network:

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

char server[] = "http://sona.cloud.thingworx.com";

EthernetClient client;

//ThingWorx App key which replaces login credentials)

char appKey[] = "4c294d42-d7b1-40f9-99da-***********";

// ThingWorx Thing name for which you want to set properties values

char thingName[] = "AWAPP";

//Interval of time at which you want the properties values to be sent to TWX server

int timeBetweenRefresh = 5000;

// ThingWorx service that will set values for the properties you need

// See the documentation for this tutorial for more information

char serviceName[] = "setTempAndHumid";

//Initialize Properties Names and Values Arrays

char* propertyNames[] = {"Temp", "Humid"};

double propertyValues[propertyCount];

// last time you connected to the server, in milliseconds

unsigned long lastConnectionTime = 0;

// state of the connection last time through the main loop

boolean lastConnected = false;

//Initialize an HTU21D library object to read

// temperature and humidity data from your connected sensor

//HTU21D myHumidity;

void setup() {

  //shut down the SD Card pins

  pinMode(4, OUTPUT);

  digitalWrite(4, HIGH);

  // start serial port:

  Serial.begin(9600);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for Leonardo only

  }

  //initialize HTU21D object to read values from sensors

  //   myHumidity.begin();

  // start the Ethernet connection:

  Serial.println("Trying to get an IP address using DHCP");

  Ethernet.begin(mac);

  Serial.print("My IP address: ");

  Serial.print(Ethernet.localIP());

  Serial.println();

}

void loop() {

  // Aquire sensor values

  propertyValues[0] = analogRead(A0);

  propertyValues[1] = analogRead(A1);

  // wait the established interval of time before

  // reading values from the sensor

  // and sending them to the TWX server again

  // delay(timeBetweenRefresh);

  if (millis() - lastConnectionTime > timeBetweenRefresh) {

    updateValues(propertyValues, client, server, appKey, thingName, serviceName, propertyNames);

  }

}

void updateValues(double values[] , EthernetClient &client, char server[], char appKey[], char thingName[], char serviceName[], char* sensorNames[])

{

  //build the String with the data that you will send

  //through REST calls to your TWX server

  char data[80];

  strcpy(data, "?appKey=");

  strcat(data, appKey);

  strcat(data, "&method=post&x-thingworx-session=true");

  // if you get a connection, report back via serial:

  if (client.connect(server, 80)) {

    Serial.println("connected");

    // send the HTTP POST request:

    client.print("POST /Thingworx/Things/");

    client.print(thingName);

    client.print("/Services/");

    client.print(serviceName);

    client.print(data);

    client.print("<");

    for (int idx = 0; idx < propertyCount; idx++)

    {

      client.print("&");

      client.print(propertyNames[idx]);

      client.print("=");

      client.print(propertyValues[idx]);

    }

    client.print(">");

    client.println(" HTTP/1.1");

    client.print("Host: ");

    client.println(server);

    client.println("Content-Type: text/html");

    client.println();

    client.stop();

    lastConnectionTime = millis();

    // print the request out

    Serial.print("POST /Thingworx/Things/");

    Serial.print(thingName);

    Serial.print("/Services/");

    Serial.print(serviceName);

    Serial.print(data);

    Serial.print("<");

    for (int idx = 0; idx < propertyCount; idx++)

    {

      Serial.print("&");

      Serial.print(propertyNames[idx]);

      Serial.print("=");

      Serial.print(propertyValues[idx]);

    }

    Serial.print(">");

    Serial.println(" HTTP/1.1");

    Serial.print("Host: ");

    Serial.println(server);

    Serial.println("Content-Type: text/html");

    Serial.println();

  }

  else {

    // kf you didn't get a connection to the server:

    Serial.println("the connection could not be established");

    client.stop();

  }

}

And this is the Serial Output

screenshot.PNG

It shows that the values were constantly updating to the Server.

But I can't See any updates in property values.

Please help me.

With regards,

Gopi

Hi Gopi,

I tested your code on my thingworx hosted instance and it worked nicely. Change your server variable from http://sona.cloud.thingworx.com "; to sona.cloud.thingworx.com. Http:// is not part of the server name.

Also I noticed that the rest call for your instance is no longer working in the browser

Did you delete the setTempAndHumid service on your AWAPP Thing ?

If so, please follow the tutorial to recreate it again and run the sketch with the changed value for your server variable. Let me know if this fixes the issue.

Best regards,

Veronica

Hi Veronica,

it is working fine now. Issue is with the Host address only. Thank you for the support.

with regards,

Gopi

Now, I have another issue MailServer Template was not available for my version of thingworx.

Also i can't add parameters in Auto Refresh widget.

Please help me

You can download the Mail Server extension from marketplace . Note that you need administrator rights to import extensions or entities. You can usually ask your teacher to do this.

I have imported it now on your instance to help you follow the tutorial easier. You should find the MailServer template now when creating a thing. 

What parameters are you trying to add to the Refresh widget ?

Top Tags