Part Number: CC3200
Other Parts Discussed in Thread: UNIFLASH
Hello,
Over a week, I am working on making a connection to Amazon AWS IoT Core Thing. Probably, I read all the threads about "CC3200 and TLS" in this forum, so I created this new thread.
Step by step, I will explain what I did to make a connection to AWS (Directly importing a project to CCS and building, flashing it didnt work).
1) Creating Thing on AWS
- I created a thing on AWS.
- Downloaded the certificate, private key and root CA files.
- Created a certificate for the thing.
- Created a policy for the thing. Edited policy rights:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "*"
}
]
}
So, any software or device can connect and publish/subscribe to any message using this policy.
2) Connection Tests:
- Amazon AWS' "ready to go" downloaded script worked well when I run it from the powershell.
- I wrote a paho mqtt python program to connect with TLS certificate files and it can publish and subscribe to a topic. So, now, I can see on my program url, socket, tls_version and chipher variables.
- I tried CC3200 mqtt examples but they all failed. After that, I programmed my CC3200 launchpad using paho embedded c to communicate my custom mqtt broker without TLS. This link was very helpful:blog.benjamin-cabe.com/.../mqtt-on-the-ti-cc3200-launchpad-thanks-to-paho-embedded-client
- To make a secure connection, I worked on CC3200 ssl example and I succeeded to make a connection to google.com with my CC3200 launchpad.
- I improved the ssl example to connect Amazon AWS and partly I succeded.
Now, I am stuck at the point where "Ganesh Gurung58" wrote on this page: e2e.ti.com/.../769842
xxxxx-ats.iot.xxxxx.amazonaws.com (iot:Data-ATS) isnt working and returning -155 connection error, but xxxxx.iot.xxxxx.amazonaws.com (iot:Data) makes a connection. I can see the connection activity on AWS Iot Core Monitor page. But the problem is sl_Send cannot send any data. When I make a subcription to the topic that CC3200 sends, it shows nothing on AWS IoT Core MQTT test page.
Here is the code comparison. Below code works without TLS to make a connection and sending MQTT package to my custom broker:
UART_PRINT("\n\rInternet Access.");
while(1)
{
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
int rc = 0;
char buf[200];
MQTTString topicString = MQTTString_initializer;
UART_PRINT("\n\rMQTT definitions.");
char* payload = "mypayload";
int payloadlen = strlen(payload);
int buflen = sizeof(buf);
UART_PRINT("\n\rpayload definitions.");
//data.clientID.cstring = "thisismeee";
data.keepAliveInterval = 20;
data.cleansession = 1;
data.clientID.cstring = "asdfjlsdl";
data.username.cstring = "usrnew";
data.password.cstring = "gabcd";
int len = MQTTSerialize_connect(buf, buflen, &data);
UART_PRINT("\n\rMQTTSerialize_connect");
topicString.cstring = "cc3200-ben-xxxx";
len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen);
UART_PRINT("\n\rMQTTSerialize_publish");
len += MQTTSerialize_disconnect(buf + len, buf - len);
UART_PRINT("\n\rMQTTSerialize_disconnect");
int mysock = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
UART_PRINT("\n\rsl_Socket");
SlSockAddrIn_t addr;
addr.sin_family = SL_AF_INET;
addr.sin_port = sl_Htons(8883);
addr.sin_addr.s_addr = sl_Htonl(0xA1B2C3D4FF);//my custom broker's ip address in hex
UART_PRINT("\n\rsl_Htonl");
sl_Connect(mysock, ( SlSockAddr_t *)&addr, sizeof(addr));
UART_PRINT("\n\rsl_Connect");
sl_Send(mysock, buf, len, NULL);
UART_PRINT("\n\rsl_Send");
sl_Close(mysock);
UART_PRINT("\n\rsl_Close");
UART_PRINT("\n\rMQTT message sent!");
osi_Sleep(1000);
}
The code below makes a connection to AWS, no error executing MQTT messages but nothing happening on the AWS MQTT test page.
// BEGIN AWS TLS CONNECTION. BECAUSE OF TI CC3200 TLS EXAMPLES DID NOT WORK, PAHO EMBEDDED C USED.
Network n;
Client hMQTTClient;
SlSockSecureFiles_t sockSecureFiles;
sockSecureFiles.secureFiles[0] = 127;
sockSecureFiles.secureFiles[1] = 128;
sockSecureFiles.secureFiles[2] = 129;//129;
sockSecureFiles.secureFiles[3] = 0;
lRetVal = TLSConnectNetwork(&n, "XXXXXXXXXXX.iot.XXXXX.amazonaws.com", 8883,
&sockSecureFiles,
SL_SO_SEC_METHOD_TLSV1_2, //SL_SO_SEC_METHOD_SSLv3_TLSV1_2
SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, 0); //SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
if( lRetVal < 0 )
{
UART_PRINT("TLSConnectNetwork function error \n\r");
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
return lRetVal;
}
// END AWS TLS CONNECTION. PAHO EMBEDDED C USED.
UART_PRINT("Opened TCP Port with return code:%d", lRetVal);
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
int rc = 0;
char buf[200];
MQTTString topicString = MQTTString_initializer;
UART_PRINT("\n\rMQTT definitions.");
char* payload = "mypayload";
int payloadlen = strlen(payload);
int buflen = sizeof(buf);
UART_PRINT("\n\rpayload definitions.");
//data.clientID.cstring = "thisismeee";
data.keepAliveInterval = 20;
data.cleansession = 1;
data.clientID.cstring = "testThing1";
int len = MQTTSerialize_connect(buf, buflen, &data);
UART_PRINT("\n\rMQTTSerialize_connect");
topicString.cstring = "denemetopic";
len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen);
UART_PRINT("\n\rMQTTSerialize_publish");
len += MQTTSerialize_disconnect(buf + len, buf - len);
UART_PRINT("\n\rMQTTSerialize_disconnect");
//UART_PRINT("\n\rsl_Connect");
sl_Send(n.my_socket, buf, len, NULL);
UART_PRINT("\n\rsl_Send");
sl_Close(n.my_socket);
UART_PRINT("\n\rsl_Close");
UART_PRINT("\n\rMQTT message sent!");
Could you please help on making a connection to Amazon AWS?
Best regards,
Onur.