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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Send sensor data to ThingWorx using Arduino and SIM808 GPRS module

mkhalil1
1-Newbie

Send sensor data to ThingWorx using Arduino and SIM808 GPRS module

Dear All,

I need to send sensor data to ThingWorx through GPRS module SIM808 connected to Arduino UNO. This requires using AT Command to start REST API (HTTP).I need support on how to form the below information in one http url to send it using AT Command AT+HTTPPARA

POST /Thingworx/Things/mything/Services/AlarmService HTTP/1.1

Host: academic.cloud.thingworx.com

appKey: b73a20dd-e142-4017-8eyy-a26xx

Content-Type: application/json

Cache-Control: no-cache

Postman-Token: add4f5b4d-ferf8-8e52-31ds-10ad6571asdsd

1 ACCEPTED SOLUTION

Accepted Solutions
vr-6
4-Participant
(To:mkhalil1)

Hi,

"AT+HTTPINIT" // Initiate

"AT+HTTPPARA"="CID",1

"AT+HTTPPARA=\"URL\",\"http://www.yourdomain.com/Thingworx/Things/<ThingName>/Services/<ServiceName>?appKey=XXXXXXXXXX\"""

"AT+HTTPPARA=\"Content\",\"application/json\"" // Content type

"AT+HTTPDATA=357, 40000"; // Size of the data

Use buffer to construct your data in JSON format.

Example: {"Temp1":"23","Temp2":"24"}


AT+HTTPACTION=1 // POST Data

AT+HTTPREAD // Read Response

AT+HTTPTERM // Terminate

View solution in original post

10 REPLIES 10
vr-6
4-Participant
(To:mkhalil1)

Hi,

"AT+HTTPINIT" // Initiate

"AT+HTTPPARA"="CID",1

"AT+HTTPPARA=\"URL\",\"http://www.yourdomain.com/Thingworx/Things/<ThingName>/Services/<ServiceName>?appKey=XXXXXXXXXX\"""

"AT+HTTPPARA=\"Content\",\"application/json\"" // Content type

"AT+HTTPDATA=357, 40000"; // Size of the data

Use buffer to construct your data in JSON format.

Example: {"Temp1":"23","Temp2":"24"}


AT+HTTPACTION=1 // POST Data

AT+HTTPREAD // Read Response

AT+HTTPTERM // Terminate

mkhalil1
1-Newbie
(To:vr-6)

Thanks Velkumar R​ for your response
All is clear except attaching Thing name as mentioned in your Example: {"Temp1":"23","Temp2":"24"}


if i have two Things and need to update their values top platform, how can i attach them with your mentioned flow

vr-6
4-Participant
(To:mkhalil1)

Hi Mohamed,

{"Temp1":"23","Temp2":"24"}  ​is Tag and its Data. Tag must be identical to inputs of service.

TWXCo.png



If you need to update two things you need to change "Thing Name" in URL

www.yourdomain.com/Thingworx/Things/<ThingName>/Services/<ServiceName>?appKey=XXXXXXXXXX\


mkhalil1
1-Newbie
(To:vr-6)

Thanks Velkumar R​, could you please share PUT code as well

vr-6
4-Participant
(To:mkhalil1)

Hi Mohamed,

I think SIM 808 support only 3 HTTPACTION

AT+HTTPACTION = 0 // Read

AT+HTTPACTION = 1 //Post

AT+HTTPACTION = 2 // Head

Please check, I am not sure about that.

For REST API calls in thingworx, check below link

ThingWorx REST API Cheat Sheet

To invoke service, post is working fine, Thanks for support Velkumar R
For updating certain SENSOR DATA, I have constructed JSON and attached it as below, but still not reflecting in sensor value, still service only is invoked, but sensor data is not updated on ThingWorx

  StaticJsonBuffer<200> jsonBuffer;

  JsonObject& rootdata = jsonBuffer.createObject();

  rootdata["Name"] = "52";

mySerial.println("AT+HTTPPARA=\"USERDATA\",rootdata");

Could you please assess?

Velkumar R

Could you please check this way of attaching data to my Thing

For updating certain SENSOR DATA, I have constructed JSON and attached it as below, but still not reflecting in sensor value, still service only is invoked, but sensor data is not updated on ThingWorx

  StaticJsonBuffer<200> jsonBuffer;

  JsonObject& rootdata = jsonBuffer.createObject();

  rootdata["Name"] = "52";

mySerial.println("AT+HTTPPARA=\"USERDATA\",rootdata");

Could you please assess?

vr-6
4-Participant
(To:mkhalil1)

Hi Mohamed,

Did you find any error in applicaion log (TWX Platform) and what is the response code in SIM 808 while posting data.

mkhalil1
1-Newbie
(To:vr-6)

Velkumar R

here is the error from ThingWorxs ,

[context: com.thingworx.webservices.context.HttpExecutionContext@78cb6519][message: Entity Not Found : [ConfiguredThing]]

from Arduino, i receive DOWNLOADas response to AT+HTTPACTION=1

vr-6
4-Participant
(To:mkhalil1)

Hi Mohamed,

Create appKey with user reference as "Administrator" and try to POST data (or) give visibility permission to "ConfiguredThing" for appKey reference user.

About Response code, if data is posted successfully you will get response code as 200

Top Tags