<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WICED &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/tools/wiced/feed/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Wed, 24 Oct 2018 01:03:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>WICED &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Mouser PSoC 6-WiFi-BT L8: Integrate WiFi and AWS Into the Game</title>
		<link>https://iotexpert.com/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/</link>
					<comments>https://iotexpert.com/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:08:53 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5965</guid>

					<description><![CDATA[Summary 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 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>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.</p>
<p>To implement this lesson I will follow these steps:</p>
<ol>
<li>Create a New Project starting from L6GameBle</li>
<li>Copy over subscriber.c and wifi_config_dct.h</li>
<li>Update the Makefile</li>
<li>Create subscriber.h</li>
<li>Update main.c</li>
<li>Update subscriber.c</li>
<li>Test</li>
</ol>
<h1>Create a New Project</h1>
<p>Copy and paste the L6GameBle project into a new project called L8GameBleAws using Copy/Paste</p>
<p><a href="https://iotexpert.com/?attachment_id=6009" rel="attachment wp-att-6009"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.02-PM.png" alt="" width="936" height="336" class="alignnone size-full wp-image-6009" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.02-PM.png 936w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.02-PM-600x215.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.02-PM-300x108.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.02-PM-768x276.png 768w" sizes="(max-width: 936px) 100vw, 936px" /></a></p>
<p>Create a new Make target for the GameBleAws project</p>
<p><a href="https://iotexpert.com/?attachment_id=6008" rel="attachment wp-att-6008"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-1.58.35-PM.png" alt="" width="808" height="824" class="alignnone size-full wp-image-6008" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-1.58.35-PM.png 808w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-1.58.35-PM-600x612.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-1.58.35-PM-294x300.png 294w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-1.58.35-PM-768x783.png 768w" sizes="(max-width: 808px) 100vw, 808px" /></a></p>
<h1>Copy subscriber.c &amp; wifi_config_dct.h</h1>
<p>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:</p>
<p><a href="https://iotexpert.com/?attachment_id=6010" rel="attachment wp-att-6010"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.58-PM.png" alt="" width="384" height="556" class="alignnone size-full wp-image-6010" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.58-PM.png 384w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.01.58-PM-207x300.png 207w" sizes="(max-width: 384px) 100vw, 384px" /></a></p>
<p><a href="https://iotexpert.com/?attachment_id=5969" rel="attachment wp-att-5969"></a></p>
<h1>Update the Makefile</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c">NAME := App_WStudio_L8GameBleAws

$(NAME)_SOURCES := main.c \
    CapSenseThread.c \
	GameThread.c \
	cy_tft_display.c \
	GoBleThread.c \
	GoBle_db.c \
	wiced_bt_cfg.c \
	subscriber.c

$(NAME)_COMPONENTS := graphics/ugui \
                      libraries/drivers/bluetooth/low_energy \
                      protocols/AWS

WIFI_CONFIG_DCT_H := wifi_config_dct.h

$(NAME)_RESOURCES  := apps/aws/iot/rootca.cer \
                      apps/aws/iot/subscriber/client.cer \
                      apps/aws/iot/subscriber/privkey.cer
                      
# To support Low memory platforms, disabling components which are not required
GLOBAL_DEFINES += WICED_CONFIG_DISABLE_SSL_SERVER \
                  WICED_CONFIG_DISABLE_DTLS \
                  WICED_CONFIG_DISABLE_ENTERPRISE_SECURITY \
                  WICED_CONFIG_DISABLE_DES \
                  WICED_CONFIG_DISABLE_ADVANCED_SECURITY_CURVES</pre>
<h1>Create subscriber.h</h1>
<p>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).</p>
<pre class="lang:c decode:true">#pragma once
extern void awsThread( wiced_thread_arg_t arg );
</pre>
<h1>Update main.c</h1>
<p>To integrate the awsThread thread into your main project you need to add the &#8220;subscriber.h&#8221; to the includes:</p>
<pre class="lang:c decode:true">#include "GameThread.h"
#include "GoBleThread.h"
#include "CapSenseThread.h"
#include "subscriber.h"
#include "wiced.h"
</pre>
<p>Add a new variable to hold the awsThreadHandle.</p>
<pre class="start-line:39 lang:c decode:true ">wiced_thread_t awsThreadHandle;</pre>
<p>Finally you should launch the AWS thread by creating it with wiced_rtos_create_thread.</p>
<pre class="start-line:96 lang:c decode:true ">void application_start( )
{
    wiced_init( );
    wiced_rtos_init_queue(&amp;paddleQueue,"paddleQueue",sizeof(game_msg_t),10);
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
    wiced_rtos_create_thread(&amp;capsenseThreadHandle,7,"CapSense Thread",capSenseThread,1024,0);
    wiced_rtos_create_thread(&amp;gameThreadHandle,7,"game Thread",gameThread,4096,0);
    GoBleThread_start();
    wiced_rtos_create_thread(&amp;awsThreadHandle,7,"AWS Thread",awsThread,4096,0);
 }
</pre>
<h1>Update subscriber.c</h1>
<p>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)</p>
<pre class="start-line:88 lang:c decode:true">#include "SystemGlobal.h"
#include "GameThread.h"</pre>
<p>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.</p>
<pre class="start-line:176 lang:c decode:true">        case WICED_AWS_EVENT_PAYLOAD_RECEIVED:
        {
            uint32_t val;
            WPRINT_APP_INFO( ("[Application/AWS] Payload Received[ Topic: %.*s ]:\n", (int)data-&gt;message.topic_length, data-&gt;message.topic ) );

            if(strncmp(WICED_TOPIC,(const char *)data-&gt;message.topic,strlen(WICED_TOPIC)) == 0 &amp;&amp; data-&gt;message.data_length &lt; 4)
            {
                sscanf((const char *)data-&gt;message.data,"%d",(int *)&amp;val);
                if(val&gt;100)
                    val = 100;

                WPRINT_APP_INFO(("Val = %d\n",(int)val));
                game_msg_t msg;
                msg.evt = MSG_POSITION;
                msg.val = val;
                wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            }
        }
        break;
