First, log in to your Simuli account and navigate to the Simuli Virtual Lab. Here we will create a new emulated instance of the STM32. Click on the Launch button under STM32 to get started.
This will open the configuration menu. First, provide a name for the project. Then, we will add the W5500 Ethernet Module by selecting them from the list of available components. Finally, review that the name for the project and the selected sensors are correct and click on the Launch button.
Once we have clicked on the Launch button, a new instance of the STM32 will be created. It can take a few minutes, so be patient.
Now that our instance is being created, let's move forward to create an Adafruit IO account and configure it.
Adafruit IO
Go to the Adafruit IO website, if you already have an account, you can directly log in and skip to the configuration part. If this is your first time at Adafruit IO, click on the Get Started for Free button at the top. This will take you to a signup page, fill all the details and click on the CREATE ACCOUNT button.
Once the account has been created, go back to the Adafruit IO website. Let's start by creating our feeds. Feeds act as our MQTT topics, where we can either publish our data or subscribe to receive the data. In this case, we will create 1 feed, for publishing our real-time values.
Click on Feeds, and then click on view all . This will open up a list of all the feeds currently set up for our account. Let's create a feed named lock.
Click on the New Feed button, this opens up a pop-up, let's name the feed lock.
Now we will create a dashboard from which we will publish values. Click on Dashboards, and then click on view all . This will open up a list of all the dashboards currently set up for our account. Let's create a dashboard named keypad.
Click on the New Dashboard button, this opens up a pop-up, let's name the dashboard keypad.
Now click on the dashboard to set up a keypad. Click on the Settings button and click on Create New Block.
Click on Number Pad from the options available and then select the feed you want to subscribe the data to.
Once the keypad is configured, our Adafruit IO setup is complete. We will now set up our STM32.
Implementing the Smart Lock
The STM32 instances come with support for Platform IO Core (CLI). We will be using it for working on our projects. To know more about Platform IO Core (CLI) and the different commands go to the Platform IO documentation.
First, we need to initialize a new project using Platform IO. Let's create a new folder called Smart-Lock which will hold all our code related to the project and then open the newly created folder in the terminal. Use the following commands:
mkdir /workspace/Smart-Lock/
cd /workspace/Smart-Lock/
Now we will initialize a new project using Platform IO. Type the following command in the terminal:
pio project init --board nucleo_f411re
The pio project init command is used to initialize the project. Then we need to specify the board which we want to use with the --board flag.
Once the project init command has run successfully, we will see some new folders inside the Smart-Lock folder. We will store the files related to the project in the src folder.
Create a new file called main.cpp inside the src folder. This file will hold the code for the Smart Home Control program. Click on the main.cpp file to open it up in our code editor. Now, go to the Github link and paste the following code inside the main.cpp file.
In the above code, replace "yourusername" with your Adafruit IO username and "youradafruitiokey", with your Adafruit IO key which is present under My Key in Adafruit IO.
Before we can compile our code, we need to install a few libraries. First, let's search for the Adafruit MQTT library. Go to your terminal and type:
pio lib search Adafruit MQTT
Platform IO will now search for the relevant libraries and provide us with the results. Here we can see that we got the library we were looking for. We can see the Library ID at the top, in this case it is 1092. We will use this ID to install the library.
Type the following command in the terminal:
pio lib install 1092
This will install the Adafruit MQTT Library along with all of its dependencies. Now we need to install the Ethernet library. Follow the same steps as before to install it via Platform IO.
pio lib search Ethernet #This is optional
pio lib install872
Now we are ready to compile our code. Save the main.cpp file. We will again use Platform IO to compile our code. Go to your terminal and type the following command.
pio run
The first time this command is run, Platform IO will download and install the relevant framework and toolchains required for the STM32. This process will take a few seconds.
Now Platform IO will compile our code and output a firmware.bin file. We need to copy this firmware file from the .pio/build/nucleo_f411re to /workspace. Usually you would need to use the cp command, but we have created a custom command called load-firmware for ease of use. Just write the following command and the firmware.bin file will be copied to the workspace folder.
load-firmware
Once we have copied the firmware.bin file, all we need to do is to reset the STM32 by pressing the red button above the STM32.
After the reset, the STM32 will load the new firmware, now enter a 4 digit numerical password on the keypad if the password is correct it will print "Code Match" and switch ON a LED otherwise it will print "Code Unmatch" and switch OFF the LED.
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Reset your password
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
Check your email
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.