Makecode Coding and Thinkspeak
Last updated
Last updated
When the IoT platform and hardware are ready, we can start coding with the Micro:bit.
The program can be divided into 3 parts:
Connecting to the Internet.
Connecting to the IoT Platform.
Main program.(Publish/Subscribe)
Robotbit was used when creating this tutorial, for Armourbit users, please refer to the instructions to modify the program.
Navigate to MakeCode’s page before continuing.
This section is about connecting the Wifibrick to the internet.
Select KittenWifi from the menu.
These blocks are needed to connect to the internet.
Create the following program.
Before moving on, it is recommended that you run this program once to ensure the module can connect to the Wifi network.
Follow the instructions to register for a ThingSpeak account.
ThingSpeakCreate a new channel.
Choose a name for your channel.
Other fields can be ignored, click Save Channel.
Open the Sharing tab.
Set the sharing settings to “Share channel view with everyone”.
The Access will change to “Public”.
Open the Devices menu, select MQTT.
Add a new device.
Select the channels accessible by this device and click Add Channel.
Click Add Device.
IMPORTANT! These MQTT Credentials are used for connecting to ThingSpeak! Please save or download the credentials as they can’t be seen after closing this page.
Build the following program and use these parameters to connect to ThingSpeak.
Host: mqtt3.thingspeak.com
ID: ThingSpeak Device Client ID
Username: ThingSpeak Device Username
Password: ThingSpeak Device Password
We need the Channel ID for publishing. The channel ID is displayed on the Channel page as a 7-digit number.
Build the following program to publish a data to ThingSpeak:
MQTT Topic: channels/[Channel ID]/publish
Message: field[field No.]=[Numeric Data]
On the ThingSpeak page, you can see the published data.
We can read the channel data by subscribing to the channel.
MQTT Topic: channels/[Channel ID]/subscribe/fields/field[field No.]
Press A to publish a message to the channel, Micro:bit will display the data received.
You are welcome to join our Whatsapp group to share your IoT projects!
There may be updates to extensions periodically, please refer to the following link to update/downgrade your extension.