Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth
In this lesson we will move the subscriber app functionality into the main GameBle project (now called GameBleAws). In order to do this, you need to turn the subscriber into a thread, and fix it so that messages that are sent to the PADDLE topic get turned into messages that can be sent to the paddleQueue.
To implement this lesson I will follow these steps:
- Create a New Project starting from L6GameBle
- Copy over subscriber.c and wifi_config_dct.h
- Update the Makefile
- Create subscriber.h
- Update main.c
- Update subscriber.c
Create a New Project
Copy and paste the L6GameBle project into a new project called L8GameBleAws using Copy/Paste
Create a new Make target for the GameBleAws project
Copy subscriber.c & wifi_config_dct.h
Use copy/paste to make a copy of the subscriber application and paste it into the GameBleAws project. Once done your folder should look like this:
Update the Makefile
NAME := App_WStudio_L8GameBleAws
$(NAME)_SOURCES := main.c \
$(NAME)_COMPONENTS := graphics/ugui \
WIFI_CONFIG_DCT_H := wifi_config_dct.h
$(NAME)_RESOURCES := apps/aws/iot/rootca.cer \
# To support Low memory platforms, disabling components which are not required
GLOBAL_DEFINES += WICED_CONFIG_DISABLE_SSL_SERVER \
In order for the main.c to know about the awsThread (which is the former application_start of subscriber.c) you should create a file called subscriber.h. Then you should define the awsThread function to match the wiced_thread_t function prototype (just a function that takes a wiced_thread_arg and returns void).
extern void awsThread( wiced_thread_arg_t arg );
To integrate the awsThread thread into your main project you need to add the “subscriber.h” to the includes:
Add a new variable to hold the awsThreadHandle.
Finally you should launch the AWS thread by creating it with wiced_rtos_create_thread.
void application_start( )
In order for subscriber.c to be useful you need to fix the includes, send the messages from the PADDLE topic to the game thread, and turn application_start into a thread. Start by fixing the includes (just like we did in the BLE Example in Lesson 6)
When you get a message to the PADDLE topic, you should parse it, then send a message to the game thread to move the paddle. You do this exactly the same way as you did in the BLE project. Notice that I protect the game thread by making sure it send a value less than 100.
WPRINT_APP_INFO( ("[Application/AWS] Payload Received[ Topic: %.*s ]:\n", (int)data->message.topic_length, data->message.topic ) );
if(strncmp(WICED_TOPIC,(const char *)data->message.topic,strlen(WICED_TOPIC)) == 0 && data->message.data_length < 4)
sscanf((const char *)data->message.data,"%d",(int *)&val);
val = 100;
WPRINT_APP_INFO(("Val = %d\n",(int)val));
msg.evt = MSG_POSITION;
msg.val = val;
I don’t really have a good program (like the GoBle) to test moving the paddle live. But you can see that when the game is over, you can still move the paddle using AWS console. In the screen shot below you can see that I moved the paddle to position 0. And you can see that the BLE started at the same time as AWS. Score.