Developing Framework for the Project
How i choose platform
I am try to build the framework which is the foundation of this project. In Cypress PSOC 6, we can choose three main OS
1. PSOC ModusToolbox App, which is specified for PSOC 6 hardware
2. Mbed, which is open source multi-platform iOT OS by ARM
3. Amazon FreeRTOS which is open source small RTOS promote by Amazon
The Mbed and Amazon FreeRTOS fully support AWS and Cypress provided document and example code for developer learning.
In this project, i choose Mbed for the platform because:
1. It provide more abstraction though Mbed HAL so it is more easy porting to other hardware. (Hardware independenting)
2. It provide object oriented programming (C++)
3. It fully support Amazon AWS and even other main competitors.
4. It support uTesnor, which is lightweight AI engine, which i want to implement at Advanced phase.
However, the learning curve of Mbed is longer because it is more sophistic and complex that FreeRTOS.
Install of Mbed CLI
Cypress provide good instructions of implement AWS under Mbed, as i just briefing introduced the step of create our framework
1. Installed Mbed CLI
2. Use mbed new <project> create a new program
3. Add Cypress Amazon AWS library
mbed add https://github.com/cypresssemiconductorco/aws-iot
4. Add Cypress connectivity-utilities (for WIFI)
mbed add https://github.com/cypresssemiconductorco/connectivity-utilities
5. Add Cypress EmWin (the licences free use for cypress customers) for LCD display
mbed add https://github.com/cypresssemiconductorco/emwin
6. Add Cypress capsense for touch button
mbed add https://github.com/cypresssemiconductorco/capsense
https://github.com/cypresssemiconductorco/emwin
7. Porting the pioneer kit TFT LCD and emWin driver for Mbed
8. Modify the mbed_app.json for emWin library and custom BSP config
9. Build network.cpp for WIFI connection
10. Build aws-iot.cpp for AWS connection
11. Build log.h for display message to LCD
12. Create Amazon AWS account, add IOT, edit the Policy document, build SSL Certificates, import to Mbed program,
However, in our environment, the WIFI under Mbed may not boot up the WIFI chip , there have chance the system is not recognised the wifi chip (SDIO bus issue),
i need to study more deeply of wifi driver (cybsp_wifi.c) for tweaking such as the timeout and stack setting.
Amazon AWS Security
After successful of connect the WIFI and get the IP from AP, the device fail connect to Amazon because the Policy document incorrect.
the key is import correct certificate, link this to "Things" and "Policies", and with correct "Policies" documents which is required custom for each iOT project.
The briefing step is:
1. Create the Things such as "myIOT"
2. under Things > Security > Create certificate.
3. Get the cert and import to aws_config.h,
4. ensure aws_config.h AWSIOT_ENDPOINT_ADDRESS some as AWS iOT console > Settings > Endpoint
5. carefully edit the policy document, for example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Receive"
],
"Resource": [
"arn:aws:iot:us-west-2:1600000000xx0:topic/AWS_TOPIC" // require match of #define AWSIOT_TOPIC
]
},
{
"Effect": "Allow",
"Action": [
"iot:Subscribe"
],
"Resource": [
"arn:aws:iot:us-west-2:1600000000xx:client/${iot:Connection.Thing.ThingName}"
]
},
{
"Effect": "Allow",
"Action": [
"iot:Connect"
],
"Resource": [
"arn:aws:iot:us-west-2:1600000000xx:client/${iot:Connection.Thing.ThingName}"
]
}
]
}
- Ensure the prefix (arn:aws:iot:us-west-2:100000000:)is correct, this is unique for individuals AWS account.
- the "resource type" (after : and before / ) need specified for each type of "Action" such as topic for iot:Publish and it:Receive.
- the last "resource name" should match your defining.
for example aws_config.h
#define AWSIOT_THING_NAME "myIOT" #define AWSIOT_TOPIC "AWS_TOPIC"
As the AWSIOT_TOPIC is "AWS_TOPIC", and i have a "things" named "myIOT", so is match of above policy document.
More detail https://docs.aws.amazon.com/iot/latest/developerguide/iot-action-resources.html
The Mbed serial console output:
Connecting to the network using Wifi... --- [RESET] --- START DEVICES...: Success Connecting to the network using Wifi... WLAN MAC Address : CC:C0:88:AA:9E:AA WLAN Firmware : wl0: Sep 5 2019 23:24:33 version 7.45.98.92 (r722362 CY) FWID 01-f7128517 WLAN CLM : API: 12.2 Data: 9.10.39 Compiler: 1.29.4 ClmImport: 1.36.3 Creation: 2019-09-05 23:10:00 WHD VERSION : v1.70.0 : v1.70.0 : GCC 6.3 : 2019-12-02 04:14:53 -0600 num of wifi: 7: Success IP: 192.168.1.139 : Success Connected to the network successfully. IP address: 192.168.1.139 connected to AWS : Success Connected to AWS endpoint Success publish to AWS successfully: Success Published to topic successfully Success publish to AWS successfully: Success Published to topic successfully Success publish to AWS successfully: Success Published to topic successfully Success publish to AWS successfully: Success Published to topic successfully Success publish to AWS successfully: Success Published to topic successfully Success
The AWS console output
What Next
The next step is improve the reliability of WIFI, and try to triggering the iOS APP (Device button > AWS Cloud > APP )
