AWS IoT

This sample shows two different scenarios with AWS IoT. A GET request on an IoT Shadow and a POST request on the AWS IoT Core message broker are shown.

The GET request is similar to the “OpenWeatherMap” sample, only the Uri has been changed to the Uri of Shadow of the IoT Thing, regarding to the AWS REST API.

The user is required to have an AWS account in order to have an IoT Core endpoint and the possibility to create certificates for the communication with TwinCAT.

PROGRAM MAIN
VAR
    // trigger command execution for AWS IoT Core samples
    bGetAwsIotShadow, bPostAwsIot  : BOOL;

    fbHttpClientAwsIot             : FB_IotHttpClient :=(sHostName:='youradress.amazonaws.com',
                                     bKeepAlive:=FALSE, tConnectionTimeout:=T#10S);

    fbHttpGetAwsIotShadow          : FB_TestHTTP_Get_awsIotShadow;
    fbHttpPostAwsIot               : FB_TestHTTP_Post_awsIot;
END_VAR
//init client parameters at startup
IF NOT fbHttpClientAwsIot.bConfigured THEN
    fbHttpClientAwsIot.stTLS.sCA:= 'C:\TwinCAT\3.1\Config\Certificates\AWS\AmazonRootCA1.pem';
    fbHttpClientAwsIot.stTLS.sCert:= 'C:\TwinCAT\3.1\Config\Certificates\AWS\certificate.pem.crt';
    fbHttpClientAwsIot.stTLS.sKeyFile:= 'C:\TwinCAT\3.1\Config\Certificates\AWS\private.pem.key';
    fbHttpClientAwsIot.nHostPort:= 8443;
END_IF

IF fbHttpClientAwsIot.bConfigured THEN
    fbHttpGetAwsIotShadow(bSend:=bGetAwsIotShadow, fbClient:=fbHttpClientAwsIot);
    fbHttpPostAwsIot(bSend:=bPostAwsIot, fbClient:=fbHttpClientAwsIot);
END_IF

fbHttpClientAwsIot.Execute();