Coder Social home page Coder Social logo

parththingularity / w5300-aws-c Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scarletwiz/w5300-aws-c

0.0 0.0 0.0 11.39 MB

This guide details how to configure and test a FreeRTOS example to connect to AWS IoT.

C 99.63% Assembly 0.30% CMake 0.07%

w5300-aws-c's Introduction

How to Test Connection to AWS IoT using freeRTOS Example

Step 1: Prepare software

The following serial terminal program is required for Connection to AWS IoT with a freeRTOS example test, download and install from below link.

Step 2: Prepare hardware

Combine W5300 TOE Shield with STM32 Nucleo429ZI board.

Connect ethernet cable to W5300 TOE Shield ethernet port.

Connect STM32 Nucleo-144 board to desktop or laptop using 5 pin micro USB cable.

Step 3: Setup AWS IoT

In order to connect to AWS IoT through freeRTOS, the development environment must be configured to use AWS IoT.

This example was tested by configuring AWS IoT Core. Please refer to the 'Create AWS IoT resources' section of document below and configure accordingly.

For more information on AWS IoT, refer to the document below.

Step 4: Setup Connect AWS IoT through freeRTOS Example

To test the Connect AWS IoT through freeRTOS example, minor settings shall be done in code.

  1. Setup network configuration such as IP in 'main.c' , which is the Connect AWS IoT through freeRTOS example in 'W5300-TOE-FREERTOS-C/Core/Src/' directory.

Setup IP, other network settings to suit your network environment and whether to use DHCP.

/* Network */
static wiz_NetInfo g_net_info =
    {
        .mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
        .ip = {192, 168, 11, 2},                     // IP address
        .sn = {255, 255, 255, 0},                    // Subnet Mask
        .gw = {192, 168, 11, 1},                     // Gateway
        .dns = {8, 8, 8, 8},                         // DNS server
        .dhcp = NETINFO_DHCP                         // DHCP enable/disable
};
  1. Setup AWS IoT configuration.

MQTT_DOMAIN should be setup as AWS IoT data endpoint, and MQTT_USERNAME and MQTT_PASSWORD do not need to be setup. Setup MQTT_CLIENT_ID same as thing created during AWS IoT Core setup.

/* AWS IoT */
#define MQTT_DOMAIN "account-specific-prefix-ats.iot.ap-northeast-2.amazonaws.com"
#define MQTT_PUB_TOPIC "$aws/things/my_rp2040_thing/shadow/update"
#define MQTT_SUB_TOPIC "$aws/things/my_rp2040_thing/shadow/update/accepted"
#define MQTT_USERNAME NULL
#define MQTT_PASSWORD NULL
#define MQTT_CLIENT_ID "my_rp2040_thing"
  1. Setup device certificate and key.

You must enter the root certificate, client certificate and private key that were downloaded in Step 2.

Root certificate uses the RSA 2048 bit key, Amazon Root CA 1, and does not use the public key.

Device certificate and key can be set in 'mqtt_certificate.h' in W5300-TOE-FREERTOS-C\Core\Inc' directory.

uint8_t mqtt_root_ca[] =
"-----BEGIN CERTIFICATE-----\r\n"
"...\r\n"
"-----END CERTIFICATE-----\r\n";

uint8_t mqtt_client_cert[] =
"-----BEGIN CERTIFICATE-----\r\n"
"...\r\n"
"-----END CERTIFICATE-----\r\n";

uint8_t mqtt_private_key[] =
"-----BEGIN RSA PRIVATE KEY-----\r\n"
"...\r\n"
"-----END RSA PRIVATE KEY-----\r\n";
  1. The following is a step-by-step guide on how to add a task in freeRTOS.

-Write the Task Function

First, write the function that the task will run. This function is usually composed of an infinite loop, where you define what the task will do.

void aws_example_task(void *argument){
    while(1)
    {
        // Your task implementation here...
    }
}

-Define the Task Handle and Attributes

Before creating a task, you have to define the task handle and task attributes.

osThreadId_t awsExampleTaskHandle;
const osThreadAttr_t aws_example_attributes = {
  .name = "awsExampleTask",
  .stack_size = 128 * 4,
  .priority = (osPriority_t) osPriorityNormal,
};

- Create the task

Create the task using the osThreadNew function. This function takes the task function, the argument to pass to the task function, and the task attributes as arguments.

awsExampleTaskHandle = osThreadNew(aws_example_task, NULL, &aws_example_attributes);

Step 5: Build

  1. After completing the AWS example configuration, build in the IDE you are using.

  2. When the build is completed, is generated in download the firmware to the STM32 Nucleo-144 board.

Step 6: Upload and Run

  1. Connect to the serial COM port of STM32 Nucleo-144 board with Tera Term.

  1. Reset your board.

  2. If the Connect AWS IoT through freeRTOS example works normally on Nucleo-144 board, you can see the network information of W5300, connecting to the AWS IoT and publishing the message.

  1. If you publish the message through the test function in AWS IoT Core to the subcribe topic was configured in Step 4, you can see that Nucleo-144 board receive the message about the subcribe topic.

w5300-aws-c's People

Contributors

scarletwiz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.