How to fetch data from dweet.io using Python (Tutorial)

Disclosure: Some of the links in this post are affiliate links. This means that, at zero cost to you, Learn Robotics will earn an affiliate commission if you click through the link and finalize a purchase. Learn Robotics is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a way for websites to earn advertising revenues by advertising and linking to Amazon.com.

Table of Contents

For this tutorial, I’m going to walk you through the process of fetching data from dweet.io using Python.

Fetch Data from dweet.io using Python

dweet.io is a website that is similar to twitter but for connected devices. You can access sensor readings through a dweet.io URL in a JSON format. We will use this website to fetch data using a Python script.

Before we begin, I recommend that you have some prior knowledge of Python. We’ll be using Python3 for this lesson, but the libraries for this exercise work with previous releases of Python.

If you don’t know Python or aren’t familiar with dictionaries, loops, syntax, or connecting to webpages to retrieve data, then I recommend taking an introductory Python class before trying this tutorial. Feel free to try this tutorial out if you have some experience with Python. Just know that I won’t be covering common syntax or explaining every detail.

I’ve linked to the Python for Everybody webpage. This material is also offered on Coursera as a 5-class specialization. You can also take the Complete Python Bootcamp on Udemy. I highly recommend taking one of these courses if you want a thorough understanding of the fundamentals of Python.

Setup & Configuration

I’ve listed all the things you’ll need to complete this project.

You’ll need to code on a laptop computer (Mac, Windows, or Linux). You won’t be able to complete this project using a tablet or iPad.

Install Python on your computer. (Windows Tutorial | Mac Tutorial)

You’ll also be prompted to install a text editor for Python. Feel free to choose whatever text editor you like. I recommend Atom.io or Sublime Text. This tutorial will be showing you screenshots from Atom.io

Download the dweepy repository from Github. Follow the instructions in the README to setup dweepy.

Getting started with dweet.io

The dweet.io website gives you the option to have public (unlocked) or private (locked) devices. All of the unlocked devices are listed on the Discover page. We will be using a random unlocked device for this tutorial. You have the option when you’re developing your own devices to lock or unlock them. Locks are $1.99/mo and will keep your sensor data private.

Since we are just fetching data, we won’t need any actual hardware configured. You can learn how to send data to dweet.io with a Wemos D1 Mini (ESP8266) in this tutorial.

Navigate to the Discover Page on dweet.io

Your list of devices will vary from the screenshot below. Select one that has a few streams. I’m going to choose the “theBHVbooktemper2017” thing and capture Temperature & Humidity data.

fetch data from dweet.io using Python

Next, click on the name of the thing. It will open up a webpage and show you recent data.

fetch data from dweet.io using Python

Create the retrieve.py script to fetch data from dweet.io

Navigate to the folder where you installed the dweepy repository. Open up the dweepy folder and create a new Python script. Your Python file must be located inside the dweepy Github folder or you’ll receive an error when you run the script. I’ve called mine “retrieve.py”

We’re going to use the features of the dweepy repository to connect to theBHVbooktemper2017 and fetch these readings.

The script will work by prompting the user for a thing name. Next, we will use the dweepy repository to connect to the URL on dweet.io to obtain readings as a JSON file.

We can then parse the JSON using key-value pairs (from dictionaries) in Python. Lastly, we’ll print these readings in Terminal for the user to see. Here’s what you get once it’s all setup!

fetch data from dweet.io using Python

Code walk-through video

Since this code is simple enough to replicate, I’ve compiled a code walk-through video. Use this to gather inspiration for your solution! You can also download a copy of the example code below!

Here’s your download! Download retrieve.py example file

If you like these types of videos, be sure to subscribe to the Learn Robotics YouTube Channel

Next Steps

In the next tutorial, I’m going to show you how to log data from dweet.io into a local database.

If you liked this article, be sure to share it with a friend! And as always, if you have any questions, drop them below!

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Wait,

Learn Robotics Online
— Get 2 months free!

Exclusive Limited Offer for Serious Beginners Ready to take their Hobby to Engineering Internships, $100k+ Careers, and Beyond!

Enroll now, and earn your first robotics certificate in the next 7 days.

👇 Click below to claim this deal.