Skip to content
PSUT / IoTEngineering learning studio
WORKSPACE
Offline-first portalDr. Mohammad Alja’afreh
Connected Networks StudioNetworking and CommunicationExperimentsWorkspaces
ThingSpeak credential and response checks

Use the channel Write API Key for writes; a private readback needs the channel Read API Key and numeric channel ID. Hidden input displays no characters. A positive entry ID confirms acceptance; zero or an HTTP error does not. Wait 20 seconds between writes; do not share keys or disable TLS verification.

ENGINEERING WORKSPACE
Home/Engineering Workspaces/ThingSpeak Cloud Studio
PSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
Cloud integration · real HTTPS
Supporting engineering workspace

ThingSpeak Cloud Studio

From simulated DHT22 or Arduino telemetry to a private cloud channel, real charts and optional local Node-RED visualization.

Open ThingSpeak ↗

01 · Create the channel in your Windows browser

  1. Sign in to ThingSpeak with your MathWorks account.
  2. Channels → My Channels → New Channel. Name the channel IoT Studio DHT22.
  3. Enable Field 1 (Temperature, °C) and Field 2 (Humidity, %). Save Channel. Keep it private.
  4. Open API Keys. Locate the Write API Key, Read API Key and numeric Channel ID. Do not paste keys into the tutor or website.
  5. Open Private View. The field charts populate only after accepted writes.

Use one writer per channel and wait at least 20 seconds between writes for this lab. The free-license minimum is 15 seconds. MathWorks channel documentation.

02 · Interactive cloud pipeline

Browser model only: no network requests, API keys or real uploads. Change inputs, send an entry and see field history and the readback state.

03 · Upload real data from WSL (X9)

Complete Setup first. Open VS Code Remote WSL. Use the WSL Bash terminal, not Python REPL. The sensor is mock; HTTPS is real. Keep this terminal open until the third upload completes.

Ubuntu WSL · Bash

WSL · Bash (copy into the WSL terminal)

source ~/psut-wsl/activate.sh
cd ~/psut-wsl/labs/pi-practical
unset THINGSPEAK_WRITE_KEY
python -m labs.exp09.upload --mock --count 3 --interval 20
✓ Expected: Three synthetic readings are submitted at the service interval; verify positive entry IDs and channel records.

Expected: positive entry IDs, mock provenance and two populated charts. Zero or a printed failure is not an accepted upload.

04 · Retrieve the most recent entry (X10)

Use a separate WSL Bash terminal. Enter the numeric channel ID and hidden read key when prompted.

Ubuntu WSL · Bash

WSL · Bash (copy into the WSL terminal)

source ~/psut-wsl/activate.sh
cd ~/psut-wsl/labs/pi-practical
read -rp "Numeric channel ID: " THINGSPEAK_CHANNEL
export THINGSPEAK_CHANNEL
read -rsp "ThingSpeak Read key: " THINGSPEAK_READ_KEY; echo
export THINGSPEAK_READ_KEY
python -m labs.exp10.download
✓ Expected: Channel entries are retrieved and printed; an empty channel may contain no records yet.
Expected result for each action (7)
  1. source ~/psut-wsl/activate.shThe toolkit virtual environment is selected in this terminal, usually with (.venv) in the prompt. Verify which python points into ~/psut-wsl/.venv.
  2. cd ~/psut-wsl/labs/pi-practicalNormally no output. pwd should show the requested directory. A missing path produces an error; do not continue until corrected.
  3. read -rp "Numeric channel ID: " THINGSPEAK_CHANNELThe shell prompts for the requested value and waits for Enter. Use the actual channel ID or path, not an example placeholder.
  4. export THINGSPEAK_CHANNELUsually silent. The variable is inherited by child processes launched from this terminal; never print a secret to verify it.
  5. read -rsp "ThingSpeak Read key: " THINGSPEAK_READ_KEY; echoA secret-entry prompt appears; typing is not echoed. Enter only your local lab credential. Nothing should expose its value.
  6. export THINGSPEAK_READ_KEYUsually silent. The variable is inherited by child processes launched from this terminal; never print a secret to verify it.
  7. python -m labs.exp10.downloadChannel entries are retrieved and printed; an empty channel may contain no records yet.

Compare entry ID and timestamp with Private View. Empty channels must first receive an accepted write.

05 · Visualize ThingSpeak readback in local Node-RED

Complete Node-RED & MQTT local setup, import the local flow once and deploy. This optional read-only bridge retrieves actual cloud records and republishes them on the local practical topic. It accepts only records explicitly labelled mock or fakepi by the supplied X9 uploader. It never uses HiveMQ or forwards keys. Use X9 rather than temperature-only P36 or P39 entries.

Ubuntu WSL · Bash

WSL · Bash (copy into the WSL terminal)

source ~/psut-wsl/activate.sh
source ~/.config/psut-wsl/mqtt-local.env
read -rp "Numeric channel ID: " THINGSPEAK_CHANNEL
export THINGSPEAK_CHANNEL
read -rsp "ThingSpeak Read key: " THINGSPEAK_READ_KEY; echo
export THINGSPEAK_READ_KEY
python ~/psut-wsl/tools/thingspeak_bridge.py --count 6 --interval 20
✓ Expected: The bridge retrieves channel entries and publishes eligible new records; check matching MQTT subscriber and source label.
Expected result for each action (7)
  1. source ~/psut-wsl/activate.shThe toolkit virtual environment is selected in this terminal, usually with (.venv) in the prompt. Verify which python points into ~/psut-wsl/.venv.
  2. source ~/.config/psut-wsl/mqtt-local.envThe local MQTT profile is loaded silently. Verify host 127.0.0.1, port 1884 and the matching topic in this shell.
  3. read -rp "Numeric channel ID: " THINGSPEAK_CHANNELThe shell prompts for the requested value and waits for Enter. Use the actual channel ID or path, not an example placeholder.
  4. export THINGSPEAK_CHANNELUsually silent. The variable is inherited by child processes launched from this terminal; never print a secret to verify it.
  5. read -rsp "ThingSpeak Read key: " THINGSPEAK_READ_KEY; echoA secret-entry prompt appears; typing is not echoed. Enter only your local lab credential. Nothing should expose its value.
  6. export THINGSPEAK_READ_KEYUsually silent. The variable is inherited by child processes launched from this terminal; never print a secret to verify it.
  7. python ~/psut-wsl/tools/thingspeak_bridge.py --count 6 --interval 20The bridge retrieves channel entries and publishes eligible new records; check matching MQTT subscriber and source label.

Open local Node-RED dashboard and select the ThingSpeak device. A repeated entry ID is skipped during the run; start X9 in another terminal for new readings. Node-RED timestamps represent reception, while the bridge prints the original entry ID. Ctrl+C stops polling. No extra cloud writes occur.

06 · Related laboratories

P34 uploads two sensor fields once; P36 uses Arduino serial temperature only; P39 demonstrates HTTPS over TCP with a fixed test value; X9 and X10 provide the complete labelled upload/readback route. Use separate channels for different schemas.

Troubleshoot in order

  1. Check WSL internet and DNS. Run curl -I https://api.thingspeak.com (no keys).
  2. Confirm the channel and correct key type. If entry 0, wait and retry once.
  3. Inspect Private View before Node-RED; an accepted HTTP write does not prove the bridge ran.
  4. For dashboard issues verify the local MQTT profile, bridge output and Accepted/Rejected telemetry Debug nodes.