</pre>
<h1>Test</h1>
<p>I don&#8217;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.</p>
<p><a href="https://iotexpert.com/?attachment_id=5970" rel="attachment wp-att-5970"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-6.55.02-PM.png" alt="" width="837" height="501" class="alignnone size-full wp-image-5970" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-6.55.02-PM.png 837w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-6.55.02-PM-600x359.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-6.55.02-PM-300x180.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-6.55.02-PM-768x460.png 768w" sizes="auto, (max-width: 837px) 100vw, 837px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC 6-WiFi-BT L7 : Implement WiFi and AWS</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:07:00 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5946</guid>

					<description><![CDATA[Summary In this lesson I am going to update one of the predefined application which we deliver as part of WICED Studio which knows how to connect to the AWS IoT Cloud to work on my network.  This will demonstrate WiFi and MQTT.  I will also fix the application so that it knows about a [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>In this lesson I am going to update one of the predefined application which we deliver as part of WICED Studio which knows how to connect to the AWS IoT Cloud to work on my network.  This will demonstrate WiFi and MQTT.  I will also fix the application so that it knows about a new MQTT Topic called &#8220;PADDLE&#8221; which will be used to send messages to move the game paddle.</p>
<p>To implement this project I will:</p>
<ol>
<li>Copy the subscriber from demo/aws/iot/pub_sub/subscriber</li>
<li>Setup a &#8220;thing&#8221; on AWS and download the certificates</li>
<li>Update the certificates in the WICED installation</li>
<li>Update the project with my AWS configuration</li>
<li>Test</li>
<li>Update the project to be compatible with the Game</li>
<li>Test</li>
</ol>
<h1>Copy Subscriber &amp; Fix the Makefile</h1>
<p>The first thing that I will do is copy/paste the subscriber application which can be found at demo/aws/iot/pub_sub/subscriber into my folder.  I will also rename the project to L7subscriber. Once that is done it should look like this:</p>
<p><a href="https://iotexpert.com/?attachment_id=6013" rel="attachment wp-att-6013"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.08.29-PM.png" alt="" width="332" height="146" class="alignnone size-full wp-image-6013" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.08.29-PM.png 332w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.08.29-PM-300x132.png 300w" sizes="auto, (max-width: 332px) 100vw, 332px" /></a></p>
<p>Then you need to edit the Makefile to update the name of the project.</p>
<pre class="start-line:37 EnlighterJSRAW" data-enlighter-language="c" ">NAME := App_WStudio_L7subscriber
<a href="https://iotexpert.com/?attachment_id=5975" rel="attachment wp-att-5975"></a></pre>
<h1>Go to Amazon.com and Create a &#8220;thing&#8221;</h1>
<p>In order to connect to the AWS cloud you need to create a &#8220;thing&#8221;.  Go to the AWS console and click &#8220;Create&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=5953" rel="attachment wp-att-5953"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM-1024x593.png" alt="" width="1024" height="593" class="alignnone size-large wp-image-5953" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM-1024x593.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM-600x347.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM-300x174.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM-768x445.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.47.55-PM.png 1166w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>We are just going to create one thing.  So, click &#8220;Create a single thing&#8221;</p>
<p><a href="https://iotexpert.com/?attachment_id=5952" rel="attachment wp-att-5952"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM-1024x589.png" alt="" width="1024" height="589" class="alignnone size-large wp-image-5952" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM-1024x589.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM-600x345.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM-300x172.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM-768x441.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.12-PM.png 1164w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Give it a name, in this case Mouser.</p>
<p><a href="https://iotexpert.com/?attachment_id=5951" rel="attachment wp-att-5951"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM-1024x1007.png" alt="" width="1024" height="1007" class="alignnone size-large wp-image-5951" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM-1024x1007.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM-600x590.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM-300x295.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM-768x755.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.48.54-PM.png 1153w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>AWS has device level security which is implemented with RSA certificates for each device.  So,  you need to let AWS create a certificate for you.</p>
<p><a href="https://iotexpert.com/?attachment_id=5950" rel="attachment wp-att-5950"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM-1024x992.png" alt="" width="1024" height="992" class="alignnone size-large wp-image-5950" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM-1024x992.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM-600x581.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM-300x291.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM-768x744.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.13-PM.png 1169w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Once that is done download the device certificate and the two keys.  You need to 100% make sure you do this now, because you wont get another chance. I&#8217;m also going to activate the certificate once I have the certificate and keys.</p>
<p><a href="https://iotexpert.com/?attachment_id=5949" rel="attachment wp-att-5949"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM-1024x665.png" alt="" width="1024" height="665" class="alignnone size-large wp-image-5949" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM-1024x665.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM-600x390.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM-300x195.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM-768x499.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.49.37-PM.png 1165w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now attach a policy to your thing.  I already have the &#8220;ww101_policy&#8221; setup.</p>
<p><a href="https://iotexpert.com/?attachment_id=5948" rel="attachment wp-att-5948"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM-1024x573.png" alt="" width="1024" height="573" class="alignnone size-large wp-image-5948" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM-1024x573.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM-600x336.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM-300x168.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM-768x430.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-3.55.43-PM.png 1165w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The policy looks like this.  Basically, things are wide open.</p>
<p><a href="https://iotexpert.com/?attachment_id=5962" rel="attachment wp-att-5962"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM-1024x943.png" alt="" width="1024" height="943" class="alignnone size-large wp-image-5962" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM-1024x943.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM-600x553.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM-300x276.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM-768x707.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.54.21-PM.png 1062w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Update the Certificates</h1>
<p>The last thing that you need is the most recent AWS certificate.  WICED expects that you use the RSA2048 bit key.</p>
<p><a href="https://iotexpert.com/?attachment_id=5955" rel="attachment wp-att-5955"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM-1024x526.png" alt="" width="1024" height="526" class="alignnone size-large wp-image-5955" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM-1024x526.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM-600x308.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM-300x154.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM-768x395.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.05.09-PM.png 1282w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now that you have the four security documents., you need to integrate them into your WICED installation.  To do this, change directories to ~/Documents/WICED-Studio-6.2/43xxx_Wi-Fi/resources/apps/aws/iot  Then copy the files, and then make symbolic links.  If you are not on a Mac or Linux then just copy the files and rename them appropriately.</p>
<p><a href="https://iotexpert.com/?attachment_id=5958" rel="attachment wp-att-5958"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.30.16-PM.png" alt="" width="776" height="211" class="alignnone size-full wp-image-5958" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.30.16-PM.png 776w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.30.16-PM-600x163.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.30.16-PM-300x82.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.30.16-PM-768x209.png 768w" sizes="auto, (max-width: 776px) 100vw, 776px" /></a></p>
<h1>Update the Project</h1>
<p>AWS creates a virtual machine and runs an MQTT server on that machine.  You can find out the DNS name of that machine on the settings screen.  Here you can see my endpoint.  You will need to configure the WICED project to talk to your server.</p>
<p><a href="https://iotexpert.com/?attachment_id=5947" rel="attachment wp-att-5947"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM-1024x418.png" alt="" width="1024" height="418" class="alignnone size-large wp-image-5947" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM-1024x418.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM-600x245.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM-300x122.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM-768x314.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.00.34-PM.png 1166w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>You need to change the actual endpoint of your MQTT server in the AWS cloud on line 119</p>
<pre class="start-line:117 EnlighterJSRAW" data-enlighter-language="c"">static wiced_aws_endpoint_info_t my_subscriber_aws_iot_endpoint = {
    .transport           = WICED_AWS_TRANSPORT_MQTT_NATIVE,
    .uri                 = "amk6m51qrxr2u-ats.iot.us-east-1.amazonaws.com",
    .peer_common_name    = NULL,
    .ip_addr             = {0},
    .port                = WICED_AWS_IOT_DEFAULT_MQTT_PORT,
    .root_ca_certificate = NULL,
    .root_ca_length      = 0,
};</pre>
<p>In the file wifi_config_dct.h you will need to change the CLIENT_AP_SSID and CLIENT_AP_PASSPHRASE for your network</p>
<pre class="start-line:60 EnlighterJSRAW" data-enlighter-language="c" ">/* This is the default AP the device will connect to (as a client)*/
#define CLIENT_AP_SSID       "WW101WPA"
#define CLIENT_AP_PASSPHRASE "yourpassword"
#define CLIENT_AP_BSS_TYPE   WICED_BSS_TYPE_INFRASTRUCTURE
#define CLIENT_AP_SECURITY   WICED_SECURITY_WPA2_MIXED_PSK
#define CLIENT_AP_CHANNEL    1
#define CLIENT_AP_BAND       WICED_802_11_BAND_2_4GHZ</pre>
<h1>Test</h1>
<p>In order to test the project you will need to create a make target and program your development kit.</p>
<p><a href="https://iotexpert.com/?attachment_id=6014" rel="attachment wp-att-6014"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.12.13-PM.png" alt="" width="942" height="762" class="alignnone size-full wp-image-6014" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.12.13-PM.png 942w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.12.13-PM-600x485.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.12.13-PM-300x243.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-2.12.13-PM-768x621.png 768w" sizes="auto, (max-width: 942px) 100vw, 942px" /></a></p>
<p>Once that is done you can go to the Amazon.com test console and send MQTT messages to the correct topic.</p>
<p><a href="https://iotexpert.com/?attachment_id=5956" rel="attachment wp-att-5956"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM-1024x825.png" alt="" width="1024" height="825" class="alignnone size-large wp-image-5956" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM-1024x825.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM-600x483.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM-300x242.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM-768x619.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.25.03-PM.png 1354w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here you can see the project attached to my network.  And successfully received the LIGHT ON message.</p>
<p><a href="https://iotexpert.com/?attachment_id=5957" rel="attachment wp-att-5957"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.26.29-PM.png" alt="" width="839" height="524" class="alignnone size-full wp-image-5957" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.26.29-PM.png 839w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.26.29-PM-600x375.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.26.29-PM-300x187.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.26.29-PM-768x480.png 768w" sizes="auto, (max-width: 839px) 100vw, 839px" /></a></p>
<h1>Update the Project for the Game</h1>
<p>We know that the game doesn&#8217;t care about the LIGHT topic so, let&#8217;s change it to PADDLE.</p>
<pre class="start-line:100 lang:c decode:true">#define WICED_TOPIC                                 "PADDLE"</pre>
<p>And let&#8217;s assume that messages to the paddle topic are ASCII numbers &lt;100.  So, we can parse the message and print it out.  Notice that I used sscanf to parse the message and we all know that is super dangerous.</p>
<pre class="start-line:173 EnlighterJSRAW" data-enlighter-language="c"">        case WICED_AWS_EVENT_PAYLOAD_RECEIVED:
        {
            char buff[10];
            uint32_t val;
            WPRINT_APP_INFO( ("[Application/AWS] Payload Received[ Topic: %.*s ]:\n", (int)data-&gt;message.topic_length, data-&gt;message.topic ) );

            if(strncmp(WICED_TOPIC,data-&gt;message.topic,strlen(WICED_TOPIC)) == 0 &amp;&amp; data-&gt;message.data_length &lt; 4)
            {
                sscanf(data-&gt;message.data,"%d",&amp;val);
                WPRINT_APP_INFO(("Val = %d\n",val));
            }
        }
        break;
</pre>
<h1>Test</h1>
<p>After making those updates let&#8217;s program the whole shooting match again.  Then test by sending some messages to the PADDLE topic.</p>
<p><a href="https://iotexpert.com/?attachment_id=5961" rel="attachment wp-att-5961"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM-1024x941.png" alt="" width="1024" height="941" class="alignnone size-large wp-image-5961" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM-1024x941.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM-600x551.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM-300x276.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM-768x706.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.51.23-PM.png 1181w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>It&#8217;s good.  Things are working.</p>
<p><a href="https://iotexpert.com/?attachment_id=5960" rel="attachment wp-att-5960"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.48.01-PM.png" alt="" width="838" height="700" class="alignnone size-full wp-image-5960" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.48.01-PM.png 838w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.48.01-PM-600x501.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.48.01-PM-300x251.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-4.48.01-PM-768x642.png 768w" sizes="auto, (max-width: 838px) 100vw, 838px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC6-WiFi-BT L6 : Integrate GoBle Bluetooth into the Game</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:06:32 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5930</guid>

					<description><![CDATA[Summary At this point we have a working BLE Remote Control and a working Game.  In this lesson I&#8217;ll merge the two projects together so that the GoBle remote control will be able to control the game paddle.  It will do this by creating messages (just like the CapSense messages) and sending them to the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>At this point we have a working BLE Remote Control and a working Game.  In this lesson I&#8217;ll merge the two projects together so that the GoBle remote control will be able to control the game paddle.  It will do this by creating messages (just like the CapSense messages) and sending them to the Game thread via the paddleQueue.  And it will send &#8220;Button0&#8221; messages when &#8220;Button A&#8221; is pressed.</p>
<p>To implement this lesson I will follow these steps:</p>
<ol>
<li>Copy everything into a new project</li>
<li>Modify the Makefile</li>
<li>Modify main.c</li>
<li>Create a new make target</li>
<li>Test it all to make sure things are still working</li>
<li>Modify GoBleThread.c</li>
<li>Program and Test</li>
</ol>
<h1>Copy L4Game into a new project L6GameBle</h1>
<p>Use &#8220;copy&#8221; and &#8220;paste&#8221; to create a new project, when you paste give it the name &#8220;L6GameBle&#8221; (there is an error in the screenshot)</p>
<p><a href="https://iotexpert.com/?attachment_id=5940" rel="attachment wp-att-5940"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.22.49-PM.png" alt="" width="471" height="168" class="alignnone size-full wp-image-5940" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.22.49-PM.png 471w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.22.49-PM-300x107.png 300w" sizes="auto, (max-width: 471px) 100vw, 471px" /></a></p>
<p>Copy the files GoBle_db.c/h, GoBleThread.c/h, and wiced_bt_cfg.c from the GoBle project into your new GameBle project.  After that is done your project should look like this:</p>
<p><a href="https://iotexpert.com/?attachment_id=5939" rel="attachment wp-att-5939"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.20.59-PM.png" alt="" width="285" height="226" class="alignnone size-full wp-image-5939" /></a></p>
<h1>Modify the Makefile</h1>
<ol>
<li>Change the name of the App to &#8220;App_WStudio_L6GameBle&#8221;</li>
<li>Add the new source files</li>
<li>Add the BLE Library &#8220;libraries/drivers/bluetooth/low_energy&#8221;</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">NAME := App_WStudio_L6GameBle

$(NAME)_SOURCES := main.c \
    CapSenseThread.c \
	GameThread.c \
	cy_tft_display.c \
	GoBleThread.c \
	GoBle_db.c \
	wiced_bt_cfg.c

$(NAME)_COMPONENTS := graphics/ugui \
                      libraries/drivers/bluetooth/low_energy
</pre>
<h1>Modify main.c</h1>
<p>Add the include for the GeBleThread.</p>
<pre class="lang:c decode:true">#include "GameThread.h"
#include "GoBleThread.h"
#include "CapSenseThread.h"
#include "wiced.h"</pre>
<p>In the application_start function add a call GoBleThread_start() to get the GoBle thread going</p>
<pre class="start-line:93 EnlighterJSRAW" data-enlighter-language="c"">void application_start( )
{
    wiced_init( );
    wiced_rtos_init_queue(&amp;paddleQueue,"paddleQueue",sizeof(game_msg_t),10);
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
    wiced_rtos_create_thread(&amp;capSenseThreadHandle,7,"CapSense Thread",capSenseThread,1024,0);
    wiced_rtos_create_thread(&amp;gameThreadHandle,7,"game Thread",gameThread,4096,0);
    GoBleThread_start();
 }
</pre>
<h1>Create a new make target</h1>
<p><a href="https://iotexpert.com/?attachment_id=5935" rel="attachment wp-att-5935"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.03.56-PM.png" alt="" width="430" height="421" class="alignnone size-full wp-image-5935" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.03.56-PM.png 430w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-20-at-1.03.56-PM-300x294.png 300w" sizes="auto, (max-width: 430px) 100vw, 430px" /></a></p>
<h1>Test it all to make sure things are still working</h1>
<p>Run the make target and make sure that the game still plays and that you can get remote control messages.</p>
<h1>Modify GoBleThread.c</h1>
<p>Add the includes for the GameThread (to get access to the game message structure) and SystemGlobal (to get access to the queue)</p>
<pre class="start-line:8 lang:c decode:true">#include "GameThread.h"
#include "SystemGlobal.h"</pre>
<p>I don&#8217;t need (or want) the button/slider printout information.  So I will delete the old button code from goble_event_handler. (delete this stuff)</p>
<pre class="start-line:137 lang:c decode:true">            WPRINT_APP_INFO(("# Buttons = %d ButtonMask=%02X Slider x=%02X Slider Y=%02X Raw=",(int)numButtons,(unsigned int)buttonMask,(unsigned int)sliderX,(unsigned int)sliderY));

            for(int i=0;i&lt;p_attr_req-&gt;data.write_req.val_len;i++)
            {
                WPRINT_APP_INFO(("%02X ",p_attr_req-&gt;data.write_req.p_val[i]));
            }
            WPRINT_APP_INFO(("\n"));</pre>
<p>Now, update the code to send the slider and button information to the GameThread (via the paddleQueue).  You may have noticed that the slider on GoBle gives you 0-&gt;0xFF and the direction is the inverse from the game we setup.  So, I will scale the value to 100 and invert it so that the controller moves the paddle the right way on line 143.  The message format is exactly the same as what we setup for the CapSense.  This means the CapSense slider works at the same time as the GoBle controller.</p>
<pre class="start-line:127 EnlighterJSRAW" data-enlighter-language="c"">   case GATT_ATTRIBUTE_REQUEST_EVT:

        p_attr_req = &amp;p_event_data-&gt;attribute_request;
        if( p_attr_req-&gt;request_type == GATTS_REQ_TYPE_WRITE  &amp;&amp; p_attr_req-&gt;data.handle == HDLC_GOBLE_SERIALPORTID_VALUE)
        {
            uint32_t numButtons = p_attr_req-&gt;data.write_req.p_val[3];
            uint32_t sliderY = p_attr_req-&gt;data.write_req.p_val[5+numButtons];
            uint32_t sliderX = p_attr_req-&gt;data.write_req.p_val[6+numButtons];
            uint32_t buttonMask = 0x00;
            for(int i=0;i&lt;numButtons;i++)
            {
                buttonMask |= (1&lt;&lt;p_attr_req-&gt;data.write_req.p_val[5+i]);
            }

            game_msg_t msg;
            msg.evt = MSG_POSITION;
            msg.val = 100 - (100*sliderY/255);
            wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            if(buttonMask &amp; 0x10)
            {
                msg.evt = MSG_BUTTON0;
                msg.val = 1;
                wiced_result_t result=wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            }
            status = WICED_BT_GATT_SUCCESS;
        }
        break;
</pre>
<h1>Program and Test</h1>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC6-WiFi-BT L5 : GoBLE &#8211;  BLE Remote Control for the Game</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:05:43 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6019</guid>

					<description><![CDATA[Summary Although I a like the video game, it is for sure missing something.  That something is IoT.  The first IoT thing that we will do to the game is to add a BLE remote control.  I wanted a pre-done remote control that could be downloaded from the App store.  After looking around a little [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>Although I a like the video game, it is for sure missing something.  That something is IoT.  The first IoT thing that we will do to the game is to add a BLE remote control.  I wanted a pre-done remote control that could be downloaded from the App store.  After looking around a little bit I found GoBle.  I published a detailed article about GoBle <a href="https://iotexpert.com/2018/10/19/goble-remote-control-wiced-bluetooth-implementation/" target="_blank" rel="noopener">here</a>, but I&#8217;ll explain enough to make it work with the game.</p>
<p>Here is a screen shot of what the remote control looks like.  You can see that on the left there is a joystick, and on the right there are some buttons.  My son tells me that this is a classic layout for a remote control.</p>
<p><a href="https://iotexpert.com/2018/10/19/goble-remote-control-wiced-bluetooth-implementation/img_6351/" rel="attachment wp-att-5907"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6351-1024x576.png" alt="" width="1024" height="576" class="alignnone size-large wp-image-5907" srcset="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6351-1024x576.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6351-600x338.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6351-300x169.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6351-768x432.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>This remote control works as a &#8220;Central&#8221; meaning it knows how to connect to Peripherals.  For this lesson we will turn on the CYW4343W and make it be a Bluetooth Peripheral.</p>
<p>To implement this lesson I will follow these steps:</p>
<ol>
<li>Create a folder called &#8220;L5GoBle&#8221;</li>
<li>Create a makefile called L5GoBle.mk</li>
<li>Setup a GATT database by creating GoBle_db.h and GoBle_db.c</li>
<li>Setup wiced_bt_cfg.c</li>
<li>Create GoBleThread.c</li>
<li>Create GoBle.c to startup the GoBleThread</li>
<li>Build, Program and Test</li>
</ol>
<h1>Create a directory called &#8220;L5GoBle&#8221;</h1>
<h1>Create a makefile called L5GoBle.mk</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c">NAME := App_WStudio_L5GoBle

$(NAME)_SOURCES    := GoBle.c \
			          GoBleThread.c \
                      GoBle_db.c \
                      wiced_bt_cfg.c

$(NAME)_INCLUDES   := .

$(NAME)_COMPONENTS += libraries/drivers/bluetooth/low_energy 
</pre>
<h1>Setup a GATT database by creating GoBle_db.h and GoBle_db.c</h1>
<p>Create a file called &#8220;GoBle_db.h&#8221;</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">// GoBle_db.h

#ifndef __GATT_DATABASE_H__
#define __GATT_DATABASE_H__

#include "wiced.h"

#define __UUID_GOBLE                                 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xb0, 0xdf, 0x00, 0x00
#define __UUID_GOBLE_SERIALPORTID                    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0xb1, 0xdf, 0x00, 0x00

// ***** Primary Service 'Generic Attribute'
#define HDLS_GENERIC_ATTRIBUTE                       0x0001

// ***** Primary Service 'Generic Access'
#define HDLS_GENERIC_ACCESS                          0x0014
// ----- Characteristic 'Device Name'
#define HDLC_GENERIC_ACCESS_DEVICE_NAME              0x0015
#define HDLC_GENERIC_ACCESS_DEVICE_NAME_VALUE        0x0016
// ----- Characteristic 'Appearance'
#define HDLC_GENERIC_ACCESS_APPEARANCE               0x0017
#define HDLC_GENERIC_ACCESS_APPEARANCE_VALUE         0x0018

// ***** Primary Service 'GoBle'
#define HDLS_GOBLE                                   0x0028
// ----- Characteristic 'SerialPortId'
#define HDLC_GOBLE_SERIALPORTID                      0x0029
#define HDLC_GOBLE_SERIALPORTID_VALUE                0x002A
// ===== Descriptor 'Client Configuration'
#define HDLD_GOBLE_SERIALPORTID_CLIENT_CONFIGURATION 0x002B


// External definitions
extern const uint8_t  gatt_database[];
extern const uint16_t gatt_database_len;
extern uint8_t BT_LOCAL_NAME[];
extern const uint16_t BT_LOCAL_NAME_CAPACITY;

#endif /* __GATT_DATABASE_H__ */
</pre>
<p>Create a file called &#8220;GoBle.c&#8221;</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">/*
 * This file has been automatically generated by the WICED 20719-B1 Designer.
 * BLE device's GATT database and device configuration.
 *
 */

// GoBle_db.c

#include "GoBle_db.h"

#include "wiced.h"
#include "wiced_bt_uuid.h"
#include "wiced_bt_gatt.h"

/*************************************************************************************
** GATT server definitions
*************************************************************************************/

const uint8_t gatt_database[] = // Define GATT database
{
    /* Primary Service 'Generic Attribute' */
    PRIMARY_SERVICE_UUID16 (HDLS_GENERIC_ATTRIBUTE, UUID_SERVICE_GATT),

    /* Primary Service 'Generic Access' */
    PRIMARY_SERVICE_UUID16 (HDLS_GENERIC_ACCESS, UUID_SERVICE_GAP),

    /* Primary Service 'GoBle' */
    PRIMARY_SERVICE_UUID128 (HDLS_GOBLE, __UUID_GOBLE),

        /* Characteristic 'SerialPortId' */
        CHARACTERISTIC_UUID128_WRITABLE (HDLC_GOBLE_SERIALPORTID, HDLC_GOBLE_SERIALPORTID_VALUE,
            __UUID_GOBLE_SERIALPORTID, LEGATTDB_CHAR_PROP_READ | LEGATTDB_CHAR_PROP_WRITE_NO_RESPONSE | LEGATTDB_CHAR_PROP_WRITE | LEGATTDB_CHAR_PROP_NOTIFY,
            LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_CMD | LEGATTDB_PERM_WRITE_REQ),

            /* Descriptor 'Client Characteristic Configuration' */
            CHAR_DESCRIPTOR_UUID16_WRITABLE (HDLD_GOBLE_SERIALPORTID_CLIENT_CONFIGURATION,
                UUID_DESCRIPTOR_CLIENT_CHARACTERISTIC_CONFIGURATION, LEGATTDB_PERM_READABLE | LEGATTDB_PERM_WRITE_REQ | LEGATTDB_PERM_AUTH_WRITABLE),

};

// Length of the GATT database
const uint16_t gatt_database_len = sizeof(gatt_database);
</pre>
<h1>Setup wiced_bt_cfg.c</h1>
<p>The WICED Bluetooth Configuration file is called &#8220;wiced_bt_config.c&#8221;.  The only change I made from the default is the timeout value of the advertising.  You can copy this directly into your file.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/*
 * This file has been automatically generated by the WICED 20719-B1 Designer.
 * Device Configuration.
 *
 */

/** wiced_bt_cfg.c
 *
 * Runtime Bluetooth stack configuration parameters
 *
 */

#include "wiced_bt_dev.h"
#include "wiced_bt_ble.h"
#include "wiced_bt_uuid.h"
#include "wiced_bt_gatt.h"
#include "wiced_bt_avrc.h"
#include "wiced_bt_cfg.h"

/* Null-Terminated Local Device Name */
uint8_t BT_LOCAL_NAME[] = { 'G','o','B','l','e','T','e','s','t','\0' };
const uint16_t BT_LOCAL_NAME_CAPACITY = sizeof(BT_LOCAL_NAME);


/*******************************************************************
 * wiced_bt core stack configuration
 ******************************************************************/
const wiced_bt_cfg_settings_t wiced_bt_cfg_settings =
{
    .device_name =                          (uint8_t*)BT_LOCAL_NAME,                                    /**&lt; Local device name (NULL terminated) */
    .device_class =                         {0x00, 0x00, 0x00},                                         /**&lt; Local device class */
    .security_requirement_mask =            BTM_SEC_NONE,                                               /**&lt; Security requirements mask (BTM_SEC_NONE, or combination of BTM_SEC_IN_AUTHENTICATE, BTM_SEC_OUT_AUTHENTICATE, BTM_SEC_ENCRYPT */
    .max_simultaneous_links =               1,                                                          /**&lt; Maximum number of simultaneous links to different devices */

    /* BR/EDR Scan Configuration */
    .br_edr_scan_cfg = {
        .inquiry_scan_type =                BTM_SCAN_TYPE_STANDARD,                                     /**&lt; Inquiry Scan Type (BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED) */
        .inquiry_scan_interval =            0x0000,                                                     /**&lt; Inquiry Scan Interval (0 to use default) */
        .inquiry_scan_window =              0x0000,                                                     /**&lt; Inquiry Scan Window (0 to use default) */

        .page_scan_type =                   BTM_SCAN_TYPE_STANDARD,                                     /**&lt; Page Scan Type (BTM_SCAN_TYPE_STANDARD or BTM_SCAN_TYPE_INTERLACED) */
        .page_scan_interval =               0x0000,                                                     /**&lt; Page Scan Interval (0 to use default) */
        .page_scan_window =                 0x0000,                                                     /**&lt; Page Scan Window (0 to use default) */
    },

    /* BLE Scan Settings */
    .ble_scan_cfg = {
        .scan_mode =                        BTM_BLE_SCAN_MODE_PASSIVE,                                  /**&lt; BLE Scan Mode (BTM_BLE_SCAN_MODE_PASSIVE or BTM_BLE_SCAN_MODE_ACTIVE) */

        /* Advertisement Scan Configuration */
        .high_duty_scan_interval =          WICED_BT_CFG_DEFAULT_HIGH_DUTY_SCAN_INTERVAL,               /**&lt; High Duty Scan Interval */
        .high_duty_scan_window =            WICED_BT_CFG_DEFAULT_HIGH_DUTY_SCAN_WINDOW,                 /**&lt; High Duty Scan Window */
        .high_duty_scan_duration =          5,                                                          /**&lt; High Duty Scan Duration in seconds (0 for infinite) */

        .low_duty_scan_interval =           WICED_BT_CFG_DEFAULT_LOW_DUTY_SCAN_INTERVAL,                /**&lt; Low Duty Scan Interval */
        .low_duty_scan_window =             WICED_BT_CFG_DEFAULT_LOW_DUTY_SCAN_WINDOW,                  /**&lt; Low Duty Scan Window */
        .low_duty_scan_duration =           5,                                                          /**&lt; Low Duty Scan Duration in seconds (0 for infinite) */

        /* Connection Scan Configuration */
        .high_duty_conn_scan_interval =     WICED_BT_CFG_DEFAULT_HIGH_DUTY_CONN_SCAN_INTERVAL,          /**&lt; High Duty Connection Cycle Connection Scan Interval */
        .high_duty_conn_scan_window =       WICED_BT_CFG_DEFAULT_HIGH_DUTY_CONN_SCAN_WINDOW,            /**&lt; High Duty Connection Cycle Connection Scan Window */
        .high_duty_conn_duration =          30,                                                         /**&lt; High Duty Connection Cycle Connection Duration in seconds (0 for infinite) */

        .low_duty_conn_scan_interval =      WICED_BT_CFG_DEFAULT_LOW_DUTY_CONN_SCAN_INTERVAL,           /**&lt; Low Duty Connection Cycle Connection Scan Interval */
        .low_duty_conn_scan_window =        WICED_BT_CFG_DEFAULT_LOW_DUTY_CONN_SCAN_WINDOW,             /**&lt; Low Duty Connection Cycle Connection Scan Window */
        .low_duty_conn_duration =           30,                                                         /**&lt; Low Duty Connection Cycle Connection Duration in seconds (0 for infinite) */

        /* Connection Configuration */
        .conn_min_interval =                WICED_BT_CFG_DEFAULT_CONN_MIN_INTERVAL,                     /**&lt; Minimum Connection Interval */
        .conn_max_interval =                WICED_BT_CFG_DEFAULT_CONN_MAX_INTERVAL,                     /**&lt; Maximum Connection Interval */
        .conn_latency =                     WICED_BT_CFG_DEFAULT_CONN_LATENCY,                          /**&lt; Connection Latency */
        .conn_supervision_timeout =         WICED_BT_CFG_DEFAULT_CONN_SUPERVISION_TIMEOUT,              /**&lt; Connection Link Supervision Timeout */
    },

    /* BLE Advertisement Settings */
    .ble_advert_cfg = {
        .channel_map =                      BTM_BLE_ADVERT_CHNL_37 |                                    /**&lt; Advertising Channel Map (mask of BTM_BLE_ADVERT_CHNL_37, BTM_BLE_ADVERT_CHNL_38, BTM_BLE_ADVERT_CHNL_39) */
                                            BTM_BLE_ADVERT_CHNL_38 |
                                            BTM_BLE_ADVERT_CHNL_39,

        .high_duty_min_interval =           WICED_BT_CFG_DEFAULT_HIGH_DUTY_ADV_MIN_INTERVAL,            /**&lt; High Duty Undirected Connectable Minimum Advertising Interval */
        .high_duty_max_interval =           WICED_BT_CFG_DEFAULT_HIGH_DUTY_ADV_MAX_INTERVAL,            /**&lt; High Duty Undirected Connectable Maximum Advertising Interval */
        .high_duty_duration =               0,                                                         /**&lt; High Duty Undirected Connectable Advertising Duration in seconds (0 for infinite) */

        .low_duty_min_interval =            WICED_BT_CFG_DEFAULT_LOW_DUTY_ADV_MIN_INTERVAL,             /**&lt; Low Duty Undirected Connectable Minimum Advertising Interval */
        .low_duty_max_interval =            WICED_BT_CFG_DEFAULT_LOW_DUTY_ADV_MAX_INTERVAL,             /**&lt; Low Duty Undirected Connectable Maximum Advertising Interval */
        .low_duty_duration =                60,                                                         /**&lt; Low Duty Undirected Connectable Advertising Duration in seconds (0 for infinite) */

        .high_duty_directed_min_interval =  WICED_BT_CFG_DEFAULT_HIGH_DUTY_DIRECTED_ADV_MIN_INTERVAL,   /**&lt; High Duty Directed Minimum Advertising Interval */
        .high_duty_directed_max_interval =  WICED_BT_CFG_DEFAULT_HIGH_DUTY_DIRECTED_ADV_MAX_INTERVAL,   /**&lt; High Duty Directed Maximum Advertising Interval */

        .low_duty_directed_min_interval =   WICED_BT_CFG_DEFAULT_LOW_DUTY_DIRECTED_ADV_MIN_INTERVAL,    /**&lt; Low Duty Directed Minimum Advertising Interval */
        .low_duty_directed_max_interval =   WICED_BT_CFG_DEFAULT_LOW_DUTY_DIRECTED_ADV_MAX_INTERVAL,    /**&lt; Low Duty Directed Maximum Advertising Interval */
        .low_duty_directed_duration =       30,                                                         /**&lt; Low Duty Directed Advertising Duration in seconds (0 for infinite) */

        .high_duty_nonconn_min_interval =   WICED_BT_CFG_DEFAULT_HIGH_DUTY_NONCONN_ADV_MIN_INTERVAL,    /**&lt; High Duty Non-Connectable Minimum Advertising Interval */
        .high_duty_nonconn_max_interval =   WICED_BT_CFG_DEFAULT_HIGH_DUTY_NONCONN_ADV_MAX_INTERVAL,    /**&lt; High Duty Non-Connectable Maximum Advertising Interval */
        .high_duty_nonconn_duration =       30,                                                         /**&lt; High Duty Non-Connectable Advertising Duration in seconds (0 for infinite) */

        .low_duty_nonconn_min_interval =    WICED_BT_CFG_DEFAULT_LOW_DUTY_NONCONN_ADV_MIN_INTERVAL,     /**&lt; Low Duty Non-Connectable Minimum Advertising Interval */
        .low_duty_nonconn_max_interval =    WICED_BT_CFG_DEFAULT_LOW_DUTY_NONCONN_ADV_MAX_INTERVAL,     /**&lt; Low Duty Non-Connectable Maximum Advertising Interval */
        .low_duty_nonconn_duration =        0,                                                          /**&lt; Low Duty Non-Connectable Advertising Duration in seconds (0 for infinite) */
    },

    /* GATT Configuration */
    .gatt_cfg = {
        .appearance =                       0x0000,                                                     /**&lt; GATT Appearance */
        .client_max_links =                 1,                                                          /**&lt; Client Config: Maximum number of servers that local client can connect to */
        .server_max_links =                 1,                                                          /**&lt; Server Config: Maximum number of remote client connections allowed by local server */
        .max_attr_len =                     512,                                                        /**&lt; Maximum attribute length; wiced_bt_cfg must have a corresponding buffer pool that can hold this length */
        .max_mtu_size =                     515,                                                        /**&lt; Maximum MTU size for GATT connections, should be between 23 and (max_attr_len + 5) */
    },

    /* RFCOMM Configuration */
    .rfcomm_cfg = {
        .max_links =                        0,                                                          /**&lt; Maximum number of simultaneous connected remote devices */
        .max_ports =                        0,                                                          /**&lt; Maximum Number of simultaneous RFCOMM ports */
    },

    /* Application-Managed L2CAP Protocol Configuration */
    .l2cap_application = {
        .max_links =                        0,                                                          /**&lt; Maximum Number of Application-Managed L2CAP Links (BR/EDR and BLE) */
        .max_psm =                          0,                                                          /**&lt; Maximum Number of Application-Managed BR/EDR PSMs */
        .max_channels =                     0,                                                          /**&lt; Maximum Number of Application-Managed BR/EDR Channels */
        .max_le_psm =                       0,                                                          /**&lt; Maximum Number of Application-Managed LE PSMs */
        .max_le_channels =                  0,                                                          /**&lt; Maximum Number of Application-Managed LE Channels */
        .max_le_l2cap_fixed_channels =      0,                                                          /**&lt; Maximum Number of Application-Managed LE L2CAP Fixed Channnels supported (in addition to mandatory channels 4, 5, and 6 */
    },

    /* Audio/Video Distribution Configuration */
    .avdt_cfg = {
        .max_links =                        0,                                                          /**&lt; Maximum Number of simultaneous Audio/Video links */
        .max_seps =                         0,                                                          /**&lt; Maximum Number of stream end points */
    },

    /* AVRC Configuration */
    .avrc_cfg = {
        .roles =                            0,                                                          /**&lt; Local Roles supported (AVRC_CONN_INITIATOR or AVRC_CONN_ACCEPTOR) */
        .max_links =                        0,                                                          /**&lt; Maximum simultaneous Remote Control links */
    },

    /* LE Address Resolution Database Settings */
    .addr_resolution_db_size =              10,                                                         /**&lt; LE Address Resolution Database Size - Effective only for pre-4.2 controller */
    .max_number_of_buffer_pools =           4,                                                          /**&lt; Maximum number of buffer pools in p_btm_cfg_buf_pools and by wiced_create_pool */
    .rpa_refresh_timeout =                  0,         /**&lt; Interval of random address refreshing - secs */
};

/*******************************************************************
 * wiced_bt_stack buffer pool configuration
 *
 * Configure buffer pools used by the stack
 *
 * Pools must be ordered in increasing buf_size.
 * If a pools runs out of buffers, the next pool will be used.
 ******************************************************************/
const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS] =
{
/*  { buf_size, buf_count, }, */
    { 64,       12,        }, /* Small Buffer Pool */
    { 360,      4,         }, /* Medium Buffer Pool (used for HCI &amp; RFCOMM control messages, min recommended size is 360) */
    { 512,      4,         }, /* Large Buffer Pool  (used for HCI ACL messages) */
    { 1024,     2,         }, /* Extra Large Buffer Pool (used for AVDT media packets and miscellaneous; if not needed, set buf_count to 0) */
};
</pre>
<h1>Create GoBleThread.c</h1>
<p>In  order for the GoBleThread to work you need:</p>
<ol>
<li>The includes for the GATT Database and the WICED bluetooth stack.</li>
<li>External References to the GATT Database.</li>
<li>A few function prototypes.</li>
<li>A function called &#8220;GoBleThread_start&#8221; to startup the Bluetooth stack and get things going. This includes providing Bluetooth management and GATT event handler functions.</li>
</ol>
<pre class="lang:c decode:true">#include "GoBle_db.h"
#include "wiced.h"
#include "wiced_bt_ble.h"
#include "wiced_bt_gatt.h"
#include "wiced_bt_stack.h"

/*******************************************************************
 * Variable Definitions
 ******************************************************************/
extern const wiced_bt_cfg_settings_t wiced_bt_cfg_settings;
extern const wiced_bt_cfg_buf_pool_t wiced_bt_cfg_buf_pools[WICED_BT_CFG_NUM_BUF_POOLS];

/*******************************************************************
 * Function Prototypes
 ******************************************************************/
static wiced_bt_dev_status_t  goble_management_callback    ( wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t *p_event_data );
static void                   goble_set_advertisement_data ( void );
static wiced_bt_gatt_status_t goble_event_handler          ( wiced_bt_gatt_evt_t  event, wiced_bt_gatt_event_data_t *p_event_data );

/*******************************************************************
 * Function Definitions
 ******************************************************************/
void GoBleThread_start(void)
{
    wiced_bt_stack_init(goble_management_callback, &amp;wiced_bt_cfg_settings, wiced_bt_cfg_buf_pools);
}
</pre>
<p>Create a function to setup the advertising data.  The GoBle iOS App looks for Peripherals that are advertising the UUID of the GoBLE Service.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">/* Set Advertisement Data */
void goble_set_advertisement_data( void )
{
    wiced_bt_ble_advert_elem_t adv_elem[3] = { 0 };
    uint8_t adv_flag = BTM_BLE_GENERAL_DISCOVERABLE_FLAG | BTM_BLE_BREDR_NOT_SUPPORTED;
    uint8_t num_elem = 0; 

    /* Advertisement Element for Flags */
    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_FLAG;
    adv_elem[num_elem].len = sizeof(uint8_t);
    adv_elem[num_elem].p_data = &amp;adv_flag;
    num_elem++;

    uint8_t gobleuuid[] = {__UUID_GOBLE};

    /* Advertisement Element for Name */
    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_128SRV_COMPLETE;
    adv_elem[num_elem].len = 16;
    adv_elem[num_elem].p_data = gobleuuid;
    num_elem++;

    /* Set Raw Advertisement Data */
    wiced_bt_ble_set_raw_advertisement_data(num_elem, adv_elem);
}
</pre>
<p>The Bluetooth Management Event Handler needs to take actions when the stack turns on, or one of the pairing events occur.</p>
<pre class="lang:c decode:true">/* Bluetooth Management Event Handler */
wiced_bt_dev_status_t goble_management_callback( wiced_bt_management_evt_t event, wiced_bt_management_evt_data_t *p_event_data )
{
    wiced_bt_dev_status_t status = WICED_BT_SUCCESS;

    switch (event)
    {
    case BTM_ENABLED_EVT:
        goble_set_advertisement_data();
        wiced_bt_gatt_register( goble_event_handler );
        wiced_bt_gatt_db_init( gatt_database, gatt_database_len );
        wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, 0, NULL);
        break;

    case BTM_SECURITY_REQUEST_EVT:
        wiced_bt_ble_security_grant(p_event_data-&gt;security_request.bd_addr, WICED_BT_SUCCESS);
        break;

    case BTM_PAIRING_IO_CAPABILITIES_BLE_REQUEST_EVT:
        p_event_data-&gt;pairing_io_capabilities_ble_request.local_io_cap = BTM_IO_CAPABILITIES_NONE;
        p_event_data-&gt;pairing_io_capabilities_ble_request.oob_data = BTM_OOB_NONE;
        p_event_data-&gt;pairing_io_capabilities_ble_request.auth_req = BTM_LE_AUTH_REQ_NO_BOND;
        break;


    case BTM_USER_CONFIRMATION_REQUEST_EVT: // Just confirm
        wiced_bt_dev_confirm_req_reply( WICED_BT_SUCCESS , p_event_data-&gt;user_confirmation_request.bd_addr);
        break;

    case BTM_PAIRED_DEVICE_LINK_KEYS_REQUEST_EVT:
        WPRINT_APP_INFO(("Paired linke keys\n"));
        status = WICED_BT_ERROR;
        break;

    case BTM_LOCAL_IDENTITY_KEYS_REQUEST_EVT:
    case BTM_PAIRING_COMPLETE_EVT:
    case BTM_ENCRYPTION_STATUS_EVT:
    case BTM_BLE_ADVERT_STATE_CHANGED_EVT:
    case BTM_LPM_STATE_LOW_POWER:
        break;

    default:
        WPRINT_APP_INFO(("Unhandled Bluetooth Management Event: 0x%x (%d)\n", event, event));
        break;
    }

    return status;
}
</pre>
<p>The GATT Event Handler is called</p>
<ol>
<li>When a connection is made or terminated</li>
<li>When the GoBle app writes to your GATT database.  When that happens we will just printout the value that was written</li>
</ol>
<pre class="lang:c decode:true">/* GATT Event Handler */
wiced_bt_gatt_status_t goble_event_handler( wiced_bt_gatt_evt_t event, wiced_bt_gatt_event_data_t *p_event_data )
{
    wiced_bt_gatt_status_t status = WICED_BT_GATT_ERROR;
    wiced_bt_gatt_attribute_request_t *p_attr_req = NULL;

    switch ( event )
    {
    case GATT_CONNECTION_STATUS_EVT:
        if(!p_event_data-&gt;connection_status.connected)
        {
            WPRINT_APP_INFO(("Disconnected\n"));
            wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, 0, NULL);
        }
        else
            WPRINT_APP_INFO(("Connected\n"));
        break;
    case GATT_ATTRIBUTE_REQUEST_EVT:

        p_attr_req = &amp;p_event_data-&gt;attribute_request;
        if( p_attr_req-&gt;request_type == GATTS_REQ_TYPE_WRITE  &amp;&amp; p_attr_req-&gt;data.handle == HDLC_GOBLE_SERIALPORTID_VALUE)
        {
            uint32_t numButtons = p_attr_req-&gt;data.write_req.p_val[3];
            uint32_t sliderY = p_attr_req-&gt;data.write_req.p_val[5+numButtons];
            uint32_t sliderX = p_attr_req-&gt;data.write_req.p_val[6+numButtons];
            uint32_t buttonMask = 0x00;
            for(int i=0;i&lt;numButtons;i++)
            {
                buttonMask |= (1&lt;&lt;p_attr_req-&gt;data.write_req.p_val[5+i]);
            }

            WPRINT_APP_INFO(("# Buttons = %d ButtonMask=%02X Slider x=%02X Slider Y=%02X Raw=",(int)numButtons,(unsigned int)buttonMask,(unsigned int)sliderX,(unsigned int)sliderY));

            for(int i=0;i&lt;p_attr_req-&gt;data.write_req.val_len;i++)
            {
                WPRINT_APP_INFO(("%02X ",p_attr_req-&gt;data.write_req.p_val[i]));
            }
            WPRINT_APP_INFO(("\n"));
            status = WICED_BT_GATT_SUCCESS;
        }
        break;
    default:
        status = WICED_BT_GATT_SUCCESS;
        break;
    }

    return status;
}
</pre>
<h1>Create GoBleThread.h</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#pragma once

extern void GoBleThread_start(void);
</pre>
<h1>Create GoBle.c to startup the GoBleThread</h1>
<pre class="lang:c decode:true ">#include "GoBleThread.h"
#include "wiced.h"


/*******************************************************************
 * Function Definitions
 ******************************************************************/
void application_start(void)
{
    wiced_init();
    GoBleThread_start();

}

</pre>
<h1>Build, Program and Test</h1>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC6-WiFi-BT L4 : The Video Game</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l4-the-video-game/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l4-the-video-game/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:04:40 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6017</guid>

					<description><![CDATA[Summary In this lesson I&#8217;ll finish the video game thread by adding the graphics etc. to play the game.  In addition I&#8217;ll fix up the CapSense thread so that it is connected to the game via an RTOS queue. There are three main things going on in this game. A state machine for the game [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>In this lesson I&#8217;ll finish the video game thread by adding the graphics etc. to play the game.  In addition I&#8217;ll fix up the CapSense thread so that it is connected to the game via an RTOS queue.</p>
<p>There are three main things going on in this game.</p>
<ol>
<li>A state machine for the game screen (Splash, Start, Running, Over)</li>
<li>A 20ms timer that updates the screen while the game is running (moves the Paddle and the Ball)</li>
<li>A GUI queue where the rest of the system &#8211; CapSense,  Bluetooth and WiFi &#8211; can send Button and Paddle messages.</li>
</ol>
<p>To implement this project I will:</p>
<ol>
<li>Setup the project and makefile by copying L3CapSenseTft</li>
<li>Update gamethread.h to define the GUI queue messages</li>
<li>Fix main.c to create the queue</li>
<li>Create SystemGlobal.h to give the rest of the files access to the gui queue</li>
<li>Updating the CapSenseThread to send GUI messages</li>
<li>Update the includes in GameThread.c</li>
<li>Add some #define macros to define game parameters</li>
<li>Add a State Machine for the game &amp; define some paddle movement methods</li>
<li>Make forward declarations for the thread functions</li>
<li>Create some variables to maintain game state</li>
<li>Add display functions for the score and the speed</li>
<li>Add functions to start and end the game</li>
<li>Add helper functions to calculate the top and bottom of the paddle</li>
<li>Add a function to update and draw the paddle</li>
<li>Add a function to update and draw the ball</li>
<li>Add a function for the game timer to call</li>
<li>Update the main game thread</li>
</ol>
<h1>Setup the project and makefile by copying L3CapSenseTft</h1>
<p>Use copy/paste to copy the L3CapSenseTft project to a new folder name L4Game.   Change the name of the makefile to be L4Game.mk.</p>
<p>Edit the makefile and change the name of the application.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">NAME := App_WStudio_L4Game

$(NAME)_SOURCES := main.c \
    CapSenseThread.c \
	GameThread.c \
	cy_tft_display.c

$(NAME)_COMPONENTS := graphics/ugui
</pre>
<p>Create a make target for this project</p>
<p><a href="https://iotexpert.com/?attachment_id=6080" rel="attachment wp-att-6080"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-6.48.06-AM.png" alt="" width="904" height="726" class="alignnone size-full wp-image-6080" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-6.48.06-AM.png 904w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-6.48.06-AM-600x482.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-6.48.06-AM-300x241.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-6.48.06-AM-768x617.png 768w" sizes="auto, (max-width: 904px) 100vw, 904px" /></a></p>
<h1>Update GameThread.h to Define the GUI Messages</h1>
<p>All of the threads in the system (CapSense, Bluetooth, and WiFi) will control the paddle and the button by sending messages to an RTOS queue.  In gameThread.h we will add a definition of that message.  The message is just a structure with two values &#8211; which GUI element and what value to send.</p>
<pre class="lang:c decode:true">#pragma once
#include "wiced.h"

typedef enum {
    MSG_POSITION,
    MSG_BUTTON0,
    MSG_BUTTON1,
} game_evt_t;

typedef struct {
    game_evt_t evt;
    uint32_t val;
} game_msg_t;

void gameThread(wiced_thread_arg_t arg);
</pre>
<h1>Fix main.c to Create the Queue</h1>
<p>I typically believe that the RTOS primitives should be owned by the main.c.  To do this edit main.c and fix the includes.</p>
<pre class="lang:c decode:true">#include "GameThread.h"
#include "wiced.h"
#include "CapSenseThread.h"
#include "SystemGlobal.h"</pre>
<p>Then define the queue variable &#8220;paddleQueue&#8221; which I should have names &#8220;guiQueue&#8221; but it is way to late to fix it now &#8212; oh well.</p>
<pre class="start-line:31 lang:c decode:true ">/******************************************************
 *               Variable Definitions
 ******************************************************/

wiced_thread_t blinkThreadHandle;
wiced_thread_t capSenseThreadHandle;
wiced_thread_t gameThreadHandle;
wiced_queue_t paddleQueue;
</pre>
<p>Create the queue</p>
<pre class="start-line:55 lang:c decode:true">void application_start( )
{
    wiced_init( );
    wiced_rtos_init_queue(&amp;paddleQueue,"paddleQueue",sizeof(game_msg_t),10);
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
    wiced_rtos_create_thread(&amp;capSenseThreadHandle,7,"CapSense Thread",capSenseThread,1024,0);
    wiced_rtos_create_thread(&amp;gameThreadHandle,7,"game Thread",gameThread,4096,0);
 }
</pre>
<h1>Create SystemGlobal.h</h1>
<p>Each of the threads in the system need to have access to the paddleQueue.  In order to do that create a file called SystemGlobal.h and extern the variable to give them that access.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#pragma once

extern wiced_queue_t paddleQueue;
</pre>
<h1>Updating the CapSenseThread to send GUI messages</h1>
<p>Remember that when we setup the CapSenseThread originally, it just printed out the values.  Let&#8217;s fix it so send messages.  So, edit CapSenseThread.c.</p>
<ol>
<li>Add a message variable (line 8)</li>
<li>Fix the button0 and button 1 to make and send RTOS messages (lines 20/21 and 26/27)</li>
<li>Fix the slider to send the position (lines 33-35)</li>
</ol>
<pre class="lang:c decode:true ">#include "wiced.h"
#include "GameThread.h"
#include "SystemGlobal.h"

void capSenseThread(wiced_thread_arg_t arg)
{

    game_msg_t msg;

    CapSense_Start();
    CapSense_ScanAllWidgets();
    while(1)
    {
        if(!CapSense_IsBusy())
        {

            CapSense_ProcessAllWidgets();
            if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
            {
                msg.evt = MSG_BUTTON0;
                wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            }

            if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
            {
                msg.evt = MSG_BUTTON1;
                wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            }

            uint32_t val = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0_WDGT_ID);
            if(val &lt; 0xFFFF)
            {
                msg.evt = MSG_POSITION;
                msg.val = val;
                wiced_rtos_push_to_queue(&amp;paddleQueue,&amp;msg,0);
            }
            CapSense_ScanAllWidgets();
        }
        wiced_rtos_delay_milliseconds(25); // Poll every 25ms (actual scan time ~8ms)
    }
}
</pre>
<h1>Update the includes in GameThread.c</h1>
<p>Now let&#8217;s fix GameThread.c.  Start by editing the includes to add a new file called &#8220;SystemGlobal.h&#8221; which contains the global variable for the GUI queue.</p>
<pre class="lang:c decode:true">#include "GameThread.h"
#include "cy_tft_display.h"
#include "SystemGlobal.h"
#include "ugui.h"
</pre>
<h1>Add some #define macros in GameThread.c</h1>
<p>There are a number of constants which I use in the game.  In this section I use #define macros to define them.</p>
<pre class="start-line:10 lang:c decode:true">#define UPDATE_SCREEN_TIME (20) // Update the screen every 20ms
#define SPEED (2)
#define SCREEN_X (320)
#define SCREEN_Y (240)
#define TOP_FIELD (21)
#define PD_WIDTH (10)
#define PD_LEN (70)
#define DOTS (3)
#define PADDLE0_COLOR (C_BLUE)
#define BALL_COLOR (C_GREEN)
#define BALL_SIZE (10)</pre>
<h1>Add a State Machine for the Game &amp; Define Paddle Movement</h1>
<p>Open up GameThread.c &#8211; all of the game control functions will go there.</p>
<p>There will be four screens in the game.  A splash screen to display Cypress and Mouser, a Ready Player 1 Screen, the actual game screen and a game over screen.</p>
<p>In addition the paddle can move a little bit at a time (increment) or jump directly to the position (absolute)</p>
<pre class="start-line:33 lang:c decode:true">// States of the game
typedef enum {
    GS_SPLASH,
    GS_START,
    GS_RUNNING,
    GS_OVER
} game_state_t;

// Methods to move the paddle
typedef enum {
    PADDLE_INCREMENT,
    PADDLE_ABSOLUTE
} paddle_update_t;</pre>
<h1>Fix the gameState statemachine</h1>
<p>In the splash screen I need to set the state machine to GS_SPLASH</p>
<pre class="start-line:242 lang:c decode:true">static void displaySplashScreen()
{
    gameState = GS_SPLASH;
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5,22,36,"Cypress");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*2,22,36,"Mouser");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*3,22,36,"PSoC 6");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*4,22,36,"WICED 4343");

    wiced_rtos_delay_milliseconds(2000);
}
</pre>
<p>In the start screen I need to set the state machine to GS_START</p>
<pre class="start-line:262 EnlighterJSRAW" data-enlighter-language="c" ">// Display the Start Screen
static void  displayStartScreen()
{
    gameState = GS_START;
    UG_FillScreen( C_BLACK );
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 -2 - 18 ,22,36,"Ready");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 + 2 + 18 ,22,36,"Player 1");
    displayStartButton();
}
</pre>
<h1>Make Forward Declarations for Functions</h1>
<p>You should define the functions in advance of using them</p>
<pre class="start-line:52 lang:c decode:true">/******************************************************
 *               Static Function Declarations
 ******************************************************/
static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string);
static void displaySplashScreen();
static void displayStartButton();
static void  displayStartScreen();
static void displayScore();
static void displaySpeed();
static void endGame();
static inline uint32_t calcPaddleTop();
static inline uint32_t calcPaddleBottom();
static void updatePaddle(paddle_update_t type);
static void updateBall();
static void updateScreen(void *arg);
</pre>
<h1>Create some variables to maintain game state</h1>
<p>The updateScreenTimer is used while the game is running to call the updateScreen every 20ms.  The rest of the variables are self explanatory.</p>
<pre class="start-line:68 lang:c decode:true">/******************************************************
 *               Variable Definitions
 ******************************************************/
static UG_GUI   gui;
static wiced_timer_t updateScreenTimer;

static uint32_t gameScore;
static game_state_t gameState;

// position of the paddle
static uint32_t paddle0_desire_pos=0;
static uint32_t paddle0_cur_pos=0;

// Position, direction and speed of the ball
static uint32_t ballx,bally;
static int32_t ballXdir, ballYdir;
static uint32_t ballSpeed;
</pre>
<h1>Add Display Functions for the Score &amp; Speed</h1>
<p>These two functions print the speed and score at the top of the screen.</p>
<pre class="start-line:134 EnlighterJSRAW" data-enlighter-language="c"">// This function displays the score
static void displayScore()
{
    char buff[10];
    sprintf(buff,"%2X",(unsigned int)gameScore);
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 75, 0, buff);
}

// This function displays the speed
static void displaySpeed()
{
    char buff[10];
    sprintf(buff,"%2X",(unsigned int)ballSpeed-1);
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 275, 0, buff);
}
</pre>
<h1>Add Function to Start the Game</h1>
<p>When the game needs to start you:</p>
<ol>
<li>Reset the score</li>
<li>Set the paddle position</li>
<li>Move the ball to the middle of the paddle</li>
<li>Set the ball to move to the right and down</li>
<li>Clear the screen, display score and speed</li>
<li>Start the game running</li>
</ol>
<pre class="start-line:153 lang:c decode:true">// This function initializes everything and starts a new game
static void startGame()
{
    gameScore = 0;

    paddle0_desire_pos = 50; // start the game with the paddle moving
    paddle0_cur_pos = 0;

    ballx = PD_WIDTH ;                   // start the ball on the paddle on the right of the screen
    bally  = calcPaddleTop() + PD_LEN/2; // start the ball in the middle of the paddle

    ballSpeed = SPEED;

    ballXdir = ballSpeed;
    ballYdir = ballSpeed;

    UG_FillScreen( C_BLACK );  // clear screen
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 0, 0,  "Score:");
    displayScore();
    UG_PutString(200,0,"Speed:");
    displaySpeed();
    UG_DrawLine(0,20,SCREEN_X,20,C_RED); // red line under text to represent top of play screen

    gameState = GS_RUNNING;
    wiced_rtos_start_timer(&amp;updateScreenTimer); // Timer to update screen
}

</pre>
<h1>Add Function to End the Game</h1>
<p>When the game is over you should:</p>
<ol>
<li>Move the game state to over</li>
<li>Stop the timer</li>
<li>Display game over</li>
<li>Display press button 0 to start</li>
</ol>
<pre class="start-line:181 lang:c decode:true">// Stop the game
static void endGame()
{
    gameState = GS_OVER;
    wiced_rtos_stop_timer(&amp;updateScreenTimer);
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2,22,36,"Game Over");
    displayStartButton();
}
</pre>
<h1>Add Helper Functions to Calculate Paddle Top &amp; Bottom</h1>
<p>There are two places where you need to know the position of the Paddle.  Specifically:</p>
<ol>
<li>To draw the paddle</li>
<li>To figure out if the ball hit the paddle or not.</li>
</ol>
<p>These two functions calculate the pixel position of the top and bottom of the paddle based on it current position</p>
<pre class="lang:c decode:true ">// Figure out the y position of the top of the paddle
static inline uint32_t calcPaddleTop()
{
    return (paddle0_cur_pos)*DOTS+TOP_FIELD;
}

// Figure out the y position of the bottom of the paddle
static inline uint32_t calcPaddleBottom()
{
    return (paddle0_cur_pos)*DOTS+PD_LEN+TOP_FIELD;
}</pre>
<h1>Add a Function to Update &amp; Draw the Paddle</h1>
<p>While the game is running you need the paddle to move.  There are two methods:</p>
<ol>
<li>Absolute just moves the current position immediately to the desired position.</li>
<li>Incremental, which moves the paddle a little bit towards the desired position.</li>
</ol>
<pre class="start-line:204 lang:c decode:true">// Move the paddle either to : PADDLE_INCREMENT the next location or PADDLE_ABSOLUTE - final location
static void updatePaddle(paddle_update_t type)
{
    // If the paddle is where it is supposed to be then just return
    if(paddle0_cur_pos == paddle0_desire_pos)
        return;

    // erase the current paddle
    UG_FillFrame(0,calcPaddleTop(),PD_WIDTH,calcPaddleBottom(),C_BLACK);

    switch (type)
    {

    case PADDLE_INCREMENT:

        if(paddle0_cur_pos &lt; paddle0_desire_pos)
            paddle0_cur_pos += SPEED;
        else
            paddle0_cur_pos -= SPEED;

        // If the paddle is within one move of the final spot, put it there
        if(abs((int)paddle0_cur_pos-(int)paddle0_desire_pos) &lt; SPEED)
            paddle0_cur_pos = paddle0_desire_pos;
        break;

    case PADDLE_ABSOLUTE:
        paddle0_cur_pos = paddle0_desire_pos;
        break;
    }
    // draw the paddle
    UG_FillFrame(0,calcPaddleTop(),PD_WIDTH,calcPaddleBottom(),PADDLE0_COLOR);
}
</pre>
<h1>Add a function to update and draw the ball</h1>
<p>You need a function to:</p>
<ol>
<li>Move the ball</li>
<li>Figure out if it hit the right/left/top/bottom of the screen and do the right thing.</li>
</ol>
<p>When the ball hits one of those surfaces it needs to change direction to either plus or minus.</p>
<p>Every time it hits the paddle the score should increase and possibly speed up.</p>
<p>If it misses the paddle the game is over.</p>
<pre class="start-line:237 EnlighterJSRAW" data-enlighter-language="c" ">// Move the ball to the next location
static void updateBall()
{
    static const uint32_t BallFudgeFactor=3;

    UG_DrawCircle(ballx,bally,BALL_SIZE,C_BLACK);

    ballx += ballXdir;
    bally += ballYdir;

    // Check to see if the ball hit the far right side
    if(ballx &gt; SCREEN_X - BALL_SIZE)
    {

        ballx = SCREEN_X - BALL_SIZE;
        ballXdir = -ballSpeed;
    }

    // check to see if the ball hit the far left side... or the paddle
    if(ballx &lt; (BALL_SIZE + PD_WIDTH + BallFudgeFactor))
    {
        // See if the ball missed the paddle
        if(bally + BALL_SIZE &lt; calcPaddleTop() || bally - BALL_SIZE &gt; calcPaddleBottom())
        {
            endGame();
            //WPRINT_APP_INFO(("Missed Paddle\r\n"));
        }

        gameScore = gameScore + 1;
        displayScore();
        if(gameScore % 3 == 0) // Speed up every three hits
        {
            ballSpeed +=1;
            displaySpeed();
        }

        ballx = BALL_SIZE + PD_WIDTH + BallFudgeFactor;
        ballXdir = +ballSpeed;
    }
    // Check to see if the ball hit the top or bottom
    if(bally &gt; SCREEN_Y - BALL_SIZE) // bottom
    {
        bally = SCREEN_Y - BALL_SIZE;
        ballYdir = -ballSpeed;
    }

    if(bally &lt; TOP_FIELD+BALL_SIZE) // top
    {
        bally = BALL_SIZE+TOP_FIELD;
        ballYdir = +ballSpeed;
    }
    UG_DrawCircle(ballx,bally,BALL_SIZE,BALL_COLOR);
}
</pre>
<h1>Create a Function for the Game Timer</h1>
<p>An RTOS timer runs every 20ms.  That timer needs a function to move the paddle and move the ball.</p>
<pre class="start-line:291 EnlighterJSRAW" data-enlighter-language="c"">// This function is called every UPADTE_SCREEN_TIME milliseconds by the updateScreenTimer
static void updateScreen(void *arg)
{
    updatePaddle(PADDLE_INCREMENT);
    updateBall();
}</pre>
<h1>Update the Main Game Thread</h1>
<p>The main game thread needs to get messages out of the queue and then do the right thing based on the game state.</p>
<pre class="start-line:298 EnlighterJSRAW" data-enlighter-language="c"">// Main game thread
void gameThread(wiced_thread_arg_t arg)
{
    game_msg_t msg;

    Cy_TFT_Init();                                             // Init the TFT
    UG_Init( &amp;gui, Cy_TFT_displayDriver, SCREEN_X, SCREEN_Y ); // Connect the driver

    UG_FillScreen( C_BLACK );   // Clear the screen
    UG_SetBackcolor( C_BLACK );
    UG_SetForecolor( C_WHITE );

    wiced_rtos_init_timer(&amp;updateScreenTimer,UPDATE_SCREEN_TIME,updateScreen,0);
    displaySplashScreen();
    displayStartScreen();

    while(1)
    {
        wiced_rtos_pop_from_queue(&amp;paddleQueue,&amp;msg,WICED_WAIT_FOREVER);
        switch(msg.evt)
        {
        case MSG_POSITION:
            if(gameState == GS_RUNNING)
                paddle0_desire_pos = msg.val/2;
            if(gameState == GS_OVER)
            {
                paddle0_desire_pos = msg.val/2;
                updatePaddle(PADDLE_ABSOLUTE);
            }
            break;

        case MSG_BUTTON0:
            if(gameState == GS_OVER || gameState == GS_START)
                startGame();
            break;
        case MSG_BUTTON1:
            break;
        }
    }
}
</pre>
<h1>Program and Test</h1>
<p>Now that it is all done&#8230; program and test it.</p>
<h1>GameThread.c</h1>
<p>Here is the whole thread is here so you can copy/paste it into your file.</p>
<pre class="lang:c decode:true ">#include "GameThread.h"
#include "cy_tft_display.h"
#include "SystemGlobal.h"
#include "ugui.h"

/******************************************************
 *                      Macros
 ******************************************************/
#define UPDATE_SCREEN_TIME (20) // Update the screen every 20ms
#define SPEED (2)
#define SCREEN_X (320)
#define SCREEN_Y (240)
#define TOP_FIELD (21)
#define PD_WIDTH (10)
#define PD_LEN (70)
#define DOTS (3)
#define PADDLE0_COLOR (C_BLUE)
#define BALL_COLOR (C_GREEN)
#define BALL_SIZE (10)

/******************************************************
 *                    Constants
 ******************************************************/

/******************************************************
 *                   Enumerations
 ******************************************************/

/******************************************************
 *                 Type Definitions
 ******************************************************/
// States of the game
typedef enum {
    GS_SPLASH,
    GS_START,
    GS_RUNNING,
    GS_OVER
} game_state_t;

// Methods to move the paddle
typedef enum {
    PADDLE_INCREMENT,
    PADDLE_ABSOLUTE
} paddle_update_t;

/******************************************************
 *                    Structures
 ******************************************************/


/******************************************************
 *               Static Function Declarations
 ******************************************************/
static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string);
static void displaySplashScreen();
static void displayStartButton();
static void  displayStartScreen();
static void displayScore();
static void displaySpeed();
static void endGame();
static inline uint32_t calcPaddleTop();
static inline uint32_t calcPaddleBottom();
static void updatePaddle(paddle_update_t type);
static void updateBall();
static void updateScreen(void *arg);

/******************************************************
 *               Variable Definitions
 ******************************************************/
static UG_GUI   gui;
static wiced_timer_t updateScreenTimer;

static uint32_t gameScore;
static game_state_t gameState;

// position of the paddle
static uint32_t paddle0_desire_pos=0;
static uint32_t paddle0_cur_pos=0;

// Position, direction and speed of the ball
static uint32_t ballx,bally;
static int32_t ballXdir, ballYdir;
static uint32_t ballSpeed;


/******************************************************
 *               Functions
 ******************************************************/

// ARH Function to put text in the center of a point (UG_PutString does upper left)
static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string)
{
    y = y - fonty/2;
    x = x - (strlen(string)/2)*fontx;
    if(strlen(string)%2)
        x = x - fontx/2;
    UG_PutString(x,y,string);
}


// Display the splash screen
static void displaySplashScreen()
{
    gameState = GS_SPLASH;
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5,22,36,"Cypress");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*2,22,36,"Mouser");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*3,22,36,"PSoC 6");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*4,22,36,"WICED 4343");

    wiced_rtos_delay_milliseconds(2000);
}

// This function displays the start button message
static void displayStartButton()
{
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutStringCenter(SCREEN_X/2 , SCREEN_Y - 30 ,12,22,  "Press B0 To Start");
}

// Display the Start Screen
static void  displayStartScreen()
{
    gameState = GS_START;
    UG_FillScreen( C_BLACK );
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 -2 - 18 ,22,36,"Ready");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 + 2 + 18 ,22,36,"Player 1");
    displayStartButton();
}


// This function displays the score
static void displayScore()
{
    char buff[10];
    sprintf(buff,"%2X",(unsigned int)gameScore);
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 75, 0, buff);
}

// This function displays the speed
static void displaySpeed()
{
    char buff[10];
    sprintf(buff,"%2X",(unsigned int)ballSpeed-1);
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 275, 0, buff);
}


// This function initializes everything and starts a new game
static void startGame()
{
    gameScore = 0;

    paddle0_desire_pos = 50; // start the game with the paddle moving
    paddle0_cur_pos = 0;

    ballx = PD_WIDTH ;                   // start the ball on the paddle on the right of the screen
    bally  = calcPaddleTop() + PD_LEN/2; // start the ball in the middle of the paddle

    ballSpeed = SPEED;

    ballXdir = ballSpeed;
    ballYdir = ballSpeed;

    UG_FillScreen( C_BLACK );  // clear screen
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutString( 0, 0,  "Score:");
    displayScore();
    UG_PutString(200,0,"Speed:");
    displaySpeed();
    UG_DrawLine(0,20,SCREEN_X,20,C_RED); // red line under text to represent top of play screen

    gameState = GS_RUNNING;
    wiced_rtos_start_timer(&amp;updateScreenTimer); // Timer to update screen
}

// Stop the game
static void endGame()
{
    gameState = GS_OVER;
    wiced_rtos_stop_timer(&amp;updateScreenTimer);
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2,22,36,"Game Over");
    displayStartButton();
}


// Figure out the y position of the top of the paddle
static inline uint32_t calcPaddleTop()
{
    return (paddle0_cur_pos)*DOTS+TOP_FIELD;
}

// Figure out the y position of the bottom of the paddle
static inline uint32_t calcPaddleBottom()
{
    return (paddle0_cur_pos)*DOTS+PD_LEN+TOP_FIELD;
}

// Move the paddle either to : PADDLE_INCREMENT the next location or PADDLE_ABSOLUTE - final location
static void updatePaddle(paddle_update_t type)
{
    // If the paddle is where it is supposed to be then just return
    if(paddle0_cur_pos == paddle0_desire_pos)
        return;

    // erase the current paddle
    UG_FillFrame(0,calcPaddleTop(),PD_WIDTH,calcPaddleBottom(),C_BLACK);

    switch (type)
    {

    case PADDLE_INCREMENT:

        if(paddle0_cur_pos &lt; paddle0_desire_pos)
            paddle0_cur_pos += SPEED;
        else
            paddle0_cur_pos -= SPEED;

        // If the paddle is within one move of the final spot, put it there
        if(abs((int)paddle0_cur_pos-(int)paddle0_desire_pos) &lt; SPEED)
            paddle0_cur_pos = paddle0_desire_pos;
        break;

    case PADDLE_ABSOLUTE:
        paddle0_cur_pos = paddle0_desire_pos;
        break;
    }
    // draw the paddle
    UG_FillFrame(0,calcPaddleTop(),PD_WIDTH,calcPaddleBottom(),PADDLE0_COLOR);
}

// Move the ball to the next location
static void updateBall()
{
    static const uint32_t BallFudgeFactor=3;

    UG_DrawCircle(ballx,bally,BALL_SIZE,C_BLACK);

    ballx += ballXdir;
    bally += ballYdir;

    // Check to see if the ball hit the far right side
    if(ballx &gt; SCREEN_X - BALL_SIZE)
    {

        ballx = SCREEN_X - BALL_SIZE;
        ballXdir = -ballSpeed;
    }

    // check to see if the ball hit the far left side... or the paddle
    if(ballx &lt; (BALL_SIZE + PD_WIDTH + BallFudgeFactor))
    {
        // See if the ball missed the paddle
        if(bally + BALL_SIZE &lt; calcPaddleTop() || bally - BALL_SIZE &gt; calcPaddleBottom())
        {
            endGame();
            //WPRINT_APP_INFO(("Missed Paddle\r\n"));
        }

        gameScore = gameScore + 1;
        displayScore();
        if(gameScore % 3 == 0) // Speed up every three hits
        {
            ballSpeed +=1;
            displaySpeed();
        }

        ballx = BALL_SIZE + PD_WIDTH + BallFudgeFactor;
        ballXdir = +ballSpeed;
    }
    // Check to see if the ball hit the top or bottom
    if(bally &gt; SCREEN_Y - BALL_SIZE) // bottom
    {
        bally = SCREEN_Y - BALL_SIZE;
        ballYdir = -ballSpeed;
    }

    if(bally &lt; TOP_FIELD+BALL_SIZE) // top
    {
        bally = BALL_SIZE+TOP_FIELD;
        ballYdir = +ballSpeed;
    }
    UG_DrawCircle(ballx,bally,BALL_SIZE,BALL_COLOR);
}

// This function is called every UPADTE_SCREEN_TIME milliseconds by the updateScreenTimer
static void updateScreen(void *arg)
{
    updatePaddle(PADDLE_INCREMENT);
    updateBall();
}


// Main game thread
void gameThread(wiced_thread_arg_t arg)
{
    game_msg_t msg;

    Cy_TFT_Init();                                             // Init the TFT
    UG_Init( &amp;gui, Cy_TFT_displayDriver, SCREEN_X, SCREEN_Y ); // Connect the driver

    UG_FillScreen( C_BLACK );   // Clear the screen
    UG_SetBackcolor( C_BLACK );
    UG_SetForecolor( C_WHITE );

    wiced_rtos_init_timer(&amp;updateScreenTimer,UPDATE_SCREEN_TIME,updateScreen,0);
    displaySplashScreen();
    displayStartScreen();

    while(1)
    {
        wiced_rtos_pop_from_queue(&amp;paddleQueue,&amp;msg,WICED_WAIT_FOREVER);
        switch(msg.evt)
        {
        case MSG_POSITION:
            if(gameState == GS_RUNNING)
                paddle0_desire_pos = msg.val/2;
            if(gameState == GS_OVER)
            {
                paddle0_desire_pos = msg.val/2;
                updatePaddle(PADDLE_ABSOLUTE);
            }
            break;

        case MSG_BUTTON0:
            if(gameState == GS_OVER || gameState == GS_START)
                startGame();
            break;
        case MSG_BUTTON1:
            break;
        }
    }
}
</pre>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l4-the-video-game/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC 6-WiFi-BT L3: Using the CY8CKIT-028-TFT Shield</title>
		<link>https://iotexpert.com/mouser-vtw-lesson-3-using-the-tft/</link>
					<comments>https://iotexpert.com/mouser-vtw-lesson-3-using-the-tft/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:03:33 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6029</guid>

					<description><![CDATA[Summary In this lesson we will start making the game.  The first thing that it will need is a display and we will use the CY8CKIT-028-TFT.  In order to talk to the display we will use a library built into WICED called ugui.  That library needs a driver configuration which we will copy of out [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>In this lesson we will start making the game.  The first thing that it will need is a display and we will use the CY8CKIT-028-TFT.  In order to talk to the display we will use a library built into WICED called ugui.  That library needs a driver configuration which we will copy of out the code example we provide.  Finally we will start building a thread called the &#8220;GameThread&#8221; which will actually make up the game.</p>
<ol>
<li>Download CE222494_PSoC6_WICED_WiFi</li>
<li>Copy the L2CapSense into L3CapSenseTft</li>
<li>Copy cy_tft_display.c/h into the project</li>
<li>Make a file GameThread.h</li>
<li>Make a file GameThread.c</li>
<li>Rename L2CapSense.mk to be L3CapSenseTft.mk &amp; Fix</li>
<li>Update main.c</li>
<li>Test</li>
</ol>
<h1>Download CE222494_PSoC6_WICED_WiFi</h1>
<p>If you click on the <a href="http://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit" target="_blank" rel="noopener">CY8CKIT-062-WiFi-BT</a> webpage you will find that there are a bunch of files which are associated with the development kit, including <a href="http://www.cypress.com/file/416491/download" target="_blank" rel="noopener">CY8CKIT-062-WiFi-BT PSoC® 6 WiFi-BT Pioneer Kit Code Examples.zip</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6068" rel="attachment wp-att-6068"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM-1024x773.png" alt="" width="1024" height="773" class="alignnone size-large wp-image-6068" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM-1024x773.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM-600x453.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM-300x227.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM-768x580.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.43.31-AM.png 1504w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Download that folder, then copy the directory into your WICED Studio Apps/WStudio folder.</p>
<p><a href="https://iotexpert.com/?attachment_id=6069" rel="attachment wp-att-6069"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.45.47-AM.png" alt="" width="956" height="394" class="alignnone size-full wp-image-6069" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.45.47-AM.png 956w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.45.47-AM-600x247.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.45.47-AM-300x124.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.45.47-AM-768x317.png 768w" sizes="auto, (max-width: 956px) 100vw, 956px" /></a></p>
<p>Once you do that it should look like this:</p>
<p><a href="https://iotexpert.com/?attachment_id=6071" rel="attachment wp-att-6071"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.48.36-AM.png" alt="" width="618" height="486" class="alignnone size-full wp-image-6071" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.48.36-AM.png 618w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.48.36-AM-600x472.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-4.48.36-AM-300x236.png 300w" sizes="auto, (max-width: 618px) 100vw, 618px" /></a></p>
<h1>Copy L3CapSense into L3CapSenseTft</h1>
<p>Now copy/paste the L2CapSense project into a new project called L3CapSenseTft</p>
<h1>Copy cy_tft_display.c/h into the project</h1>
<p>Open up the CE222494 code example directory and copy the two files cy_tft_display.c andcy_tft_display.c which are drivers for the ugui library and then paste them into your new project L3CapSenseTft.</p>
<h1>Make a file GameThread.h</h1>
<p>Create a new file called GamThread.h and a definition of the GameThread which will be used by the main.c to get the game thread going.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#pragma once
#include "wiced.h"

void gameThread(wiced_thread_arg_t arg);
</pre>
<h1>Make a file GameThread.c</h1>
<p>Now create a file called GameThread.c it will have 5 functions.  Here is the whole file to make it simpler to copy and paste, but Ill explain each function one by one</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "GameThread.h"

#include "cy_tft_display.h"

#define SCREEN_X (320)
#define SCREEN_Y (240)

static UG_GUI   gui;


// ARH Function to put text in the center of a point (UG_PutString does upper left)
static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string)
{
    y = y - fonty/2;
    x = x - (strlen(string)/2)*fontx;
    if(strlen(string)%2)
        x = x - fontx/2;
    UG_PutString(x,y,string);
}


// Display the splash screen
static void displaySplashScreen()
{
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5,22,36,"Cypress");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*2,22,36,"Mouser");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*3,22,36,"PSoC 6");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*4,22,36,"WICED 4343");

    wiced_rtos_delay_milliseconds(2000);
}

// This function displays the start button message
static void displayStartButton()
{
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutStringCenter(SCREEN_X/2 , SCREEN_Y - 30 ,12,22,  "Press B0 To Start");
}


// Display the Start Screen
static void  displayStartScreen()
{
    UG_FillScreen( C_BLACK );
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 -2 - 18 ,22,36,"Ready");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 + 2 + 18 ,22,36,"Player 1");
    displayStartButton();
}

// Main game thread
void gameThread(wiced_thread_arg_t arg)
{

    Cy_TFT_Init();                                             // Init the TFT
    UG_Init( &amp;gui, Cy_TFT_displayDriver, SCREEN_X, SCREEN_Y ); // Connect the driver

    UG_FillScreen( C_BLACK );   // Clear the screen
    UG_SetBackcolor( C_BLACK );
    UG_SetForecolor( C_WHITE );

    displaySplashScreen();
    displayStartScreen();

    while(1)
    {
        wiced_rtos_delay_milliseconds(1000);
    }
}
</pre>
<p>The main game thread function is: void gameThread(wiced_thread_arg_t arg).  This function</p>
<ol>
<li>Initializes the TFT</li>
<li>Initializes the UGUI library</li>
<li>Clears the screen (by setting it all black)</li>
<li>Sets the colors to draw white on black</li>
<li>Displays the splash screen (which takes 2 seconds)</li>
<li>Displays the start screen</li>
<li>Waits until the end of time</li>
</ol>
<pre class="start-line:53 EnlighterJSRAW" data-enlighter-language="c"">// Main game thread
void gameThread(wiced_thread_arg_t arg)
{

    Cy_TFT_Init();                                             // Init the TFT
    UG_Init( &amp;gui, Cy_TFT_displayDriver, SCREEN_X, SCREEN_Y ); // Connect the driver

    UG_FillScreen( C_BLACK );   // Clear the screen
    UG_SetBackcolor( C_BLACK );
    UG_SetForecolor( C_WHITE );

    displaySplashScreen();
    displayStartScreen();

    while(1)
    {
        wiced_rtos_delay_milliseconds(1000);
    }
}
</pre>
<p>The function displaySplashScreen simply sets the font, then draws 4 text strings, then waits for a few seconds&#8230; then moves on</p>
<pre class="start-line:23 EnlighterJSRAW" data-enlighter-language="c" ">// Display the splash screen
static void displaySplashScreen()
{
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5,22,36,"Cypress");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*2,22,36,"Mouser");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*3,22,36,"PSoC 6");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/5*4,22,36,"WICED 4343");

    wiced_rtos_delay_milliseconds(2000);
}</pre>
<p>The displayStartScreen put the &#8220;Ready Player 1 on the screen&#8221; and then tells the user to press the B0 to start the game.</p>
<pre class="start-line:35 EnlighterJSRAW" data-enlighter-language="c"">// This function displays the start button message
static void displayStartButton()
{
    UG_FontSelect(&amp;FONT_12X20);
    UG_PutStringCenter(SCREEN_X/2 , SCREEN_Y - 30 ,12,22,  "Press B0 To Start");
}


// Display the Start Screen
static void  displayStartScreen()
{
    UG_FillScreen( C_BLACK );
    UG_FontSelect( &amp;FONT_22X36 );
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 -2 - 18 ,22,36,"Ready");
    UG_PutStringCenter(SCREEN_X/2,SCREEN_Y/2 + 2 + 18 ,22,36,"Player 1");
    displayStartButton();
}
</pre>
<p>The U8G_PutString function uses coordinates x and y to set the upper left of the text.  For formatting purposes it is easier for me to think about the middle of the string.  This function just calculates the upper left (x,y) given the middle center (x,y).  To do this you need to also know the (x,y) size of the font.</p>
<p>static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string)</p>
<pre class="start-line:11 EnlighterJSRAW" data-enlighter-language="c"">// ARH Function to put text in the center of a point (UG_PutString does upper left)
static void UG_PutStringCenter(uint32_t x, uint32_t y, uint32_t fontx, uint32_t fonty,char *string)
{
    y = y - fonty/2;
    x = x - (strlen(string)/2)*fontx;
    if(strlen(string)%2)
        x = x - fontx/2;
    UG_PutString(x,y,string);
}</pre>
<h1>Rename L2CapSense.mk to be L3CapSenseTft.mk &amp; Fix</h1>
<p>To make this build we need to modify the makefile to know about the new thread as well as the tft driver.  In addition we need to tell the linker to link with the graphics library.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">NAME := App_WStudio_L3CapSenseTft

$(NAME)_SOURCES := 	main.c \
				CapSenseThread.c \
				GameThread.c \
				cy_tft_display.c
				
				

$(NAME)_COMPONENTS := graphics/ugui
</pre>
<h1>Update main.c</h1>
<p>In main.c I will:</p>
<ol>
<li>Include the GameThread.h</li>
<li>Add a variable to hold the gameThreadHandle</li>
<li>Then start the gameThread</li>
</ol>
<pre class="EnlighterJSRAW" data-enlighter-language="c">#include "wiced.h"
#include "CapSenseThread.h"
#include "GameThread.h"

/******************************************************
 *                      Macros
 ******************************************************/

/******************************************************
 *                    Constants
 ******************************************************/

/******************************************************
 *                   Enumerations
 ******************************************************/

/******************************************************
 *                 Type Definitions
 ******************************************************/

/******************************************************
 *                    Structures
 ******************************************************/


/******************************************************
 *               Static Function Declarations
 ******************************************************/


/******************************************************
 *               Variable Definitions
 ******************************************************/

wiced_thread_t blinkThreadHandle;
wiced_thread_t capSenseThreadHandle;
wiced_thread_t gameThreadHandle;



/******************************************************
 *               Function Definitions
 ******************************************************/
void pdlBlinkThread(wiced_thread_arg_t arg)
{
     while(1)
     {
         Cy_GPIO_Inv(GPIO_PRT0,3);
         wiced_rtos_delay_milliseconds(500);
     }
}

void application_start( )
{
    wiced_init();
    WPRINT_APP_INFO(("Started Application\n"));
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
    wiced_rtos_create_thread(&amp;capSenseThreadHandle,7,"CapSense Thread",capSenseThread,1024,0);
    wiced_rtos_create_thread(&amp;gameThreadHandle,7,"game Thread",gameThread,4096,0);


}
</pre>
<h1>Test</h1>
<p>Now it is ready to test.  So create a Make Target, then Build and Program.  Hopefully you are now Ready Player 1.</p>
<p><a href="https://iotexpert.com/?attachment_id=6073" rel="attachment wp-att-6073"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-5.07.20-AM.png" alt="" width="940" height="744" class="alignnone size-full wp-image-6073" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-5.07.20-AM.png 940w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-5.07.20-AM-600x475.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-5.07.20-AM-300x237.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-23-at-5.07.20-AM-768x608.png 768w" sizes="auto, (max-width: 940px) 100vw, 940px" /></a></p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-vtw-lesson-3-using-the-tft/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC 6-WiFi-BT L2 : WICED Studio &#038; CapSense</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:02:13 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6027</guid>

					<description><![CDATA[Summary In this lesson we will build your first WICED Studio project (the blinking LED)  and make sure that you can program the development kit.  Then we will update the project to include a thread for managing the CapSense block.  This thread will be carried into the other projects. To implement this lesson I will [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>In this lesson we will build your first WICED Studio project (the blinking LED)  and make sure that you can program the development kit.  Then we will update the project to include a thread for managing the CapSense block.  This thread will be carried into the other projects.</p>
<p>To implement this lesson I will follow these steps:</p>
<ol>
<li>Start WICED Studio 6.2</li>
<li>Select 43xxx</li>
<li>Create a folder called L2CapSense</li>
<li>Create main.c and build a blinking LED thread</li>
<li>Create L2CapSense.mk</li>
<li>Create a make target</li>
<li>Build Program and test it</li>
<li>Create CapSenseThread.c</li>
<li>Create CapSenseThread.h</li>
<li>Update main.c</li>
<li>Update the makefile</li>
<li>Build Program and Test</li>
</ol>
<h1>Create the L2CapSense Folder</h1>
<p><a href="https://iotexpert.com/?attachment_id=6053" rel="attachment wp-att-6053"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM-914x1024.png" alt="" width="914" height="1024" class="alignnone size-large wp-image-6053" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM-914x1024.png 914w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM-600x673.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM-268x300.png 268w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM-768x861.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.30.19-AM.png 1042w" sizes="auto, (max-width: 914px) 100vw, 914px" /></a></p>
<h1>Create main.c</h1>
<p>Right click on the folder and create a new file.  Name it L2CapSense</p>
<p><a href="https://iotexpert.com/?attachment_id=6052" rel="attachment wp-att-6052"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM-925x1024.png" alt="" width="925" height="1024" class="alignnone size-large wp-image-6052" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM-925x1024.png 925w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM-600x664.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM-271x300.png 271w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM-768x850.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.32.04-AM.png 1048w" sizes="auto, (max-width: 925px) 100vw, 925px" /></a></p>
<p>Insert the blinking LED code into main.c</p>
<pre class="lang:c decode:true">#include "wiced.h"

/******************************************************
 *                      Macros
 ******************************************************/

/******************************************************
 *                    Constants
 ******************************************************/

/******************************************************
 *                   Enumerations
 ******************************************************/

/******************************************************
 *                 Type Definitions
 ******************************************************/

/******************************************************
 *                    Structures
 ******************************************************/


/******************************************************
 *               Static Function Declarations
 ******************************************************/


/******************************************************
 *               Variable Definitions
 ******************************************************/

wiced_thread_t blinkThreadHandle;

/******************************************************
 *               Function Definitions
 ******************************************************/
void pdlBlinkThread(wiced_thread_arg_t arg)
{
     while(1)
     {
         Cy_GPIO_Inv(GPIO_PRT0,3);
         wiced_rtos_delay_milliseconds(500);
     }
}

void application_start( )
{
    WPRINT_APP_INFO(("Started Application\n"));
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
}</pre>
<h1>Create L2CapSense.mk</h1>
<p>Create a makefile called L2CapSense.mk</p>
<p><a href="https://iotexpert.com/?attachment_id=6050" rel="attachment wp-att-6050"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM-922x1024.png" alt="" width="922" height="1024" class="alignnone size-large wp-image-6050" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM-922x1024.png 922w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM-600x667.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM-270x300.png 270w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM-768x853.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.33.04-AM.png 1046w" sizes="auto, (max-width: 922px) 100vw, 922px" /></a></p>
<p>Put the build information into the L2CapSense.mk</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">NAME := App_WStudio_L2CapSense

$(NAME)_SOURCES := 	main.c
</pre>
<h1>Create a Make Target to run the project</h1>
<p><a href="https://iotexpert.com/?attachment_id=6049" rel="attachment wp-att-6049"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.36.10-AM.png" alt="" width="880" height="768" class="alignnone size-full wp-image-6049" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.36.10-AM.png 880w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.36.10-AM-600x524.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.36.10-AM-300x262.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.36.10-AM-768x670.png 768w" sizes="auto, (max-width: 880px) 100vw, 880px" /></a></p>
<h1>Build and Test the Blinking LED</h1>
<p><a href="https://iotexpert.com/?attachment_id=6057" rel="attachment wp-att-6057"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM-1024x513.png" alt="" width="1024" height="513" class="alignnone size-large wp-image-6057" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM-1024x513.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM-600x301.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM-300x150.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM-768x385.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.16.09-PM.png 1548w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Create/Edit a File called CapSenseThread.c</h1>
<pre class="lang:c decode:true">#include "wiced.h"

void capSenseThread(wiced_thread_arg_t arg)
{

    CapSense_Start();
    CapSense_ScanAllWidgets();
    while(1)
    {
        if(!CapSense_IsBusy())
        {

            CapSense_ProcessAllWidgets();
            if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
            {
                WPRINT_APP_INFO(("Button 0 Active\n"));
            }

            if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
            {
                WPRINT_APP_INFO(("Button 1 Active\n"));
            }

            uint32_t val = CapSense_GetCentroidPos(CapSense_LINEARSLIDER0_WDGT_ID);
            if(val &lt; 0xFFFF)
            {
                WPRINT_APP_INFO(("Slider = %d\n",(int)val));

            }
            CapSense_ScanAllWidgets();
        }
        wiced_rtos_delay_milliseconds(25); // Poll every 25ms (actual scan time ~8ms)
    }
}
</pre>
<h1>Create/Edit a File Called CapSenseThread.h</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">#pragma once
#include "wiced.h"
void capSenseThread(wiced_thread_arg_t arg);
</pre>
<h1>Update main.c</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">#include "wiced.h"
#include "CapSenseThread.h"
</pre>
<p>Add a variable to hold the handle for the capSenseThread at the top of main.c</p>
<pre class="start-line:35 EnlighterJSRAW" data-enlighter-language="c" ">wiced_thread_t capSenseThreadHandle;
</pre>
<p>Update the main function to start the CapSenseThread</p>
<pre class="start-line:49 EnlighterJSRAW" data-enlighter-language="c"">void application_start( )
{
    WPRINT_APP_INFO(("Started Application\n"));
    wiced_rtos_create_thread(&amp;blinkThreadHandle,7,"Blink Thread",pdlBlinkThread,500,0);
    wiced_rtos_create_thread(&amp;capSenseThreadHandle,7,"CapSense Thread",capSenseThread,1024,0);

}
</pre>
<h1>Update the L2CapsenseThread.mk</h1>
<pre class="EnlighterJSRAW" data-enlighter-language="c" ">NAME := App_WStudio_L2CapSense

$(NAME)_SOURCES := 	main.c \
				CapSenseThread.c
				
</pre>
<h1>Build, Program and Test the CapSenseThread</h1>
<p><a href="https://iotexpert.com/?attachment_id=6058" rel="attachment wp-att-6058"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM-1024x500.png" alt="" width="1024" height="500" class="alignnone size-large wp-image-6058" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM-1024x500.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM-600x293.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM-300x147.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM-768x375.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-1.33.22-PM.png 1556w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC 6-WiFi-BT L1 : Developer Resources</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l1-developers-resources/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l1-developers-resources/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 24 Oct 2018 09:01:32 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WIFI]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=6021</guid>

					<description><![CDATA[Summary This is an index of links to all of the PSoC 6 &#38; CYW4343W learning resources.  You can click the links to go the website or see screen captures of the resources. PSoC 6 Product Page WiFi + Bluetooth Combo Product Page PSoC 6 Documentation PSoC 6 Community Wireless Combo Community CY8CKIT-062-BT-WiFi Development Kit [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<h1>Summary</h1>
<p>This is an index of links to all of the PSoC 6 &amp; CYW4343W learning resources.  You can click the links to go the website or see screen captures of the resources.</p>
<ol>
<li><a href="http://www.cypress.com/products/32-bit-arm-cortex-m4-psoc-6" target="_blank" rel="noopener">PSoC 6 Product Page</a></li>
<li><a href="http://www.cypress.com/products/wi-fi-bluetooth-combos" target="_blank" rel="noopener">WiFi + Bluetooth Combo Product Page</a></li>
<li><a href="http://www.cypress.com/products/32-bit-arm-cortex-m4-psoc-6#tabs-0-bottom_side-5" target="_blank" rel="noopener">PSoC 6 Documentation</a></li>
<li><a href="https://community.cypress.com/community/psoc-6" target="_blank" rel="noopener">PSoC 6 Community</a></li>
<li><a href="https://community.cypress.com/community/wiced-wifi" target="_blank" rel="noopener">Wireless Combo Community</a></li>
<li><a href="http://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit" target="_blank" rel="noopener">CY8CKIT-062-BT-WiFi Development Kit Product Page</a></li>
<li><a href="http://www.cypress.com/file/407731/download" target="_blank" rel="noopener">CY8CKIT-062-BT-WiFi Development Kit Guide</a></li>
<li><a href="http://www.cypress.com/file/385916/download" target="_blank" rel="noopener">PSoC 6 Datasheet</a></li>
<li><a href="http://www.cypress.com/file/298081/download" target="_blank" rel="noopener">CYW4343W Datasheet</a></li>
<li><a href="http://www.cypress.com/file/385621/download" target="_blank" rel="noopener">PSoC 6 Technical Reference Manuals</a></li>
<li><a href="http://www.cypress.com/search/all?f[0]=meta_type%3Atechnical_documents&amp;f[1]=resource_meta_type%3A574&amp;f[2]=field_related_products%3A114026" target="_blank" rel="noopener">PSoC 6 Application Notes</a></li>
<li><a href="http://www.cypress.com/search/all?sort_by=changed&amp;f%5B0%5D=meta_type%3Atechnical_documents&amp;f%5B1%5D=field_related_products%3A121332&amp;f%5B2%5D=resource_meta_type%3A574" target="_blank" rel="noopener">WiFi + Bluetooth Combo Application Notes</a></li>
<li><a href="http://www.cypress.com/documentation/code-examples/psoc-6-mcu-code-examples" target="_blank" rel="noopener">PSoC 6 Code Examples</a></li>
<li><a href="http://www.cypress.com/training/free-online-video-training-and-tutorials-cypress" target="_blank" rel="noopener">Video Tutorials</a></li>
<li><a href="https://community.cypress.com/community/knowledge-base-articles/content?filterID=contentstatus%5Bpublished%5D~category%5Bpsoc-6%5D" target="_blank" rel="noopener">PSoC 6 Knowledge Base</a></li>
<li>Peripheral Driver Library Documentation (Doxygen)</li>
<li>WICED Documentation</li>
</ol>
<h1>PSoC 6 Product Page</h1>
<p>You can find the PSoC 6 Product landing page for PSoC 6 <a href="http://www.cypress.com/products/32-bit-arm-cortex-m4-psoc-6" target="_blank" rel="noopener">here</a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM-1024x870.png" alt="" width="1024" height="870" class="alignnone size-large wp-image-4499" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM-1024x870.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM-600x510.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM-300x255.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM-768x652.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.57.54-PM.png 1280w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>WiFi + Bluetooth Combo Page</h1>
<p><a href="https://iotexpert.com/?attachment_id=6037" rel="attachment wp-att-6037"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.51.59-AM-1024x783.png" alt="" width="1024" height="783" class="alignnone size-large wp-image-6037" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.51.59-AM-1024x783.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.51.59-AM-600x459.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.51.59-AM-300x229.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.51.59-AM-768x587.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>PSoC 6 Documentation</h1>
<p>On the PSoC 6 Product Landing page there is a documentation tab that has links to all of the current documentation.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM-806x1024.png" alt="" width="806" height="1024" class="alignnone size-large wp-image-4502" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM-806x1024.png 806w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM-600x762.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM-236x300.png 236w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM-768x975.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.16.16-PM.png 834w" sizes="auto, (max-width: 806px) 100vw, 806px" /></a></p>
<h1>PSoC 6 Community</h1>
<p>Cypress has an active development community and forum.  It can be found <a href="https://community.cypress.com/community/psoc-6" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM-1024x876.png" alt="" width="1024" height="876" class="alignnone size-large wp-image-4495" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM-1024x876.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM-600x514.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM-300x257.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM-768x657.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-2.40.56-PM.png 1478w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Wireless WiFi + Bluetooth Combo Community</h1>
<p><a href="https://iotexpert.com/?attachment_id=6038" rel="attachment wp-att-6038"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.54.42-AM-1024x585.png" alt="" width="1024" height="585" class="alignnone size-large wp-image-6038" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.54.42-AM-1024x585.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.54.42-AM-600x343.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.54.42-AM-300x171.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.54.42-AM-768x438.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>CY8CKIT-062-WiFi-BT Development Kit Web Page</h1>
<p>Every Cypress development kit has a web page that contains all of the information about it, including links to the documentation and store.  The CY8CKIT-062-WiFi-BT kit page is <a href="http://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6039" rel="attachment wp-att-6039"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.56.36-AM-1024x694.png" alt="" width="1024" height="694" class="alignnone size-large wp-image-6039" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.56.36-AM-1024x694.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.56.36-AM-600x407.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.56.36-AM-300x203.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.56.36-AM-768x520.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>CY8CKIT-062-WiFi-BT Development Kit Guide</h1>
<p>You can find the development kit guide <a href="http://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6040" rel="attachment wp-att-6040"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.58.01-AM-1024x440.png" alt="" width="1024" height="440" class="alignnone size-large wp-image-6040" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.58.01-AM-1024x440.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.58.01-AM-600x258.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.58.01-AM-300x129.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-5.58.01-AM-768x330.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<h1>PSoC 6 Datasheet</h1>
<p>The PSoC 6 Datasheet is available on Cypress.com <a href="http://www.cypress.com/file/385916/download" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6041" rel="attachment wp-att-6041"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.00.20-AM-1024x749.png" alt="" width="1024" height="749" class="alignnone size-large wp-image-6041" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.00.20-AM-1024x749.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.00.20-AM-600x439.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.00.20-AM-300x219.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.00.20-AM-768x562.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<h1>CYW4343W Datasheet</h1>
<p>The CYW4343W datasheet can be found <a href="http://www.cypress.com/file/298081/download" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/?attachment_id=6042" rel="attachment wp-att-6042"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM-1024x662.png" alt="" width="1024" height="662" class="alignnone size-large wp-image-6042" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM-1024x662.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM-600x388.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM-300x194.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM-768x497.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-6.02.12-AM.png 1994w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>PSoC 6 Technical Reference Manual</h1>
<p>Each of the PSoC 6 devices has a lengthy discussion of the Technical Resources.  These documents can be found <a href="http://www.cypress.com/file/385621/download" target="_blank" rel="noopener">here</a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM-1024x997.png" alt="" width="1024" height="997" class="alignnone size-large wp-image-4501" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM-1024x997.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM-600x584.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM-300x292.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM-768x748.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.12.57-PM.png 1105w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>PSoC 6 Application Notes</h1>
<p>You can get them all on our website&#8230; here is a link to the filtered list of <a href="http://www.cypress.com/search/all?f[0]=meta_type%3Atechnical_documents&amp;f[1]=resource_meta_type%3A574&amp;f[2]=field_related_products%3A114026" target="_blank" rel="noopener">PSoC 6 Application Notes</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM-1024x917.png" alt="" width="1024" height="917" class="alignnone size-large wp-image-4459" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM-1024x917.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM-600x537.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM-300x269.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM-768x687.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.06.05-PM.png 1363w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The best application note is always the &#8220;Getting Started&#8221;.  In this case it is <a href="http://www.cypress.com/documentation/application-notes/an210781-getting-started-psoc-6-mcu-bluetooth-low-energy-ble?source=search&amp;cat=technical_documents" target="_blank" rel="noopener">AN210781 &#8220;Getting Started with PSoC 6 MCU with Bluetooth Low Energy (BLE) Connectivity&#8221;</a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM-1024x940.png" alt="" width="1024" height="940" class="alignnone size-large wp-image-4460" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM-1024x940.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM-600x551.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM-300x276.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM-768x705.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-12.08.11-PM.png 1421w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>WiFi + Bluetooth Combo Application Notes</h1>
<p>Here is a link to all of the <a href="http://www.cypress.com/search/all?sort_by=changed&amp;f%5B0%5D=meta_type%3Atechnical_documents&amp;f%5B1%5D=field_related_products%3A121332&amp;f%5B2%5D=resource_meta_type%3A574" target="_blank" rel="noopener">WiFI Bluetooth Combo Application</a> Notes.</p>
<p><a href="https://iotexpert.com/?attachment_id=6045" rel="attachment wp-att-6045"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.20.58-AM-1024x784.png" alt="" width="1024" height="784" class="alignnone size-large wp-image-6045" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.20.58-AM-1024x784.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.20.58-AM-600x460.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.20.58-AM-300x230.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.20.58-AM-768x588.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>PSoC 6 Code Examples</h1>
<p>You can find all of the PSoC 6 code examples on the <a href="http://www.cypress.com/documentation/code-examples/psoc-6-mcu-code-examples" target="_blank" rel="noopener">web</a>.  In addition they are built into PSoC Creator.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM-1024x770.png" alt="" width="1024" height="770" class="alignnone size-large wp-image-4500" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM-1024x770.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM-600x451.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM-300x226.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM-768x577.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.01.49-PM.png 1342w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Or in PSoC Creator:</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM.png" alt="" width="310" height="310" class="alignnone size-large wp-image-4455" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM.png 310w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM-300x300.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM-100x100.png 100w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.26-AM-150x150.png 150w" sizes="auto, (max-width: 310px) 100vw, 310px" /></a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.45-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.45-AM.png" alt="" width="626" height="476" class="alignnone size-large wp-image-4454" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.45-AM.png 626w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.45-AM-600x456.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.55.45-AM-300x228.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.56.02-AM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.56.02-AM.png" alt="" width="626" height="477" class="alignnone size-full wp-image-4453" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.56.02-AM.png 626w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.56.02-AM-600x457.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-11.56.02-AM-300x229.png 300w" sizes="auto, (max-width: 626px) 100vw, 626px" /></a></p>
<h1>Videos</h1>
<p>Cypress has made a bunch of videos that take you step by step through an introduction to PSoC 6.  You can find them on the Cypress t<a href="http://www.cypress.com/training/psoc-101-video-tutorial-series-how-use-arm-cortex-m4-based-psoc-6" target="_blank" rel="noopener">raining website.</a></p>
<p><a href="https://iotexpert.com/?attachment_id=6046" rel="attachment wp-att-6046"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.24.27-AM-1024x735.png" alt="" width="1024" height="735" class="alignnone size-large wp-image-6046" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.24.27-AM-1024x735.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.24.27-AM-600x431.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.24.27-AM-300x215.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-22-at-9.24.27-AM-768x551.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>PSoC 6 Knowledge Base</h1>
<p>The Cypress technical support team writes &#8220;Knowledge Base&#8221; articles when there are repeated issues reported by customers.  You can find them <a href="https://community.cypress.com/community/knowledge-base-articles/content?filterID=contentstatus%5Bpublished%5D~category%5Bpsoc-6%5D" target="_blank" rel="noopener">here</a>.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM-1024x819.png" alt="" width="1024" height="819" class="alignnone size-large wp-image-4505" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM-1024x819.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM-600x480.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM-300x240.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM-768x614.png 768w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-03-at-3.50.02-PM.png 1252w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-3.52.32-PM.png"></a></p>
<h1>Peripheral Driver Library Documentation (Doxygen)</h1>
<p>All of the APIs in the PDL are documented in a Doxygen generated HTML document.  You can get there from</p>
<ul>
<li>Help -&gt; Peripheral Driver Library (this link is live only when you have a PSoC 6 project open)</li>
<li>Right click on a component -&gt; Open PDL Documentation</li>
</ul>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM-1024x580.png" alt="" width="1024" height="580" class="alignnone size-large wp-image-4619" srcset="https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM-1024x580.png 1024w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM-600x340.png 600w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM-300x170.png 300w, https://iotexpert.com/wp-content/uploads/2017/11/Screen-Shot-2017-11-06-at-4.01.06-PM-768x435.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l1-developers-resources/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser PSoC 6-WiFi-BT L0 : Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</title>
		<link>https://iotexpert.com/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/</link>
					<comments>https://iotexpert.com/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Tue, 23 Oct 2018 17:05:09 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[WICED]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5983</guid>

					<description><![CDATA[Summary Hello everyone.  This is lesson 0 of a series of 9 lessons about creating applications for the Cypress CY8CKIT-062-WiFi-BLE development kit.  The marketing guys call the class &#8220;Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth&#8221; &#8230; which although a really long name, is a good description of what we are [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>Hello everyone.  This is lesson 0 of a series of 9 lessons about creating applications for the Cypress CY8CKIT-062-WiFi-BLE development kit.  The marketing guys call the class &#8220;Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth&#8221; &#8230; which although a really long name, is a good description of what we are going to do.</p>
<p>What I will do today is take you lesson by lesson through the class and talk about how it all works and what you need to do.  When I built the class it was absolutely my goal to have every button click and line of code described.  That being said,  it is likely that I made some errors.  So, during the class you will be able to send messages to my team who will answer the questions, or ask me and Ill answer live.  If you missed the class, that&#8217;s OK, you will be able to watch it on replay.  In addition if you have a question after the live stream is over, leave a comment here and Ill answer.</p>
<p>I will attempt to go slowly enough for you to follow along, but if I go to fast, don&#8217;t worry you should be able to follow along with the instructions on this website.</p>
<p>Todays virtual workshop is going to go like this.  Every lesson will have this table in it and you will be able to click to the right place.</p>
<p><span><h1>Designing low-power, cloud-connected IoT devices with PSoC® 6 MCU’s and WICED® Wi-Fi/Bluetooth</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Lesson</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/">Introduction</a></td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l1-developers-resources/">Developer Resources</a></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l2-wiced-studio-capsense/">WICED Studio &amp; CapSense</a></td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-3-using-the-tft/">Using the CY8CKIT-028-TFT Shield</a></td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l4-the-video-game/">The Video Game</a></td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l5-goble-ble-remote-control-for-the-game/">GoBle &amp; Bluetooth</a></td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l6-integrate-goble-bluetooth-into-the-game/">Integrate GoBle Bluetooth into the Game</a></td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-psoc6-wifi-bt-l7-implement-wifi-and-aws/">Implement WiFi and AWS</a></td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/10/24/mouser-vtw-lesson-8-integrate-wifi-and-aws-into-the-game/">Integrate WiFi and AWS Into the Game</a></td>
</tr>
</tbody></table></div></p></span></p>
<p>You will need a few things for this class:</p>
<ul>
<li>CY8CKIT-062-WiFi-BT</li>
<li>WICED Studio 6.2</li>
<li>CySmart or LightBlue a BLE</li>
<li>GoBle an iOS Remote Control App</li>
<li>An Amazon AWS IoT Account</li>
<li>A WiFi Access Point connected to the Internet</li>
</ul>
<h1>CY8CKIT-062-WiFi-BT</h1>
<p>All of the projects in this series of lesson will be built to be programmed onto a CY8CKIT-062-WiFi-BT.  You can get the development kit from <a href="https://www.mouser.com/ProductDetail/Cypress-Semiconductor/CY8CKIT-062-WIFI-BT?qs=lYGu3FyN48c6Xy1GM0bmkg%3D%3D" target="_blank" rel="noopener">Mouser</a>.  This development kit has a bunch of cool stuff including</p>
<ul>
<li>PSoC 6 &#8211; The lowest power, most secure MCU for the IoT</li>
<li>CYW4343W &#8211; A WICED WiFi Bluetooth Combo Radio</li>
<li>S25FL512SAGMFI011 &#8211; A Cypress 512Mb Quad SPI Flash</li>
<li>CCG2 &#8211; A Cypress Type C Controller to manage Power</li>
</ul>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/img_6357-2/" rel="attachment wp-att-5988"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6357-2-1024x564.jpg" alt="" width="1024" height="564" class="alignnone size-large wp-image-5988" srcset="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6357-2-1024x564.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6357-2-600x331.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6357-2-300x165.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6357-2-768x423.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>The CY8CKIT-028-TFT a full color 320&#215;240 TFT display with an ST7789S display controller.<a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/img_6358-2/" rel="attachment wp-att-5989"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6358-2-984x1024.jpg" alt="" width="984" height="1024" class="alignnone size-large wp-image-5989" srcset="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6358-2-984x1024.jpg 984w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6358-2-600x625.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6358-2-288x300.jpg 288w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6358-2-768x800.jpg 768w" sizes="auto, (max-width: 984px) 100vw, 984px" /></a></p>
<p>Here is the whole thing together</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/img_6361/" rel="attachment wp-att-5991"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6361-1024x531.jpg" alt="" width="1024" height="531" class="alignnone size-large wp-image-5991" srcset="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6361-1024x531.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6361-600x311.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6361-300x155.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6361-768x398.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>WICED Studio 6.2</h1>
<p>This class is build around WICED Studio 6.2, the Cypress IDE built on top of Eclipse.  WICED Studio has all of the tools, examples and SDKs to build projects for the Cypress WICED Bluetooth and WiFi products.  We support Windows, Mac and Linux and you can download it from our community website: <a href="https://community.cypress.com/community/wireless" target="_blank" rel="noopener">https://community.cypress.com/community/wireless</a> (which I hope you have done by now)</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-9-42-30-am/" rel="attachment wp-att-5987"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-9.42.30-AM-1024x624.png" alt="" width="1024" height="624" class="alignnone size-large wp-image-5987" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-9.42.30-AM-1024x624.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-9.42.30-AM-600x365.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-9.42.30-AM-300x183.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-9.42.30-AM-768x468.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>CySmart or LightBlue a BLE</h1>
<p>CySmart is a BLE GATT Browser which you can get from the<a href="https://itunes.apple.com/us/app/cysmart/id928939093?mt=8" target="_blank" rel="noopener"> iOS App store</a> or the <a href="https://play.google.com/store/apps/details?id=com.cypress.cysmart&amp;hl=en_US" target="_blank" rel="noopener">Google Play store</a></p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-10-29-35-am/" rel="attachment wp-att-5995"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM-1024x894.png" alt="" width="1024" height="894" class="alignnone size-large wp-image-5995" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM-1024x894.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM-600x524.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM-300x262.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM-768x671.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.29.35-AM.png 1830w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-10-30-16-am/" rel="attachment wp-att-5994"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM-965x1024.png" alt="" width="965" height="1024" class="alignnone size-large wp-image-5994" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM-965x1024.png 965w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM-600x637.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM-283x300.png 283w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM-768x815.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.30.16-AM.png 1524w" sizes="auto, (max-width: 965px) 100vw, 965px" /></a></p>
<p>&nbsp;</p>
<h1>GoBle an iOS Remote Control App</h1>
<p>GoBle is a Robot Remote Control App which can be downloaded from the <a href="https://itunes.apple.com/us/app/goble-bluetooth-4-0-controller/id950937437?mt=8" target="_blank" rel="noopener">iOS App Store</a>.</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-10-28-30-am/" rel="attachment wp-att-5993"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.28.30-AM-1024x800.png" alt="" width="1024" height="800" class="alignnone size-large wp-image-5993" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.28.30-AM-1024x800.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.28.30-AM-600x469.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.28.30-AM-300x234.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-10.28.30-AM-768x600.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>An Amazon AWS IoT Account</h1>
<p>In order to connect Amazon AWS IoT you will need to create an <a href="https://console.aws.amazon.com" target="_blank" rel="noopener">Amazon AWS Account</a>.  It is essentially free to test you simple applications (obviously there are fees if you deploy many devices)</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-11-21-16-am/" rel="attachment wp-att-6001"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM-1024x849.png" alt="" width="1024" height="849" class="alignnone size-large wp-image-6001" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM-1024x849.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM-600x497.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM-300x249.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM-768x637.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.21.16-AM.png 1930w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/2018/10/23/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/screen-shot-2018-10-21-at-11-23-27-am/" rel="attachment wp-att-6000"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.23.27-AM-1024x581.png" alt="" width="1024" height="581" class="alignnone size-large wp-image-6000" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.23.27-AM-1024x581.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.23.27-AM-600x340.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.23.27-AM-300x170.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-21-at-11.23.27-AM-768x436.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-psoc6-wifi-bt-l0-designing-low-power-cloud-connected-iot-devices-with-psoc-6-mcus-and-wiced-wi-fi-bluetooth/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Mouser Video Training Workshop &#8211; October 24</title>
		<link>https://iotexpert.com/mouser-video-training-workshop-october-24/</link>
					<comments>https://iotexpert.com/mouser-video-training-workshop-october-24/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Fri, 19 Oct 2018 15:14:10 +0000</pubDate>
				<category><![CDATA[4343W]]></category>
		<category><![CDATA[CY8CKIT-062-WiFi-BT]]></category>
		<category><![CDATA[Mouser 10-24-18 PSoC 6 & 4343W WiFi/BLE]]></category>
		<category><![CDATA[PSoC 6]]></category>
		<category><![CDATA[PSoC Creator]]></category>
		<category><![CDATA[WICED]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5895</guid>

					<description><![CDATA[On October 24, I will be teaching a Mouser video training workshop &#8230; live streaming on the internet.  The workshop will be about PSoC, WICED, WiFi and Bluetooth.  I am going to show PSoC Creator, WICED Studio and Cypress&#8217;s new development tool Modus Toolbox. You can register for the workshop at this link. I am [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>On October 24, I will be teaching a <a href="http://mouser.com" target="_blank" rel="noopener">Mouser</a> video training workshop &#8230; live streaming on the internet.  The workshop will be about PSoC, WICED, WiFi and Bluetooth.  I am going to show PSoC Creator, WICED Studio and Cypress&#8217;s new development tool Modus Toolbox.</p>
<p>You can register for the workshop at this <a href="https://www.electronicdesign.com/webcasts/designing-low-power-cloud-connected-iot-devices-psoc-6-mcu-s-and-wiced-wi-fibluetooth?partnerref=Mouser" target="_blank" rel="noopener">link</a>.</p>
<p>I am going to build the whole class around the <a href="http://www.cypress.com/documentation/development-kitsboards/psoc-6-wifi-bt-pioneer-kit" target="_blank" rel="noopener">CY8CKIT-062-BLE-WiFi</a> Development Kit.  You can get the devlopment kit from <a href="https://www.mouser.com/ProductDetail/Cypress-Semiconductor/CY8CKIT-062-WIFI-BT?qs=lYGu3FyN48c6Xy1GM0bmkg%3D%3D" target="_blank" rel="noopener">Mouser</a>.</p>
<p><a href="https://iotexpert.com/2018/10/19/mouser-video-training-workshop-october-24/img_6353/" rel="attachment wp-att-5899"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6353-e1539961924645-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-5899 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/10/IMG_6353-e1539961924645-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6353-e1539961924645-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6353-e1539961924645-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/10/IMG_6353-e1539961924645-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Here is the introduction:</p>
<div class="jupiterx-oembed"><iframe loading="lazy" title="Mouser Video Workshop PSoC" width="500" height="281" src="https://www.youtube.com/embed/30NgWBwbu5w?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/mouser-video-training-workshop-october-24/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WICED 20719 BLE Central Custom Profile w/LED &#038; CapSense &#8211; Part 2</title>
		<link>https://iotexpert.com/wiced-20719-ble-central-custom-profile-w-led-capsense-part-2/</link>
					<comments>https://iotexpert.com/wiced-20719-ble-central-custom-profile-w-led-capsense-part-2/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Wed, 10 Oct 2018 12:25:43 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5871</guid>

					<description><![CDATA[Summary In the previous article I showed you how to create a BLE Central that could attach to a BLE peripheral that is advertising a custom service.  Then, I showed you how to write values to the LED Characteristic in the Peripheral GATT Server.  In this article Ill show you how to set the CCCD [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the <a href="https://iotexpert.com/2018/10/08/wiced-20719-ble-central-custom-profile-w-led-capsense-part-1/">previous article</a> I showed you how to create a BLE Central that could attach to a BLE peripheral that is advertising a custom service.  Then, I showed you how to write values to the LED Characteristic in the Peripheral GATT Server.  In this article Ill show you how to set the CCCD and what happens when the Peripheral notifies.</p>
<p>The steps to build this project will be as follows</p>
<ol>
<li>Create a new project with copy/paste</li>
<li>Write the CCCD</li>
<li>Handle the new GATT Events</li>
</ol>
<h1>Create a new project by copy/paste</h1>
<p>I wanted to have three different projects for each of the steps in this series of articles.  To create the 2nd example (the subject of this article) Ill just do a copy/paste and then fix a few things.  Start with the copy.</p>
<p><a href="https://iotexpert.com/?attachment_id=5876" rel="attachment wp-att-5876"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.12-AM.png" alt="" width="514" height="455" class="alignnone size-large wp-image-5876" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.12-AM.png 514w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.12-AM-300x266.png 300w" sizes="auto, (max-width: 514px) 100vw, 514px" /></a></p>
<p>When you paste it will ask you to give a new name to the directory.</p>
<p><a href="https://iotexpert.com/?attachment_id=5875" rel="attachment wp-att-5875"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.39-AM.png" alt="" width="474" height="166" class="alignnone size-large wp-image-5875" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.39-AM.png 474w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.04.39-AM-300x105.png 300w" sizes="auto, (max-width: 474px) 100vw, 474px" /></a></p>
<p>Give the main file a new name, in this case ex02CCCD.c</p>
<p><a href="https://iotexpert.com/?attachment_id=5877" rel="attachment wp-att-5877"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.09.24-AM.png" alt="" width="235" height="74" class="alignnone size-full wp-image-5877" /></a></p>
<p>And create a new make target.</p>
<p><a href="https://iotexpert.com/?attachment_id=5874" rel="attachment wp-att-5874"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.05.55-AM.png" alt="" width="487" height="460" class="alignnone size-large wp-image-5874" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.05.55-AM.png 487w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.05.55-AM-300x283.png 300w" sizes="auto, (max-width: 487px) 100vw, 487px" /></a></p>
<p>Fix the makefile with the new name of the source file.</p>
<p><a href="https://iotexpert.com/?attachment_id=5873" rel="attachment wp-att-5873"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM-1024x360.png" alt="" width="1024" height="360" class="alignnone size-large wp-image-5873" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM-1024x360.png 1024w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM-600x211.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM-300x105.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM-768x270.png 768w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.06.06-AM.png 1041w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Build and test to make sure that everything still works&#8230;. and it seems to.</p>
<p><a href="https://iotexpert.com/?attachment_id=5878" rel="attachment wp-att-5878"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.07.59-AM.png" alt="" width="838" height="490" class="alignnone size-full wp-image-5878" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.07.59-AM.png 838w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.07.59-AM-600x351.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.07.59-AM-300x175.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.07.59-AM-768x449.png 768w" sizes="auto, (max-width: 838px) 100vw, 838px" /></a></p>
<h1>Write the CCCD</h1>
<p>The Peripheral that we are talking to in this example has a CapSense Characteristic that has a Client Characteristic Configuration Descriptors, also known as the CCCD.   When you set the CCCD to 1, the Peripheral will then send you notifications anytime the underlying Characteristic changes.  WICED has some utility functions to help you interact with the remote GATT server.  To add them to your project, first include the header file.</p>
<pre class="start-line:34 lang:c decode:true ">#include "wiced_bt_gatt_util.h"</pre>
<p>Then modify your makefile to include the library.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">$(NAME)_COMPONENTS += gatt_utils_lib.a</pre>
<p>To actually turn on/off the CCCD you simply call the library function wiced_bt_util_set_gatt_client_config_descriptor.  Ill add a case &#8216;n&#8217; to turn on notifications and a case &#8216;N&#8217; to turn them off.  Notice the 0x12 is hardcoded in two places, something which is really bad and Ill fix in the next article.  Don&#8217;t forget to add the two cases to the help message.</p>
<pre class="start-line:422 lang:c decode:true">     case 'n':
         WICED_BT_TRACE("CCCD On\n");
         if(conn_id )
             wiced_bt_util_set_gatt_client_config_descriptor(conn_id,0x12,1); // Very bad hardcode 0x12

         break;

     case 'N':
         WICED_BT_TRACE("CCCD Off\n");
         if(conn_id )
             wiced_bt_util_set_gatt_client_config_descriptor(conn_id,0x12,0); // Very bad hardcode 0x12
         break;


    case '?':
        /* Print help */
        WICED_BT_TRACE( "\n" );
        WICED_BT_TRACE( "+------- Available Commands -------+\n" );
        WICED_BT_TRACE( "|  n    CCCD On                    |\n" );
        WICED_BT_TRACE( "|  N    CCCD Off                   |\n" );</pre>
<p>Now when I test&#8230; I can press the &#8216;n&#8217; to set the CCCD.  When I touch the CapSense slider I seem to get a whole bunch of &#8220;Unknown GATT Event 1&#8243;s (we will figure that out in just a bit).  So it seems to be working.  When I press &#8216;N&#8217; I don&#8217;t get the messages.</p>
<p><a href="https://iotexpert.com/?attachment_id=5881" rel="attachment wp-att-5881"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.25.49-AM.png" alt="" width="852" height="522" class="alignnone size-full wp-image-5881" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.25.49-AM.png 852w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.25.49-AM-600x368.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.25.49-AM-300x184.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.25.49-AM-768x471.png 768w" sizes="auto, (max-width: 852px) 100vw, 852px" /></a><br />
Is there something special about the function wiced_bt_util_set_gatt_client_config_descriptor?  Nope.  If you right click on it, you can look at the source code.  This code looks exactly like the &#8220;writeLed&#8221; function that we wrote in the previous example.  The only difference is that instead of allocating a buffer using wiced_bt_get_buffer the author of this function allocated the buffer on the stack.</p>
<pre class="start-line:36 lang:c decode:true ">/*
 * Format and send GATT Write Request to set value of a G
 */
wiced_bt_gatt_status_t wiced_bt_util_set_gatt_client_config_descriptor(uint16_t conn_id, uint16_t handle, uint16_t value)
{
    wiced_bt_gatt_status_t status;
    uint8_t                buf[sizeof(wiced_bt_gatt_value_t) + 1];
    wiced_bt_gatt_value_t *p_write = ( wiced_bt_gatt_value_t* )buf;
    uint16_t               u16 = value;

    // Allocating a buffer to send the write request
    memset(buf, 0, sizeof(buf));

    p_write-&gt;handle   = handle;
    p_write-&gt;offset   = 0;
    p_write-&gt;len      = 2;
    p_write-&gt;auth_req = GATT_AUTH_REQ_NONE;
    p_write-&gt;value[0] = u16 &amp; 0xff;
    p_write-&gt;value[1] = (u16 &gt;&gt; 8) &amp; 0xff;

    // Register with the server to receive notification
    status = wiced_bt_gatt_send_write (conn_id, GATT_WRITE, p_write);
    return status;
}</pre>
<h1>Handle the new GATT Events</h1>
<p>In the screenshot of the serial terminal above you can see a bunch of &#8220;Unknown GATT Event 1&#8221;.  What is that?  To figure that out, right click on the GATT_CONNECTION_EVT and go to declaration.</p>
<p><a href="https://iotexpert.com/?attachment_id=5882" rel="attachment wp-att-5882"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.28.18-AM.png" alt="" width="765" height="217" class="alignnone size-full wp-image-5882" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.28.18-AM.png 765w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.28.18-AM-600x170.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.28.18-AM-300x85.png 300w" sizes="auto, (max-width: 765px) 100vw, 765px" /></a></p>
<p>This will take you to this enumeration, which shows all of the possible GATT events.  And, in this table you can see that 0x01 is GATT_OPERATION_CPLT_EVT.</p>
<pre class="start-line:611 EnlighterJSRAW" data-enlighter-language="c" ">/** GATT events */
typedef enum
{
    GATT_CONNECTION_STATUS_EVT,                         /**&lt; GATT connection status change. Event data: #wiced_bt_gatt_connection_status_t */
    GATT_OPERATION_CPLT_EVT,                            /**&lt; GATT operation complete. Event data: #wiced_bt_gatt_event_data_t */
    GATT_DISCOVERY_RESULT_EVT,                          /**&lt; GATT attribute discovery result. Event data: #wiced_bt_gatt_discovery_result_t */
    GATT_DISCOVERY_CPLT_EVT,                            /**&lt; GATT attribute discovery complete. Event data: #wiced_bt_gatt_event_data_t */
    GATT_ATTRIBUTE_REQUEST_EVT,                         /**&lt; GATT attribute request (from remote client). Event data: #wiced_bt_gatt_attribute_request_t */
    GATT_CONGESTION_EVT                                 /**&lt; GATT congestion (running low in tx buffers). Event data: #wiced_bt_gatt_congestion_event_t */
} wiced_bt_gatt_evt_t;
</pre>
<p>So, lets update the GATT Event handler for that case.  What Ill do is just printout the information that is sent (which is of type wiced_bt_gatt_event_data_t).</p>
<pre class="start-line:298 lang:c decode:true">    case GATT_OPERATION_CPLT_EVT:

        // When you get something back from the peripheral... print it out.. and all of its data

        WICED_BT_TRACE("Gatt Event Complete Conn=%d Op=%d status=0x%X Handle=0x%X len=%d Data=",
                p_data-&gt;operation_complete.conn_id,
                p_data-&gt;operation_complete.op,
                p_data-&gt;operation_complete.status,
                p_data-&gt;operation_complete.response_data.handle,
                p_data-&gt;operation_complete.response_data.att_value.len);

        for(int i=0;i&lt;p_data-&gt;operation_complete.response_data.att_value.len;i++)
        {
            WICED_BT_TRACE("%02X ",p_data-&gt;operation_complete.response_data.att_value.p_data[i]);
        }
        WICED_BT_TRACE("\n");

        break;</pre>
<p>After I program the CYW920719Q40EVB_01 you can see that things seem to be working.  Specifically, I found the peripheral, connected to it, set the CCCD for CapSense, then pressed the CapSense slider on the Peripheral.  Notice that after I set the CCCD, I get an event complete with op=3 and handle=0x12.  This is the write response message for the CCCD handle. (remember the hardcoded 0x12 from above).</p>
<p>The other thing to see is that each time there is CapSense update, the Peripheral sends out a notification of handle 0x11 with the current CapSense slider value.  Notice that the slider value is little endian.  You can see the last value is 0xFFFF which is a no touch in CapSense.</p>
<p><a href="https://iotexpert.com/?attachment_id=5883" rel="attachment wp-att-5883"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.31.49-AM.png" alt="" width="843" height="517" class="alignnone size-full wp-image-5883" srcset="https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.31.49-AM.png 843w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.31.49-AM-600x368.png 600w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.31.49-AM-300x184.png 300w, https://iotexpert.com/wp-content/uploads/2018/10/Screen-Shot-2018-10-07-at-11.31.49-AM-768x471.png 768w" sizes="auto, (max-width: 843px) 100vw, 843px" /></a></p>
<p>The &#8220;op&#8221; is just one of the enumerated values from the list below.  You can see the 0x06 is Notification.  And 0x03 is Write.</p>
<pre class="start-line:366 EnlighterJSRAW" data-enlighter-language="c" ">/** GATT client operation type, used in client callback function
*/
enum wiced_bt_gatt_optype_e
{
    GATTC_OPTYPE_NONE             = 0,    /**&lt; None      */
    GATTC_OPTYPE_DISCOVERY        = 1,    /**&lt; Discovery */
    GATTC_OPTYPE_READ             = 2,    /**&lt; Read      */
    GATTC_OPTYPE_WRITE            = 3,    /**&lt; Write     */
    GATTC_OPTYPE_EXE_WRITE        = 4,    /**&lt; Execute Write */
    GATTC_OPTYPE_CONFIG           = 5,    /**&lt; Configure */
    GATTC_OPTYPE_NOTIFICATION     = 6,    /**&lt; Notification */
    GATTC_OPTYPE_INDICATION       = 7     /**&lt; Indication */
};</pre>
<p><span><p>You can find all of the source code for these projects at <a href="https://github.com/iotexpert/PSoC4BLE-Central">github.com/iotexpert/PSoc4BLE-Central </a></p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Article</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2017/05/09/psoc4-ble-central-custom-profile-wled-capsense/">PSoC 4 BLE Central</a></td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/05/11/psoc4-ble-central-using-cysmart-dongle/">PSoC 4 BLE Central - Using the CySmart Dongle</a></td>
</tr>

<tr><td ><a href="https://iotexpert.com/2018/10/08/wiced-20719-ble-central-custom-profile-w-led-capsense-part-1/">WICED 20719 BLE Central Custom Profile w/LED &amp; CapSense - Part 1</a></td>
</tr>

<tr><td >WICED 20719 BLE Central Custom Profile w/LED &amp; CapSense - Part 2</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/wiced-20719-ble-central-custom-profile-w-led-capsense-part-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>IoT Mailbox: An Introduction</title>
		<link>https://iotexpert.com/iot-mailbox-an-introduction/</link>
					<comments>https://iotexpert.com/iot-mailbox-an-introduction/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Mon, 13 Aug 2018 12:04:49 +0000</pubDate>
				<category><![CDATA[Bluetooth]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5743</guid>

					<description><![CDATA[Summary On the days that my newspaper carrier decides to deliver the newspaper, you can be sure that it won&#8217;t be there before 4:00am or after 10:00am.  Why do I still get a newspaper?  Because my wife likes it.  The status of the delivery is a constant source of speculation in the morning.  Have you [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>On the days that my newspaper carrier decides to deliver the newspaper, you can be sure that it won&#8217;t be there before 4:00am or after 10:00am.  Why do I still get a newspaper?  Because my wife likes it.  The status of the delivery is a constant source of speculation in the morning.  Have you been out to the newspaper box?  Will you go?  etc.  So it seems only logical to make an IoT device that figures out if I have a newspaper.  Obviously this is a bit silly to put as much time and effort as I have into that simple task.  But, doing something cool has it own worth.  And it will give me a chance to use the new WICED XR (extended range) Bluetooth radio module <a href="http://www.cypress.com/documentation/datasheets/cybt-483039-02-ez-bt-xr-wiced-module" target="_blank" rel="noopener">CYBT-483039-02</a>.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/img_6171/" rel="attachment wp-att-5744"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-225x300.jpg" alt="" width="225" height="300" class="alignnone wp-image-5744 size-medium" srcset="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-225x300.jpg 225w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-600x800.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-768x1024.jpg 768w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6171-scaled.jpg 1920w" sizes="auto, (max-width: 225px) 100vw, 225px" /></a></p>
<p>And here is a picture of the new module on the <a href="http://www.cypress.com/documentation/development-kitsboards/cybt-483039-eval-ez-bt-module-arduino-evaluation-board" target="_blank" rel="noopener">CYBT-483039-EVAL EZ-BT</a> evaluation kit.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/cybt-483039-eval/" rel="attachment wp-att-5751"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL.jpg" alt="" width="302" height="404" class="alignnone size-full wp-image-5751" srcset="https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL.jpg 302w, https://iotexpert.com/wp-content/uploads/2018/08/CYBT-483039-EVAL-224x300.jpg 224w" sizes="auto, (max-width: 302px) 100vw, 302px" /></a></p>
<p>For this design I want</p>
<ol>
<li>A newspaper sensor (not sure what that will be)</li>
<li>Waterproof case</li>
<li>A temperature sensor</li>
<li>A custom circuit board</li>
<li>A solar battery charger</li>
<li>The ability to program and debug the 20719 (which will be acting as a beacon)</li>
<li>An OTA Bootloader</li>
<li>A Real Time Clock</li>
<li>A wifi/ble bridge (inside the house)</li>
<li>Some cloud data capture and display</li>
<li>An iOS App</li>
</ol>
<p>So far, this project has been quite a rabbit hole as I don&#8217;t/didn&#8217;t know anything about battery power supplies.  Specifically energy harvesting solar powered lithium ion battery chargers and system power supply.  Unfortunately Cypress doesnt make an IC that performs this application &#8230; so if you send Mouser a few hundred dollars and they will send you a box of a bunch of different Solar PMIC Evaluation kits, ST, TI, Linear, Analog Devices, and Microchip. (which I will write about in detail later)</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/img_6174/" rel="attachment wp-att-5750"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-1024x768.jpg" alt="" width="1024" height="768" class="alignnone wp-image-5750 size-large" srcset="https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-1024x768.jpg 1024w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-600x450.jpg 600w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-300x225.jpg 300w, https://iotexpert.com/wp-content/uploads/2018/08/IMG_6174-e1533994969721-768x576.jpg 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Architecture</h1>
<p>Here is a picture of the architecture.</p>
<p><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/mboxarch/" rel="attachment wp-att-5745"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-1024x842.png" alt="" width="1024" height="842" class="alignnone size-large wp-image-5745" srcset="https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-1024x842.png 1024w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-600x493.png 600w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-300x247.png 300w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch-768x632.png 768w, https://iotexpert.com/wp-content/uploads/2018/08/mboxarch.png 1104w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>In the next Article I will start the process of learning about Solar Battery Charging PMICs.</p>
<p><span><p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Article</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2018/08/13/iot-mailbox-an-introduction/">IoT Mailbox Introduction</a></td>
<td >An introduction to the long series of articles about creating a new IoT System.</td>
</tr>

<tr><td >IoT Mailbox: Solar Battery Chargers &amp; System Power Supplies</td>
<td ></td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/iot-mailbox-an-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Lesson 9 &#8211; WICED Bluetooth: Classic Serial Port</title>
		<link>https://iotexpert.com/lesson-9-wiced-bluetooth-classic-serial-port/</link>
					<comments>https://iotexpert.com/lesson-9-wiced-bluetooth-classic-serial-port/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 12:39:24 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[Mouser CYW20719 Bluetooth 5.0]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5625</guid>

					<description><![CDATA[Summary In all of the previous examples I have been using Bluetooth Low Energy.  One of the great benefits of the Cypress CYW20719 is that it is a Combo Radio.  Combo means that it can use both Bluetooth Low Energy as well as Bluetooth Classic.  I am late to the Bluetooth game but as best [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>WICED Bluetooth Using the CYW20719</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Title</th>
<th >Comment</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/06/23/lesson-0-a-two-hour-wiced-bluetooth-class/">A Two Hour WICED Bluetooth Class</a></td>
<td >WICED Bluetooth Using the CYW20719 in all its glory</td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-1-wiced-bluetooth-a-tour-of-the-resources/">Resources</a></td>
<td ><span>Links to all of the Cypress WICED information including videos, application notes etc.</span></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/">Your First Project</a></td>
<td >Making Hello World &amp; the Blinky LED</td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/">The Super Mux Tool</a></td>
<td >Learning about platforms and the Super Mux Tool</td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-4-wiced-bluetooth-using-snips/">Snips</a></td>
<td >Using the example projects to learn Bluetooth</td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-5-wiced-bluetooth-bluetooth-designer-turn-up-the-radio/">Bluetooth Designer</a></td>
<td >Using the tool to customize a project and get going fast</td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-6-wiced-bluetooth-the-peripheral-comes-alive/">The CCCD &amp; Notification</a></td>
<td >Writing back to the Central</td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/">Advertising  Beacon</a></td>
<td >Building a beacon project to advertise your custom information </td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/">Scanner</a></td>
<td >Viewing the world around you</td>
</tr>

<tr><td >9</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/">Bluetooth Classic SPP</a></td>
<td >Using the Serial Port Profile to Transmit Lots of Data</td>
</tr>
</tbody></table></div></p>
<p>Source code: </p>
<ul>
<li>git@github.com:iotexpert/wiced_bt_intro.git</li>
<li>https://github.com/iotexpert/wiced_bt_intro</li>
</ul>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In all of the previous examples I have been using Bluetooth Low Energy.  One of the great benefits of the Cypress CYW20719 is that it is a Combo Radio.  Combo means that it can use both Bluetooth Low Energy as well as Bluetooth Classic.  I am late to the Bluetooth game but as best I can tell Bluetooth Classic and Bluetooth Low Energy are exactly the same &#8230; except everything is different.  When Bluetooth was originally conceived, one of the principal functions was to act as &#8220;serial port wire cutter&#8221;.  Everywhere you looked there were devices that used a serial port wire, e.g. mice, printers, keyboards etc.</p>
<p>For this lesson we are going to dip back into the snip directory to get a Bluetooth Classic program to start with.  The program snip.bt.spp implements the Serial Port Profile (SPP).  The SPP is emulates a classic serial port.  It has all of the uart wires that we know and love including rx,tx,cts etc.  What this allows you to do is open up a high speed (much faster than BLE) connection.</p>
<p>To implement this lesson I will perform the following steps</p>
<ol>
<li>Make a new folder in the wiced_bt_class folder</li>
<li>Copy the files from apps/snip/bt/spp into my new folder</li>
<li>Create a make target and program it</li>
<li>Make a connection using a Bluetooth serial port on my Mac</li>
<li>Look at where the pin is set</li>
<li>Examine the spp setup code</li>
<li>Modify it to print out all the data sent to the SPP</li>
</ol>
<h1>Implement the SPP</h1>
<p>&nbsp;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-41-56-am/" rel="attachment wp-att-5630"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.41.56-AM.png" alt="" width="512" height="169" class="alignnone size-large wp-image-5630" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.41.56-AM.png 512w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.41.56-AM-300x99.png 300w" sizes="auto, (max-width: 512px) 100vw, 512px" /></a></p>
<p>Set the folder name to &#8220;spp&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-44-33-am/" rel="attachment wp-att-5632"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.44.33-AM.png" alt="" width="523" height="585" class="alignnone size-full wp-image-5632" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.44.33-AM.png 523w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.44.33-AM-268x300.png 268w" sizes="auto, (max-width: 523px) 100vw, 523px" /></a></p>
<p>Copy and past the files from the folder apps.snip.bt.spp</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-42-21-am/" rel="attachment wp-att-5629"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.42.21-AM.png" alt="" width="482" height="118" class="alignnone size-full wp-image-5629" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.42.21-AM.png 482w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.42.21-AM-300x73.png 300w" sizes="auto, (max-width: 482px) 100vw, 482px" /></a><br />
And paste them into your new spp folder</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-46-49-am/" rel="attachment wp-att-5633"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.46.49-AM.png" alt="" width="340" height="223" class="alignnone size-full wp-image-5633" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.46.49-AM.png 340w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.46.49-AM-300x197.png 300w" sizes="auto, (max-width: 340px) 100vw, 340px" /></a></p>
<p>Create a make target for your spp project</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-47-49-am/" rel="attachment wp-att-5635"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.47.49-AM.png" alt="" width="452" height="442" class="alignnone size-full wp-image-5635" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.47.49-AM.png 452w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.47.49-AM-300x293.png 300w" sizes="auto, (max-width: 452px) 100vw, 452px" /></a></p>
<p>Program the board with your project</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-51-35-am/" rel="attachment wp-att-5634"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM-1024x648.png" alt="" width="1024" height="648" class="alignnone size-large wp-image-5634" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM-1024x648.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM-600x379.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM-300x190.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM-768x486.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.51.35-AM.png 1306w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now tell the computer to open a classic connection by running file-&gt;open bluetooth</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-9-00-25-am/" rel="attachment wp-att-5641"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.00.25-AM.png" alt="" width="654" height="394" class="alignnone size-full wp-image-5641" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.00.25-AM.png 654w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.00.25-AM-600x361.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.00.25-AM-300x181.png 300w" sizes="auto, (max-width: 654px) 100vw, 654px" /></a></p>
<p>Select the &#8220;spp test&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-9-08-06-am/" rel="attachment wp-att-5642"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM-1024x799.png" alt="" width="1024" height="799" class="alignnone size-large wp-image-5642" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM-1024x799.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM-600x468.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM-300x234.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM-768x600.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.08.06-AM.png 1158w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now press some keys on the new terminal window&#8230; and look at the output window of the &#8220;spp test&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-58-00-am/" rel="attachment wp-att-5637"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM-1024x703.png" alt="" width="1024" height="703" class="alignnone size-large wp-image-5637" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM-1024x703.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM-600x412.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM-300x206.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM-768x528.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.58.00-AM.png 1782w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Type in the pin code which is 0000.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-8-57-46-am/" rel="attachment wp-att-5638"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM-1024x479.png" alt="" width="1024" height="479" class="alignnone size-large wp-image-5638" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM-1024x479.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM-600x281.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM-300x140.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM-768x359.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-8.57.46-AM.png 1026w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>But, how did I know the pin code?  Look at the source code.</p>
<pre class="start-line:154 lang:c decode:true ">uint8_t pincode[4] = { 0x30, 0x30, 0x30, 0x30 };
</pre>
<p>Now, when you press keys on the &#8220;Bluetooth serial terminal&#8221; you will see a not very helpful message on the CYW920719Q40EVB-01 terminal window.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-9-11-49-am/" rel="attachment wp-att-5643"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM-1024x706.png" alt="" width="1024" height="706" class="alignnone size-large wp-image-5643" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM-1024x706.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM-600x413.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM-300x207.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM-768x529.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-9.11.49-AM.png 1788w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>I think that it would be better to print out the characters that the person types.  So lets figure out how this works.  In the application init function on line 251 there is a call to wiced_bt_spp_startup</p>
<pre class="start-line:233 EnlighterJSRAW" data-enlighter-language="c" ">void application_init(void)
{
    wiced_bt_gatt_status_t gatt_status;
    wiced_result_t         result;


#if SEND_DATA_ON_INTERRUPT
    /* Configure the button available on the platform */
    wiced_platform_register_button_callback( WICED_PLATFORM_BUTTON_1, app_interrupt_handler, NULL, WICED_PLATFORM_BUTTON_RISING_EDGE);

    // init timer that we will use for the rx data flow control.
    wiced_init_timer(&amp;app_tx_timer, app_tx_ack_timeout, 0, WICED_MILLI_SECONDS_TIMER);
#endif

    app_write_eir();


    // Initialize SPP library
    wiced_bt_spp_startup(&amp;spp_reg);</pre>
<p>That function takes a pointer to a structure with a bunch of interesting things in it.  Notice that there is a function called &#8220;spp_rx_data_callback&#8221; that is called every time that data come in from the SPP.</p>
<pre class="start-line:111 EnlighterJSRAW" data-enlighter-language="c"">wiced_bt_spp_reg_t spp_reg =
{
    SPP_RFCOMM_SCN,                     /* RFCOMM service channel number for SPP connection */
    MAX_TX_BUFFER,                      /* RFCOMM MTU for SPP connection */
    spp_connection_up_callback,         /* SPP connection established */
    NULL,                               /* SPP connection establishment failed, not used because this app never initiates connection */
    NULL,                               /* SPP service not found, not used because this app never initiates connection */
    spp_connection_down_callback,       /* SPP connection disconnected */
    spp_rx_data_callback,               /* Data packet received */
};</pre>
<p>Now look at the function spp_rx_data_callback.  All it does is print out a message saying how much data and the hex value of the data.</p>
<pre class="start-line:450 EnlighterJSRAW" data-enlighter-language="c" ">wiced_bool_t spp_rx_data_callback(uint16_t handle, uint8_t* p_data, uint32_t data_len)
{
    int i;
//    wiced_bt_buffer_statistics_t buffer_stats[4];

//    wiced_bt_get_buffer_usage (buffer_stats, sizeof(buffer_stats));

//    WICED_BT_TRACE("0:%d/%d 1:%d/%d 2:%d/%d 3:%d/%d\n", buffer_stats[0].current_allocated_count, buffer_stats[0].max_allocated_count,
//                   buffer_stats[1].current_allocated_count, buffer_stats[1].max_allocated_count,
//                   buffer_stats[2].current_allocated_count, buffer_stats[2].max_allocated_count,
//                   buffer_stats[3].current_allocated_count, buffer_stats[3].max_allocated_count);

//    wiced_result_t wiced_bt_get_buffer_usage (&amp;buffer_stats, sizeof(buffer_stats));

    WICED_BT_TRACE("%s handle:%d len:%d %02x-%02x\n", __FUNCTION__, handle, data_len, p_data[0], p_data[data_len - 1]);

#if LOOPBACK_DATA
    wiced_bt_spp_send_session_data(handle, p_data, data_len);
#endif
    return WICED_TRUE;
}</pre>
<p>So,  How about instead of that message we just print out the data.</p>
<pre class="start-line:465 EnlighterJSRAW" data-enlighter-language="c"">    //WICED_BT_TRACE("%s handle:%d len:%d %02x-%02x\n", __FUNCTION__, handle, data_len, p_data[0], p_data[data_len - 1]);

    for(int i=0;i&lt;data_len;i++)
        WICED_BT_TRACE("%c",p_data[i]);</pre>
<p>Now when I run the project and type I see the characters that I type coming out on the serial port.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/screen-shot-2018-06-27-at-10-27-02-am/" rel="attachment wp-att-5645"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM-1024x451.png" alt="" width="1024" height="451" class="alignnone size-large wp-image-5645" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM-1024x451.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM-600x264.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM-300x132.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM-768x338.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-27-at-10.27.02-AM.png 1562w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/lesson-9-wiced-bluetooth-classic-serial-port/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Lesson 8 &#8211; WICED Bluetooth: The Advertising Scanner</title>
		<link>https://iotexpert.com/lesson-8-wiced-bluetooth-the-advertising-scanner/</link>
					<comments>https://iotexpert.com/lesson-8-wiced-bluetooth-the-advertising-scanner/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 12:38:54 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[Mouser CYW20719 Bluetooth 5.0]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5600</guid>

					<description><![CDATA[Summary In the last lesson I showed you how to build a BLE Advertising Beacon.  In that lesson I used a program called the &#8220;AdvScanner&#8221; which ran on a CYW920719Q40EVB-01 and acted like a Bluetooth Sniffer.  In this lesson I&#8217;ll show you how to build a simpler version of that program to look for the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>WICED Bluetooth Using the CYW20719</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Title</th>
<th >Comment</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/06/23/lesson-0-a-two-hour-wiced-bluetooth-class/">A Two Hour WICED Bluetooth Class</a></td>
<td >WICED Bluetooth Using the CYW20719 in all its glory</td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-1-wiced-bluetooth-a-tour-of-the-resources/">Resources</a></td>
<td ><span>Links to all of the Cypress WICED information including videos, application notes etc.</span></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/">Your First Project</a></td>
<td >Making Hello World &amp; the Blinky LED</td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/">The Super Mux Tool</a></td>
<td >Learning about platforms and the Super Mux Tool</td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-4-wiced-bluetooth-using-snips/">Snips</a></td>
<td >Using the example projects to learn Bluetooth</td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-5-wiced-bluetooth-bluetooth-designer-turn-up-the-radio/">Bluetooth Designer</a></td>
<td >Using the tool to customize a project and get going fast</td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-6-wiced-bluetooth-the-peripheral-comes-alive/">The CCCD &amp; Notification</a></td>
<td >Writing back to the Central</td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/">Advertising  Beacon</a></td>
<td >Building a beacon project to advertise your custom information </td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/">Scanner</a></td>
<td >Viewing the world around you</td>
</tr>

<tr><td >9</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/">Bluetooth Classic SPP</a></td>
<td >Using the Serial Port Profile to Transmit Lots of Data</td>
</tr>
</tbody></table></div></p>
<p>Source code: </p>
<ul>
<li>git@github.com:iotexpert/wiced_bt_intro.git</li>
<li>https://github.com/iotexpert/wiced_bt_intro</li>
</ul>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>In the last lesson I showed you how to build a BLE Advertising Beacon.  In that lesson I used a program called the &#8220;AdvScanner&#8221; which ran on a CYW920719Q40EVB-01 and acted like a Bluetooth Sniffer.  In this lesson I&#8217;ll show you how to build a simpler version of that program to look for the L7_Advertiser we built in the last lesson.</p>
<p>The important concepts in this lesson are:</p>
<ol>
<li>BLE Scanning</li>
<li>Parsing Advertising Packets</li>
</ol>
<p>I am going to build a project that Scans for BLE Advertisers.  Then, I&#8217;ll add the ability to print out the advertising packet.  And finally, I will add filtering capability to only look for advertisers who are using the Cypress Manufacturers code.</p>
<p>The steps that we will follow are:</p>
<ol>
<li>Make a new project with WICED Bluetooth Designer called L8_Scanner</li>
<li>Turn off the GATT Database</li>
<li>Move it into your project folder</li>
<li>Fix the WICED_BT_TRACE to use the PUART</li>
<li>Create a make target and build it</li>
<li>Add a new function that prints out Advertising Packets</li>
<li>Update the l8_scanner_app_init function to remove Advertising</li>
<li>Update the wiced_bt_config to never stop scanning</li>
<li>Program the development kit and see what happens</li>
<li>Update the newAdv function to print out the raw data in the advertising packet</li>
<li>Program again and see all of the chaos</li>
<li>Put a filter for the Advertisers using the Cypress MFG Code</li>
<li>Program</li>
</ol>
<h1>Implement the Project</h1>
<p>Create a new project called L8_Scanner using the Bluetooth Designer</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-3-27-25-pm/" rel="attachment wp-att-5601"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.25-PM.png" alt="" width="522" height="501" class="alignnone size-full wp-image-5601" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.25-PM.png 522w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.25-PM-300x288.png 300w" sizes="auto, (max-width: 522px) 100vw, 522px" /></a></p>
<p>Turn off the GATT Database and then press Generate Code</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-3-27-38-pm/" rel="attachment wp-att-5602"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.38-PM.png" alt="" width="663" height="477" class="alignnone size-full wp-image-5602" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.38-PM.png 663w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.38-PM-600x432.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.27.38-PM-300x216.png 300w" sizes="auto, (max-width: 663px) 100vw, 663px" /></a></p>
<p>Move the project into the wiced_bt_class folder</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-3-41-07-pm/" rel="attachment wp-att-5605"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.41.07-PM.png" alt="" width="262" height="192" class="alignnone size-full wp-image-5605" /></a></p>
<p>Update the WICED_BT_TRACE to send output to the PUART</p>
<pre class="start-line:105 lang:c decode:true ">#if ((defined WICED_BT_TRACE_ENABLE) || (defined HCI_TRACE_OVER_TRANSPORT))
    /* Set the Debug UART as WICED_ROUTE_DEBUG_NONE to get rid of prints */
    //  wiced_set_debug_uart( WICED_ROUTE_DEBUG_NONE );

    /* Set Debug UART as WICED_ROUTE_DEBUG_TO_PUART to see debug traces on Peripheral UART (PUART) */
      wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_PUART );

    /* Set the Debug UART as WICED_ROUTE_DEBUG_TO_WICED_UART to send debug strings over the WICED debug interface */
    //wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_WICED_UART );
#endif</pre>
<p>Modify the make target &amp; program that was created by the BT Designer</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-3-38-52-pm/" rel="attachment wp-att-5604"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.38.52-PM.png" alt="" width="386" height="404" class="alignnone size-full wp-image-5604" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.38.52-PM.png 386w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.38.52-PM-287x300.png 287w" sizes="auto, (max-width: 386px) 100vw, 386px" /></a></p>
<p>Make a new function that will be called when WICED finds a new advertising packet.</p>
<pre class="start-line:120 lang:c decode:true">void newAdv(wiced_bt_ble_scan_results_t *p_scan_result, uint8_t *p_adv_data)
{
    WICED_BT_TRACE("Found device %B\n",p_scan_result-&gt;remote_bd_addr);

}</pre>
<p>Remove the start advertising from l8_scanner_app_init</p>
<pre class="start-line:127 lang:c decode:true">/*
 * This function is executed in the BTM_ENABLED_EVT management callback.
 */
void l8_scanner_app_init(void)
{
    /* Initialize Application */
    wiced_bt_app_init();

    /* Allow peer to pair */
    wiced_bt_set_pairable_mode(WICED_TRUE, 0);

    /* Set Advertisement Data */
    //l8_scanner_set_advertisement_data();

    /* Start Undirected LE Advertisements on device startup.
     * The corresponding parameters are contained in 'wiced_bt_cfg.c' */
    /* TODO: Make sure that this is the desired behavior. */
    //wiced_bt_start_advertisements(BTM_BLE_ADVERT_UNDIRECTED_HIGH, 0, NULL);
    wiced_bt_ble_scan(BTM_BLE_SCAN_TYPE_HIGH_DUTY,FALSE,newAdv);
}</pre>
<p>Update wiced_bt_config.c to never stop scanning.</p>
<pre class="start-line:53 lang:c decode:true">        .high_duty_scan_duration =          0,                                                          /**&lt; High Duty Scan Duration in seconds (0 for infinite) */
</pre>
<p>Program your development kit and see what happens.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-4-05-52-pm/" rel="attachment wp-att-5606"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM-1024x553.png" alt="" width="1024" height="553" class="alignnone size-large wp-image-5606" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM-1024x553.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM-600x324.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM-300x162.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM-768x414.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.05.52-PM.png 1160w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now lets update the program to print the advertising packets.</p>
<pre class="start-line:120 lang:c decode:true">void newAdv(wiced_bt_ble_scan_results_t *p_scan_result, uint8_t *p_adv_data)
{

    uint8_t mfgLen;
    uint8_t* mfgData = wiced_bt_ble_check_advertising_data( p_adv_data,0xFF,&amp;mfgLen);


    WICED_BT_TRACE("Found device %B ",p_scan_result-&gt;remote_bd_addr);

    uint8_t index=0;
    int fieldLength=p_adv_data[index];
    do {
        for(int i=0;i&lt;=fieldLength;i++)
            WICED_BT_TRACE("%02X ",p_adv_data[index+i]);

        index = index + fieldLength + 1;
        fieldLength = p_adv_data[index];

    } while(fieldLength);

    WICED_BT_TRACE("\n");
}
</pre>
<p>Now program the development kit and see what happens.  Where I am sitting this is not very helpful because there are boatloads of advertisers.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-4-30-26-pm/" rel="attachment wp-att-5607"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.30.26-PM-1024x539.png" alt="" width="1024" height="539" class="alignnone size-large wp-image-5607" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.30.26-PM-1024x539.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.30.26-PM-600x316.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.30.26-PM-300x158.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-4.30.26-PM-768x404.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now let&#8217;s make one more change.  Instead of printing all of the packets let&#8217;s only look only at the ones that have Manufacturer data, the right length and the Cypress manufacturer id.</p>
<pre class="lang:c decode:true ">    uint8_t mfgLen;
    uint8_t* mfgData = wiced_bt_ble_check_advertising_data( p_adv_data,0xFF,&amp;mfgLen);

    if(!(mfgData &amp;&amp; mfgLen == 3 &amp;&amp; mfgData[0] == 0x31 &amp;&amp; mfgData[1]  == 0x01 ))
        return;
</pre>
<p>Now I only see my L7_Advertising project</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/screen-shot-2018-06-26-at-5-21-49-pm/" rel="attachment wp-att-5618"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM-1024x639.png" alt="" width="1024" height="639" class="alignnone size-large wp-image-5618" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM-1024x639.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM-600x374.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM-300x187.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM-768x479.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-5.21.49-PM.png 1658w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/lesson-8-wiced-bluetooth-the-advertising-scanner/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Lesson 7 &#8211; WICED Bluetooth: Bluetooth Advertising</title>
		<link>https://iotexpert.com/lesson-7-wiced-bluetooth-bluetooth-advertising/</link>
					<comments>https://iotexpert.com/lesson-7-wiced-bluetooth-bluetooth-advertising/#comments</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 28 Jun 2018 12:38:21 +0000</pubDate>
				<category><![CDATA[CYW920179Q40EVB-01]]></category>
		<category><![CDATA[Mouser CYW20719 Bluetooth 5.0]]></category>
		<category><![CDATA[WICED]]></category>
		<category><![CDATA[WICED 20719]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=5578</guid>

					<description><![CDATA[Summary Everywhere you go there are bunches of Bluetooth devices that are acting as beacons.  Apple has a standard called iBeacon.  Google has a standard called Eddystone.  Some companies use those standards, and some companies make proprietary beacons.  In this lesson we will build a beacon. The important concepts in this lesson are: Advertising packet [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><span><h1>WICED Bluetooth Using the CYW20719</h1>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >#</th>
<th >Title</th>
<th >Comment</th>
</tr>
</thead>
<tbody>
<tr><td >0</td>
<td ><a href="https://iotexpert.com/2018/06/23/lesson-0-a-two-hour-wiced-bluetooth-class/">A Two Hour WICED Bluetooth Class</a></td>
<td >WICED Bluetooth Using the CYW20719 in all its glory</td>
</tr>

<tr><td >1</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-1-wiced-bluetooth-a-tour-of-the-resources/">Resources</a></td>
<td ><span>Links to all of the Cypress WICED information including videos, application notes etc.</span></td>
</tr>

<tr><td >2</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-2-wiced-bluetooth-your-first-projects/">Your First Project</a></td>
<td >Making Hello World &amp; the Blinky LED</td>
</tr>

<tr><td >3</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-3-wiced-bluetooth-the-super-mux-tool/">The Super Mux Tool</a></td>
<td >Learning about platforms and the Super Mux Tool</td>
</tr>

<tr><td >4</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-4-wiced-bluetooth-using-snips/">Snips</a></td>
<td >Using the example projects to learn Bluetooth</td>
</tr>

<tr><td >5</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-5-wiced-bluetooth-bluetooth-designer-turn-up-the-radio/">Bluetooth Designer</a></td>
<td >Using the tool to customize a project and get going fast</td>
</tr>

<tr><td >6</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-6-wiced-bluetooth-the-peripheral-comes-alive/">The CCCD &amp; Notification</a></td>
<td >Writing back to the Central</td>
</tr>

<tr><td >7</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/">Advertising  Beacon</a></td>
<td >Building a beacon project to advertise your custom information </td>
</tr>

<tr><td >8</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-8-wiced-bluetooth-the-advertising-scanner/">Scanner</a></td>
<td >Viewing the world around you</td>
</tr>

<tr><td >9</td>
<td ><a href="https://iotexpert.com/2018/06/28/lesson-9-wiced-bluetooth-classic-serial-port/">Bluetooth Classic SPP</a></td>
<td >Using the Serial Port Profile to Transmit Lots of Data</td>
</tr>
</tbody></table></div></p>
<p>Source code: </p>
<ul>
<li>git@github.com:iotexpert/wiced_bt_intro.git</li>
<li>https://github.com/iotexpert/wiced_bt_intro</li>
</ul>
<p>&nbsp;</p></span></p>
<h1>Summary</h1>
<p>Everywhere you go there are bunches of Bluetooth devices that are acting as beacons.  Apple has a standard called iBeacon.  Google has a standard called Eddystone.  Some companies use those standards, and some companies make proprietary beacons.  In this lesson we will build a beacon.</p>
<p>The important concepts in this lesson are:</p>
<ol>
<li>Advertising packet formats</li>
<li>wiced_bt_cfg.c</li>
</ol>
<p>The steps I will follow are:</p>
<ol>
<li>Run BT Designer</li>
<li>Setup the device as &#8220;no gatt database&#8221;</li>
<li>Move the project into the wiced_bt_class folder</li>
<li>Edit the make target</li>
<li>Fix the WICED_BT_TRACE to go to the PUART</li>
<li>Run it</li>
<li>Edit the wiced_bt_cfg.c to never timeout</li>
<li>Setup no random address changing</li>
<li>Add the manufacturing data uint8_t array and include the Cypress company code</li>
<li>Change the start advertising call to BTM_BLE_ADVERT_NONCONN_HIGH, BLE_ADDR_PUBLIC</li>
<li>Update the length of the advertising packet</li>
<li>Update the set advertising packet to have the manufacturing data</li>
<li>Add a button interrupt function</li>
<li>Register the button interrupt</li>
</ol>
<h1>BLE Concepts</h1>
<p>The Advertising Packet is a string of 3-31 bytes that is broadcast at a configurable interval. The packet is broken up into variable length fields. Each field has the form:</p>
<ul>
<li>Length in bytes (not including the Length byte)</li>
<li>Type</li>
<li>Optional Data</li>
</ul>
<p>The minimum packet requires the &lt;&lt;Flags&gt;&gt; field which is a set of flags that defines how the device behaves (e.g. is it connectable?). Here is a list of the other field Types that you can add:</p>
<pre class="start-line:161 lang:c decode:true ">/** Advertisement data types */
enum wiced_bt_ble_advert_type_e {
    BTM_BLE_ADVERT_TYPE_FLAG                        = 0x01,                 /**&lt; Advertisement flags */
    BTM_BLE_ADVERT_TYPE_16SRV_PARTIAL               = 0x02,                 /**&lt; List of supported services - 16 bit UUIDs (partial) */
    BTM_BLE_ADVERT_TYPE_16SRV_COMPLETE              = 0x03,                 /**&lt; List of supported services - 16 bit UUIDs (complete) */
    BTM_BLE_ADVERT_TYPE_32SRV_PARTIAL               = 0x04,                 /**&lt; List of supported services - 32 bit UUIDs (partial) */
    BTM_BLE_ADVERT_TYPE_32SRV_COMPLETE              = 0x05,                 /**&lt; List of supported services - 32 bit UUIDs (complete) */
    BTM_BLE_ADVERT_TYPE_128SRV_PARTIAL              = 0x06,                 /**&lt; List of supported services - 128 bit UUIDs (partial) */
    BTM_BLE_ADVERT_TYPE_128SRV_COMPLETE             = 0x07,                 /**&lt; List of supported services - 128 bit UUIDs (complete) */
    BTM_BLE_ADVERT_TYPE_NAME_SHORT                  = 0x08,                 /**&lt; Short name */
    BTM_BLE_ADVERT_TYPE_NAME_COMPLETE               = 0x09,                 /**&lt; Complete name */
    BTM_BLE_ADVERT_TYPE_TX_POWER                    = 0x0A,                 /**&lt; TX Power level  */
    BTM_BLE_ADVERT_TYPE_DEV_CLASS                   = 0x0D,                 /**&lt; Device Class */
    BTM_BLE_ADVERT_TYPE_SIMPLE_PAIRING_HASH_C       = 0x0E,                 /**&lt; Simple Pairing Hash C */
    BTM_BLE_ADVERT_TYPE_SIMPLE_PAIRING_RAND_C       = 0x0F,                 /**&lt; Simple Pairing Randomizer R */
    BTM_BLE_ADVERT_TYPE_SM_TK                       = 0x10,                 /**&lt; Security manager TK value */
    BTM_BLE_ADVERT_TYPE_SM_OOB_FLAG                 = 0x11,                 /**&lt; Security manager Out-of-Band data */
    BTM_BLE_ADVERT_TYPE_INTERVAL_RANGE              = 0x12,                 /**&lt; Slave connection interval range */
    BTM_BLE_ADVERT_TYPE_SOLICITATION_SRV_UUID       = 0x14,                 /**&lt; List of solicitated services - 16 bit UUIDs */
    BTM_BLE_ADVERT_TYPE_128SOLICITATION_SRV_UUID    = 0x15,                 /**&lt; List of solicitated services - 128 bit UUIDs */
    BTM_BLE_ADVERT_TYPE_SERVICE_DATA                = 0x16,                 /**&lt; Service data - 16 bit UUID */
    BTM_BLE_ADVERT_TYPE_PUBLIC_TARGET               = 0x17,                 /**&lt; Public target address */
    BTM_BLE_ADVERT_TYPE_RANDOM_TARGET               = 0x18,                 /**&lt; Random target address */
    BTM_BLE_ADVERT_TYPE_APPEARANCE                  = 0x19,                 /**&lt; Appearance */
    BTM_BLE_ADVERT_TYPE_ADVERT_INTERVAL             = 0x1a,                 /**&lt; Advertising interval */
    BTM_BLE_ADVERT_TYPE_LE_BD_ADDR                  = 0x1b,                 /**&lt; LE device bluetooth address */
    BTM_BLE_ADVERT_TYPE_LE_ROLE                     = 0x1c,                 /**&lt; LE role */
    BTM_BLE_ADVERT_TYPE_256SIMPLE_PAIRING_HASH      = 0x1d,                 /**&lt; Simple Pairing Hash C-256 */
    BTM_BLE_ADVERT_TYPE_256SIMPLE_PAIRING_RAND      = 0x1e,                 /**&lt; Simple Pairing Randomizer R-256 */
    BTM_BLE_ADVERT_TYPE_32SOLICITATION_SRV_UUID     = 0x1f,                 /**&lt; List of solicitated services - 32 bit UUIDs */
    BTM_BLE_ADVERT_TYPE_32SERVICE_DATA              = 0x20,                 /**&lt; Service data - 32 bit UUID */
    BTM_BLE_ADVERT_TYPE_128SERVICE_DATA             = 0x21,                 /**&lt; Service data - 128 bit UUID */
    BTM_BLE_ADVERT_TYPE_CONN_CONFIRM_VAL            = 0x22,                 /**&lt; LE Secure Connections Confirmation Value */
    BTM_BLE_ADVERT_TYPE_CONN_RAND_VAL               = 0x23,                 /**&lt; LE Secure Connections Random Value */
    BTM_BLE_ADVERT_TYPE_URI                         = 0x24,                 /**&lt; URI */
    BTM_BLE_ADVERT_TYPE_INDOOR_POS                  = 0x25,                 /**&lt; Indoor Positioning */
    BTM_BLE_ADVERT_TYPE_TRANS_DISCOVER_DATA         = 0x26,                 /**&lt; Transport Discovery Data */
    BTM_BLE_ADVERT_TYPE_SUPPORTED_FEATURES          = 0x27,                 /**&lt; LE Supported Features */
    BTM_BLE_ADVERT_TYPE_UPDATE_CH_MAP_IND           = 0x28,                 /**&lt; Channel Map Update Indication */
    BTM_BLE_ADVERT_TYPE_PB_ADV                      = 0x29,                 /**&lt; PB-ADV */
    BTM_BLE_ADVERT_TYPE_MESH_MSG                    = 0x2A,                 /**&lt; Mesh Message */
    BTM_BLE_ADVERT_TYPE_MESH_BEACON                 = 0x2B,                 /**&lt; Mesh Beacon */
    BTM_BLE_ADVERT_TYPE_3D_INFO_DATA                = 0x3D,                 /**&lt; 3D Information Data */
    BTM_BLE_ADVERT_TYPE_MANUFACTURER                = 0xFF                  /**&lt; Manufacturer data */
};</pre>
<p>Here is an example of the advertising packet that we are going to generate</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-3-15-02-pm/" rel="attachment wp-att-5597"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM-1024x198.png" alt="" width="1024" height="198" class="alignnone size-large wp-image-5597" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM-1024x198.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM-600x116.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM-300x58.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM-768x149.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-3.15.02-PM.png 1260w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<h1>Implement the Project</h1>
<p>Run BT Designer and create a new project called &#8220;L7_Advertising&#8221;</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-1-50-23-pm/" rel="attachment wp-att-5584"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.23-PM.png" alt="" width="523" height="501" class="alignnone size-large wp-image-5584" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.23-PM.png 523w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.23-PM-300x287.png 300w" sizes="auto, (max-width: 523px) 100vw, 523px" /></a></p>
<p>Turn off the GATT Database</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-1-50-58-pm/" rel="attachment wp-att-5583"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.58-PM.png" alt="" width="709" height="487" class="alignnone size-large wp-image-5583" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.58-PM.png 709w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.58-PM-600x412.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.50.58-PM-300x206.png 300w" sizes="auto, (max-width: 709px) 100vw, 709px" /></a> <a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-1-50-23-pm/" rel="attachment wp-att-5584"></a></p>
<p>Move the project into the wiced_bt_class folder</p>
<p><a href="https://iotexpert.com/?attachment_id=5582" rel="attachment wp-att-5582"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.51.41-PM.png" alt="" width="299" height="287" class="alignnone size-full wp-image-5582" /></a></p>
<p>Edit the make target</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-1-24-22-pm/" rel="attachment wp-att-5580"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.24.22-PM.png" alt="" width="653" height="414" class="alignnone size-full wp-image-5580" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.24.22-PM.png 653w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.24.22-PM-600x380.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.24.22-PM-300x190.png 300w" sizes="auto, (max-width: 653px) 100vw, 653px" /></a></p>
<p>Setup the the WICED_BT_TRACE to use the PUART</p>
<pre class="start-line:115 lang:c decode:true">#if ((defined WICED_BT_TRACE_ENABLE) || (defined HCI_TRACE_OVER_TRANSPORT))
    /* Set the Debug UART as WICED_ROUTE_DEBUG_NONE to get rid of prints */
    //  wiced_set_debug_uart( WICED_ROUTE_DEBUG_NONE );

    /* Set Debug UART as WICED_ROUTE_DEBUG_TO_PUART to see debug traces on Peripheral UART (PUART) */
      wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_PUART );

    /* Set the Debug UART as WICED_ROUTE_DEBUG_TO_WICED_UART to send debug strings over the WICED debug interface */
    //wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_WICED_UART );
#endif</pre>
<p>Run it</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-1-55-47-pm/" rel="attachment wp-att-5585"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM-1024x557.png" alt="" width="1024" height="557" class="alignnone size-large wp-image-5585" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM-1024x557.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM-600x326.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM-300x163.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM-768x417.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-1.55.47-PM.png 1148w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>Now that we know it is working, Ill edit the wiced_bt_cfg.c to never timeout</p>
<pre class="start-line:98 lang:c decode:true">        .high_duty_nonconn_duration =       0,                                                         /**&lt; High Duty Non-Connectable Advertising Duration in seconds (0 for infinite) */
</pre>
<p>Setup no random address changing</p>
<pre class="start-line:145 lang:c decode:true">    .rpa_refresh_timeout =                  WICED_BT_CFG_DEFAULT_RANDOM_ADDRESS_NEVER_CHANGE,         /**&lt; Interval of random address refreshing - secs */
</pre>
<p>Now edit the L7_Advertising.c to add the manufacturing data uint8_t array</p>
<pre class="start-line:49 lang:c decode:true">uint8_t manuf_data[] = {0x31,0x01,0x00};</pre>
<p>Switch to non-connectable advertising</p>
<pre class="start-line:148 lang:c decode:true">    wiced_bt_start_advertisements(BTM_BLE_ADVERT_NONCONN_HIGH, BLE_ADDR_PUBLIC, NULL);
</pre>
<p>Update the l7_advertising_set_advertisement_data function to have three elements in the advertising packet</p>
<pre class="start-line:160 lang:c decode:true">    wiced_bt_ble_advert_elem_t adv_elem[3] = { 0 };
</pre>
<p>Add the Manufacturer information to the advertising packet</p>
<pre class="start-line:177 lang:c decode:true">    /* Advertisement Element for Manufacturer Data */
    adv_elem[num_elem].advert_type = BTM_BLE_ADVERT_TYPE_MANUFACTURER;
    adv_elem[num_elem].len = sizeof(manuf_data);
    adv_elem[num_elem].p_data = manuf_data;
    num_elem++;</pre>
<p>Add a button interrupt function</p>
<pre class="start-line:94 lang:c decode:true">void buttonISR(void *data, uint8_t port_pin )
{

    manuf_data[2] += 1;
    l7_advertising_set_advertisement_data();
    WICED_BT_TRACE("Manufacturer Data = %d\n",manuf_data[2]);
}</pre>
<p>Register the button interrupt</p>
<pre class="start-line:150 lang:c decode:true"> wiced_hal_gpio_register_pin_for_interrupt( WICED_GPIO_PIN_BUTTON_1, buttonISR, NULL );
    wiced_hal_gpio_configure_pin( WICED_GPIO_PIN_BUTTON_1, ( GPIO_INPUT_ENABLE | GPIO_PULL_UP | GPIO_EN_INT_FALLING_EDGE ), GPIO_PIN_OUTPUT_HIGH );
</pre>
<h1>Test using the AdvScanner</h1>
<p>I have given you a project called the &#8220;AdvScanner&#8221;.  You can run it by creating a make target.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-2-15-18-pm/" rel="attachment wp-att-5589"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.15.18-PM.png" alt="" width="481" height="367" class="alignnone size-full wp-image-5589" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.15.18-PM.png 481w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.15.18-PM-300x229.png 300w" sizes="auto, (max-width: 481px) 100vw, 481px" /></a></p>
<p>When I run the L7_Advertising project and press the buttons a few times my terminal will look like this</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-2-16-15-pm/" rel="attachment wp-att-5590"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM-1024x550.png" alt="" width="1024" height="550" class="alignnone size-large wp-image-5590" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM-1024x550.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM-600x322.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM-300x161.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM-768x412.png 768w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.16.15-PM.png 1166w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
<p>And when I look at the output of the scanner program you can see the advertising packet for the this project.  Notice that the last three bytes are 31 01 03.  The 03 is the count of button presses.</p>
<p><a href="https://iotexpert.com/2018/06/28/lesson-7-wiced-bluetooth-bluetooth-advertising/screen-shot-2018-06-26-at-2-10-57-pm/" rel="attachment wp-att-5588"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.10.57-PM-1024x665.png" alt="" width="1024" height="665" class="alignnone size-large wp-image-5588" srcset="https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.10.57-PM-1024x665.png 1024w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.10.57-PM-600x390.png 600w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.10.57-PM-300x195.png 300w, https://iotexpert.com/wp-content/uploads/2018/06/Screen-Shot-2018-06-26-at-2.10.57-PM-768x499.png 768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/lesson-7-wiced-bluetooth-bluetooth-advertising/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
