electrotwelve 3 Posted July 26, 2016 Share Posted July 26, 2016 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"} Quote Link to post Share on other sites
bluehash 1,581 Posted July 26, 2016 Share Posted July 26, 2016 Not very sure about this.. but looks like a key/token issue. Is there any api key that you can add from AWS to your code? Quote Link to post Share on other sites
spirilis 1,265 Posted July 26, 2016 Share Posted July 26, 2016 Yeah all those sort of REST APIs require an authentication token in the headers. Look more into AWS documentation for this. It might be a key you get from their dashboard GUI for your account. Quote Link to post Share on other sites
electrotwelve 3 Posted July 27, 2016 Author Share Posted July 27, 2016 Thanks folks. As it turns out I was using the wrong port. Its supposed to be 8443 instead of 443. With that in place, everything worked great! I also had to modify the PostData format to match what AWS needs it to be. adrianF 1 Quote Link to post Share on other sites
fuyichin 0 Posted May 19, 2017 Share Posted May 19, 2017 @electrotwelve May I know how you connect to AWS with RootCA and Client Certificate in Energia. Quote Link to post Share on other sites
Mrinal 0 Posted November 9, 2017 Share Posted November 9, 2017 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.