These examples connect the Pico LTE to AWS IoT Core over the cellular connection: an HTTPS POST to the device shadow, and MQTT publish and subscribe. The board authenticates with the certificates of an AWS IoT thing.
Before you begin
Hardware
- Sixfab Pico LTE or Pico LTE 2Registered and active in Sixfab Connect, connected to the computer with the micro USB cable.
Software
- Thonny with MicroPython and the Pico LTE SDKSet up as in the quickstart.
- config.jsonIn the root of the board: Prepare the configuration file.
- AWS accountWith access to AWS IoT Core: create and activate an AWS account.
Set up AWS IoT Core
-
Open AWS IoT Core.
Sign in to the AWS Management Console, type IoT Core in the search bar and select the service.

-
Create policy.
Under Manage in the side bar, open Security → Policies and click Create policy.

Enter a name, set the policy effect to Allow and the policy action and resource to
*(all), then click Create.
-
Create thing.
Open All devices → Things, click Create things, select Create single thing and click Next.

Enter the thing’s name, set the device shadow to Unnamed shadow (classic) and click Next.

-
Create its certificate.
Select Auto-generate a new certificate (recommended) and click Next.

Select the policy you created and click Create thing.

-
Save certificates with these names.
- Device certificate:
client.pem - Private key file:
user_key.pem - Root certificate:
cacert.pem

Put the three files in a folder named
certand upload the folder to the root of the board.
- Device certificate:
On the first run, the SDK moves the certificates into the module’s secure storage and deletes them from the board’s file system.
Find endpoint and topics
Open All devices → Things, select your thing, then the Device Shadows tab and Classic Shadow.

Under MQTT Topics are the host address (the endpoint) and the topics: the publish topic ends in /update.




Run examples
The scripts are in the examples/aws-iot folder of the SDK repository. AWS needs no username or password: the certificates authenticate the board. The message, PAYLOAD_JSON in the script, must be JSON: AWS IoT Core accepts JSON messages.
-
Set endpoint and topic in config.json.
{ "aws": { "https": { "endpoint": "YOUR_AWS_HOST_ADDRESS", "topic": "YOUR_AWS_PUBLISH_TOPIC" } } } -
Run http_post.py.
Open
examples/aws-iot/http_post.pyin Thonny, changePAYLOAD_JSONif you like, and click Run.
INFO: Publishing data to AWS IoT... INFO: Certificates uploaded secure storage. Deleting from file system... INFO: Certificates deleted from file system. INFO: Certificates found in PicoLTE. INFO: Result {'status': 0, 'response': ['{"message":"OK","traceId":"7c2d4647-0ad6-8426-ab82-647fd45d874"}'], 'interval': 0} -
Check device shadow.
The device shadow state on the Classic Shadow page shows
"App": "AWS HTTP Example".
-
Set host and topic in config.json.
{ "aws": { "mqtts": { "host": "YOUR_AWS_HOST_ADDRESS", "port": 8883, "pub_topic": "YOUR_AWS_PUBLISH_TOPIC" } } } -
Run mqtt_publish.py.
Open
examples/aws-iot/mqtt_publish.pyin Thonny, changePAYLOAD_JSONif you like, and click Run.
INFO: Publishing data to AWS IoT... INFO: Result {'status': 0, 'response': ['OK'], 'interval': 0} -
Check device shadow.
The device shadow state shows
"App": "AWS MQTT Example".
-
Set host and topics in config.json.
{ "aws": { "mqtts": { "host": "YOUR_AWS_HOST_ADDRESS", "port": 8883, "sub_topics": [ ["YOUR_MQTT_TOPIC/1", QoS], ["YOUR_MQTT_TOPIC/2", QoS] ] } } }For example:
"sub_topics": [ ["$aws/things/test2-2/shadow/get/accepted", 0] ] -
Open MQTT test client.
On the same AWS IoT page, click MQTT test client, then Publish to a topic.


-
Run mqtt_subscribe.py.
Open
examples/aws-iot/mqtt_subscribe.pyin Thonny and click Run.
-
Publish message.
In the MQTT test client, enter the topic and a message payload and click Publish.

The log shows the message received:

Troubleshooting
INFO: {'interval': 0, 'status': 1}with HTTPS and no message in the device shadow: the endpoint inconfig.jsonis wrong. Copy it again from MQTT Topics.- Status
0but the device shadow does not change: the message was sent. Check that the topic inconfig.jsonis the publish topic ending in/update, that the policy allows all actions (*), and thatPAYLOAD_JSONfollows the AWS IoT Core message format. MQTT: None 8883 Noneand no connection to the broker:config.jsonhas no host or topic. Copy the example above and fill in its fields without breaking the JSON.Certificates couldn't find in modem!: the certificate files do not have the names above, or they are not in thecert/folder of the board.- Status
1with MQTT and no other error: the certificates do not let the board sign in to the broker. Upload the correct certificates, with the correct names, tocert/; if that fails, repeat the AWS IoT Core setup and upload the new certificates.