Uploading data from RPi SenseHat to Thingspeak via python script | Raspberry Pi | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Uploading data from RPi SenseHat to Thingspeak via python script
No permission to create posts
June 21, 2017
1:14 pm
New Member
Forum Posts: 1
Member Since:
June 21, 2017
sp_UserOfflineSmall Offline

Dear fellow coders, i'm trying to upload temperature data from my RPi sensehat -> Thingspeak channel. I copied the scripts from the internet and tried to integrate them together. I executed the Python script on Putty terminal, the printed temperature looks ok, hovering between 29-30 degrees C but when displayed on thingspeak, it shows up as werid numbers like 4 or 6 degrees C.

Greatly appreciate your advice! Thank you!


#!/usr/bin/env python


import httplib, urllib

import time

sleep = 3

key = '...'


def thermometer():


from sense_hat import SenseHat


sense = SenseHat()



tmax = 40

tmin = tmax - 8


while True:

temp = sense.get_temperature()

#-----rd off temp to 2 d.p.-----

temp = round(temp,2)


temp = int(temp) - tmin

for x in range(0, 8):

for y in range(0, temp):

sense.set_pixel(x, y, 255, 0, 0)

for y in range(temp, 8):

sense.set_pixel(x, y, 0, 0, 0)


params = urllib.urlencode({'field1': temp, 'key':key })

headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept": "text/plain"}

conn = httplib.HTTPConnection("api.thingspeak.com:80")



conn.request("POST", "/update", params, headers)

response = conn.getresponse()

print temp

print response.status, response.reason

data = response.read()



print "connection failed"



#sleep for desired amount of time

if __name__ == "__main__":

while True:





June 22, 2017
9:24 am

Forum Posts: 885
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

I think I see part of the problem.

Following these lines in your code:

tmax = 40

tmin = tmax - 8

Then tmin = 32.

temp = int(temp) - tmin #.....or temp=30 - 32

For temps such as 29-30, you would get a temp of -2 to -3 when you post to ThingSpeak.  This doesn't explain the values of 4 or 6, except if your variable type for temp is unsigned, but it explains some of the difference (rounding could explain more).  Generally ThingSpeak is pretty literal about what it does with your data, so I wouldn't usually look there if I see a wrong format of my data, as long as you get a success response after your post.

Good luck with your project!

June 23, 2017
2:24 am

Forum Posts: 279
Member Since:
January 29, 2014
sp_UserOfflineSmall Offline

I suspect the previous poster is correct- you are messing up the value of temp before you send it to thingspeak. Either save a copy of the variable or move the section where you send to thingspeak before you update the pixels.


If that doesnt work you could also try printing out the value of params to make sure you are sending what you think you are sending


print temp

print params

print response.status, response.reason

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
23 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

bogart, estebanmateo93, mikewrite, onlinebusiness, winzy99, Zark_zeugan

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457