Jump to content
electrotwelve

Using RESTful API to work with AWS IoT

Recommended Posts

I've been tinkering with AWS IoT in conjunction with CC3200 + Energia for a while now with varying degrees of success. The purpose of this post is using the RESTful API to update a "thing" status in the cloud. The code is listed below and I'm seeing some authentication errors. I was hoping someone can correct me if there are any errors in the way I'm using "client.ssConnect". I used a slightly modified WiFiClient.cpp and WiFiClient.h from here. I know its not a library issue since I'm able to connect using MQTT. 

char aws_endpoint[] = "xxxxxxxxxxxxxx.iot.us-east-1.amazonaws.com";
 
if (client.sslConnect(aws_endpoint, 443))
  {
    Serial.println("Connected to server");
 
    String PostData = "{\"value1\" : \"testValue\", \"value2\" : \"Hello\", \"value3\" : \"World!\" }";
 
    request = "POST /things/";
    request += thingname;
    request += "/shadow";
    request += " HTTP/1.1";
    Serial.print("Request:\t"); Serial.println(request);
    Serial.print("Post data:\t"); Serial.println(PostData);
 
    client.println(request);
    client.println("Host: ");
    client.println(aws_endpoint);
    //client.println(":443");
    client.println("User-Agent: Energia/1.1");
    client.println("Connection: close");
    client.println("Content-Type: application/json");
    client.print("Content-Length: "); client.println(PostData.length());
    client.println();
    client.println(PostData);
    client.println();
  }
  else
  {
    Serial.println("Connection failed");
 
  }
 
  Serial.println(); 
 
  // Capture response from the server. (10 second timeout)
  long timeOut = 5000;
  long lastTime = millis();
  
  while((millis()-lastTime) < timeOut)
  { // Wait for incoming response from server
    while (client.available()) 
    { // Characters incoming from the server
      char c = client.read();            // Read characters
      Serial.write(c);
    }
  }

Here is the output that I see:

RootCA found!
Client certificates found!

Device ID is:	3250763216

Attempting to connect to WiFi network .
Connected to WiFi network: ABCDEFGH
Waiting for IP 
IP is: 192.168.1.107
Connected to server
Request:	POST /things/MyCC3200/shadow HTTP/1.1
Post data:	{\"value1\" : \"testValue\", \"value2\" : \"Hello\", \"value3\" : \"World!\" }

HTTP/1.1 403 Forbidden
content-type: application/json
content-length: 91
date: Tue, 26 Jul 2016 11:46:59 GMT
x-amzn-RequestId: 4d5388a9-e3c4-460a-b674-c3f971f3330d
connection: Keep-Alive
x-amzn-ErrorType: ForbiddenException:

{"message":"Missing Authentication Token","traceId":"4d5388a9-e3c4-460a-b674-c3f971f3330d"}

Share this post


Link to post
Share on other sites

Hello electrotwelve,

I am recently started working with AWS IoT. I have the same requirement. I just want to know how I can know the url like as you told "

char aws_endpoint[] = "xxxxxxxxxxxxxx.iot.us-east-1.amazonaws.com";". What are those "xxxxxxxxxxxxxxxx" meaning.

 

Thanks,

Mrinal

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...