Friday, April 3, 2015

IoT at, Python on RPi 2 to send data to Cloud

This example modify from my previous example of "Display Raspberry Pi CPU temperature graphically, using Python 2 with Matplotlib", add the function to send the temperature to cloud, doesn't require any setup or sign-up— just publish and go. is simple publishing and subscribing for machines, sensors, devices, robots, and gadgets (we just call them things). We call published messages ‘dweets’. It’s helpful to think of as a Twitter for things, in fact.

This example code run on Python 2, Raspberry Pi 2/Raspbian, get CPU temperature, plot the graph on local screen, and send to, with API like this:

Where helloRaspberryPi_RPi2_vcgencmd is my-thing-name. To view my thing online, visit:

Please notice that it is just a trial experience, not a completed example.

View on

view on Raspberry Pi 2

#$ sudo pip install requests
import requests
import os
import matplotlib.pyplot as plt
from drawnow import *

# This example send the core temperature of Raspberry Pi
# to, a IoT on Cloud.
# with name = helloRaspberryPi_RPi2_vcgencmd
# To check this dweet, visit here on browser
dweetIO = ""
myName = "helloRaspberryPi_RPi2_vcgencmd"
myKey = "measure_temp"

tempC = []


def plotTempC():
    plt.title('Raspberry Pi core temperture')
    plt.ylabel('Temp C')
    plt.plot(tempC, 'rx-', label='Degrees C')
    plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,26):
while True:

    ostemp = os.popen('vcgencmd measure_temp').readline()
    temp = (ostemp.replace("temp=", "").replace("'C\n", ""))

    #Send to Cloud,
    rqsString = dweetIO+myName+'?'+myKey+'='+str(temp)
    rqs = requests.get(rqsString)
    print rqs.status_code
    print rqs.headers
    print rqs.content

Create dashboards for things with
Read JSON using Java

Related example on Arduino:
Arduino Uno + Ethernet Shield send data to and

No comments: