The Internet of Things (IoT) allows us to put small devices around our environment to measure and control. The Raspberry PI Pico-W is an excellent platform for developing such IoT devices, connecting over WIFI and MQTT protocol.
The Internet of Things (IoT) allows us to put small devices around our environment to measure and control. The Raspberry PI Pico-W is an excellent platform for developing such IoT devices, connecting over WIFI and MQTT protocol.
In this course, we explore how to code C++ for a Pico-W IoT device using the FreeRTOS coreMQTT-Agent library version v1.1.0. We take the approach of building an IoT framework for all the devices we want to build. With the ability to connect, publish and subscribe to messages. To operate we also need an MQTT broker and the course talks through the use of Eclipse Mosquitto as a locally installed broker on a Raspberry PI, or using Flespi as a cloud-hosted broker.
The course covers:
Establishing WIFI connectivity in station mode to an access point or router
Building TCPIP socket transport for MQTT protocol
Publishing messages
Subscribing and taking action on messages
Securing MQTT over a TLS Socket, using WoldSSL
Simple circuits to turn on and off an external LED using a local switch connected to the Pico-W are used to test the concepts.
The course assumes knowledge of C++. Though each example walks through the functionality, the course will not talk about the syntax of C++. FreeRTOS Kernel is used to support concurrent tasks for managing the MQTT protocol and an understanding of FreeRTOS Kernel is assumed. I have another course on FreeRTOS Kernel for the Raspberry PI Pico to cover this.
The course assumes you can compile and deploy C++ code to the Pico using the Raspberry PI Pico SDK. My other course “Introduction to C Development Environment for Raspberry PICO” teaches these skills.
Test scrips to interact with the device are written in Python. Some basic Python knowledge would be helpful.
Full captions are provided for the course and are not auto-generated.
Introduction to the course and the goal to build out an IoT stack for our application in C++ on the Pico-W
Introduction to the Tutor, Dr Jon Durrant.
The course approach, structure and resources to help you learn.
Section summary and resources.
The goals for this section:
Raspberry PI Pico Setup
SDK and Code Deployment
MQTT Broker Service
First Pico-W Thing
Setting up the Pico-W with header pins and the SDK.
A reminder of the two approaches available to copy binary code onto the Pico-W.
The course code repository is on GitHub. Its structure and how to download it.
We will require an MQTT Broker to get IoT devices to connect. Introducing the concept of a broker.
How to install a local MQTT Broker on a Raspberry PI 4.
How to use the Flespi as a cloud-hosted MQTT BRoker.
A first example IoT Thing built out to run against the broker and control an LED.
Section Summary and Resources.
Goals of this section are to explain the features of MQTT and the Software Stack this course will build.
MQTT originated in 1999 and is now a common IoT device protocol. This lecture looks at the features of MQTT.
To operate MQTT on the Pico-W we require a software stack that will handle the messaging. Ontop of this stack can sit our application. This lecture outlines the stack we will spend the rest of the course building.
Quiz on MQTT and the Software Stack for the Pico-W
This section is all about establishing a connection:
Wifi Connection
Socket Transport
MQTT Connection or Session
Connecting Raspberry PI Pico to a WIFI SSID.
Establishing an MQTT session using coreMQTT-Agent
The goals of this section are to be able to publish.
MQTT Topic Space that we will publish into
Listen in Python to the Pico-W publish a message
Publish using coreMQTT-Agent:
Lifecycle Message when Pico-W connects
LED Status
MQTT publishes messages to topics. Topics form a hierarchical space.
To show we have published we need a listener. For this section, we will listen from a Python test script.
MQTT does not produce any message on a device first connecting to the broker. In this lecture we add to the framework to publish a message each time we connect.
We attach a switch and LED to the Pico-W so that pushing the switch changes the state of the LED (on to off). Then publish the state of the LED over MQTT.
Section Summary and Resources.
This section is all about subscribing and receiving messages on the Pico-W.
Publish and control from Python
Look at coreMQTT-Agent Subscribe Feature
Explore group of Pico-W devices communicating
We need to be able to send messages to our Pico-W IoT device. We will once again use Python to provide these test scripts.
To enable subscription we will need to extend our framework by:
Wrapping the Subscribe Function
Handle Subscription Call-back
Handle Incoming Data Call-back
This lecture explores the design for extending our framework before we get into an example in the next lecture.
This example extends are latched LED device to be remotely controllable over MQTT.
In this example, we will use two Pico-W both operating as latched LED lights. We will make the switch on either device to control both devices at once.
This section will look at the concepts of security for MQTT.
Transport
Authentication
MQTT Topic Space Authorization
Audit Logging
Securing the transport layer.
Building a TLS transport layer using WolfSSL and testing with HTTP GET.
Updating the IoT framework to secure the MQTT session over a TLS socket.
Importance of authentication to identify the client device.
Authorising access to the topic space for the clients.
Audit log to identify unusual behaviour for debugging and security assessment.
A quick quiz on security concepts.
Section Summary
This section explores how the state of our device is actually a generalised problem and can have a general interface.
State Problem
Digital Twin Concept
State for Pico-W
This lecture generalises the concept of state for our sensor or controller devices. How a digital twin service might help us manage these devices.
This section explores one way of extending our framework to manage the state in a general way. You could do this in lots of other ways.
Congratulations on completing the course. Please leave a positive review on Udemy and get in touch to tell me how you are putting the knowledge to use.
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.