D.I.Y: How to upload Your Raspberry Pi Sensor Data to Thingspeak Website


This tutorial is purely intended for beginners.

Every wondered how to create a web page where you can see your sensor data for your IoT project? There are plenty of options out there ranging from using your laptop or desktop device as the gateway to using an Esp8266 chip. Today I am going to tell you how to use your Raspberry Pi as a gateway device for uploading your sensor data on Thingspeak server.

Things needed:

  1. Raspbeery Pi
  2. Power Cable
  3. Wifi adapter or LAN connection to Raspbeery Pi

Step 1: Signup for Thingspeak

Go to www.thinspeak.com


Fig1. Thingspeak Website

Click on “Sign Up” option and complete the details


Fig2. Create user account

Step 2: Create a Channel for Your Data

Once you Sign in after your account activation, Create a new channel by clicking “New Channel” button


Fig3. Creating New Channel

After the “New Channel” page loads, enter the Name and Description of the data you want to upload

You can enter the name of your data (ex: Temperature) in Field1. If you want more Fields you can check the box next to Field option and enter the corresponding name of your data.


Fig4. New Channel settings

Click on “Save Channel” button to save all of your settings.


Fig5. Save settings for New Channel

I created two Fields, one is CPU Memory and one for CPU Temperature


Fig6. Creating field charts to display data

Step 3: Get an API Key

To upload our data, we need an API key, which we will later include in a piece of python code to upload our sensor data to Thingspeak Website.

Click on “API Keys” tab to get the key for uploading your sensor data.


Fig7. Copy the Write API Key of the channel

(Note: The advantage of using Thingspeak compared to Xively or any other websites is that the convenience of using Matlab Analysis and Matlab Visualizations. This is a good option especially if you are doing some kind of research projects)

Once you have the “Write API Key”. We are almost ready to upload our data, except for the python code.

Step 4: Modifying the Python Code

Go to https://github.com/sriharshakunda/Thingspeak_CPU_Python-Code

Download the code into your Raspberry Pi Home folder.

Open the CPU_Python.py file in a notepad.

Edit the line 19 by using CPU_Temp instead of temp.

Use your Write API Key to replace the key with your API Key

Save the file to overwrite changes


Fig8. Python Code for Uploading Data

Step 5: Assuming you have python 2.7 and proper python libraries, go to the folder where you copied the CPU_Python.py file

Type python2.7 CPU_Python.py file

If the code runs properly you should see “200 ok” and something like “58.30” (CPU temperature value)

In case if there are any errors uploading the data, you will receive “connection failed” message

Step 6: Check Thinspeak API and Confirm data transfer

Open your channel and you should see the temperature uploading into thinspeak website.


Fig9. CPU Temperature data displayed in Field Chart

(Image for reference only, not exact temperatures)

I will write about customizations and creating multiple field charts and uploading data from Arduino using Raspberry Pi as Gateway in the upcoming articles.

You can create a python script and run it when the raspberry pi starts. You can follow this instructable tutorial to try it.

In the next tutorial we will see how can we use Raspbeery Pi as gateway device to upload data from arduino to Thinspeak server using Python code.


  1. Where is your next tutorial on how can we use Raspbeery Pi as gateway device to upload data from arduino to Thinspeak server using Python code?

  2. Hello,

    Great work by you, i really appreciate this. can you please suggest me which python packages are required for this tutorial ? I’m totally new for all this cloud things.

    Thanks !

  3. Hi
    I tried this and ended up with following error. Can you help me to get through?

    Traceback (most recent call last):
    File “/home/pi/CPU_Python.py”, line 35, in
    File “/home/pi/CPU_Python.py”, line 19, in thermometer
    params = urllib.urlencode({‘field1’: CPU_Temp, ‘key’:key })
    NameError: global name ‘CPU_Temp’ is not defined

    • I just put “CPU_Temp” and “key” between double-quotations.
      The error disappeared BUT still I cannot see the result on thingspeak.com

  4. Hello. May I know when is your next tutorial on how can we use Raspberry Pi as gateway device to upload data from Arduino to Thingspeak server using Python code will be uploaded?

  5. where is that next tutorial for Raspbeery Pi as gateway device to upload data from arduino to Thinspeak server??? i require that for my project.


Please enter your comment!
Please enter your name here