This is a tutorial about connecting SIMCom modules to the Amazon Web Service through the MQTT protocol. This demo was made using SIM7600SA-H, but can be used with all SIM7600 models.
To start the project, you need to be with your carrier's APN and an account in the AWS created.
2. AWS IoT CoreOn the initial AWS console, select IoT Core (if you can not find it, just type IoT Core in Find Services).
In AWS IoT Core, select AWS IoT> Manage> Things and in the upper right corner click Create
In the device creation screen, select the first option: Create a single thing
Give a name to your device
In Apply a type to this thing, click Create a type
Fill it like the example below:
There is no further modification to the device creation screen. Click Next.
Certificates are the files containing the cryptographic keys for authentication of your device. After completed the device creation (step 2.1), the screen below will appear automatically.
(If any problem occurs, you can access the certificate creation menu through the left navigation in AWS IoT > Secure > Certificates and clicking the create button in the top corner right).
You must create a certificate for your device. Select the first option One-click certificate creation (recommended), click Create Certificate.
3 files will be generated:
- Device Certificate
- Public key
- Private Key
Download the 3 files and keep them in a safe place.
(These files can not be recovered later, so store them in a really safe place!)
Download Root CA, click the Activate button, and then click Done.
Policies are the permissions of actions that the device can take within the system, such as connecting, publishing or subscribing to topics.
You need to create a policy for your device by selecting AWS IoT> Secure> Policies from the left navigation menu and clicking the Create button on the upper corner right.
Create a name for your policy, fill in the parameters as below, and click Create
Action: iot:*
Resource ARN: *
Effect: Allow
Now you need to link the created policy. In the navigation bar on the right side select AWS IoT> Manage> Things and click on the previously created device.
Inside the device screen, select Security in the left sidebar and click on the existing certificate:
On the certificate screen, select Actions > Attach Policy
Select the policy that you created and click Attach
Open Teraterm with the following settings:
Port: "XX" (select the COM port for AT commands)
Speed: 9600
Data: 8 bit
Parity: none
Stop bits: 1 bit
Flow control: none
Click Setup > Terminal and under New-line select CR+LF as below. Click OK.
You must send the certificates to the module. The command for the different certificates is the same, just change the parameters name (always ending with the .pem extension) and size according to each file.
To know the size of the file, right click on the certificate and select properties.
In the example above we have 1220 bytes, so the command looks like this:
AT+CCERTDOWN="clientcert.pem", 1220
Then click on the file, drag-and-drop on the TeraTerm and click OK.
The certificate will be sent to the module and displayed on the screen
Repeat the example procedure with the commands and files below.
AT+CCERTDOWN="clientcert.pem",1220 // change size and send cetificate-pem.crt
AT+CCERTDOWN="clientkey.pem",1675 // change size and send private.pem.key
AT+CCERTDOWN="cacert.pem",1188 // change size and send AmazonRootCA1.pem
Make sure all 3 files are inside the module with the command
AT+CCERTLIST
Finally, it is necessary to configure the type of authentication that will be made on the connection. Use the commands below to configure the use of certificates.
AT+CSSLCFG="sslversion",0,4
AT+CSSLCFG="authmode",0,2
AT+CSSLCFG="cacert",0,"cacert.pem"
AT+CSSLCFG="clientcert",0,"clientcert.pem"
AT+CSSLCFG="clientkey",0,"clientkey.pem"
Send commands using TeraTerm:
AT+CMQTTSTART
AT+CMQTTACCQ=0,"SIMCom_client01",1
AT+CMQTTSSLCFG=0,0
AT+CMQTTWILLTOPIC=0,31
aws/things/simcom7600_device01/
AT+CMQTTWILLMSG=0,17,1
SIMCom Connected!
Open your device's screen in AWS IoT, click Interact, and then copy the Rest API Endpoint.
Send the command below by the terminal replacing your Endpoint between tcp:// and :8883
AT+CMQTTCONNECT=0,"tcp://your-endpoint:8883"
In this demonstration we will publish all messages within the topic
aws/things/simcom7600_device01/
Open your device's screen in AWS IoT, click Activity, and select MQTT Client in the upper right corner
Insert topic aws/things/simcom7600_device01/ and Subscribe to topic
Open the terminal and subscribe for the same topic using the commands below
AT+CMQTTSUBTOPIC=0,31,1
aws/things/simcom7600_device01/
AT+CMQTTSUB=0
Enter the commands below into the terminal to publish a message
AT+CMQTTTOPIC=0,31
aws/things/simcom7600_device01/
AT+CMQTTPAYLOAD=0,38
{"message":"Hello from SIMCom Module"}
AT+CMQTTPUB=0,1,60
Open the AWS IoT MQTT client and see that the message has been published to the server:
Now on the AWS IoT MQTT client click Publish to topic and see that a second message will be published and displayed on the terminal.
Congratulations! Your MQTT communication is working!
Comments