AttributeError: module 'thingspeak' has no attribute 'Channel' channel = thingspeak​.Channel(i​d=channel_​id, api_key=key)

In the example raspberry pi py script, which was working fine, now i am getting this error. Cant find any sililar issues on the net... any ideas peeps?
import thingspeak
import time
channel_id = 1231234 # PUT CHANNEL ID HERE
key = '123123123123' # PUT YOUR WRITE KEY HERE
pin = 4
def measure(channel):
try:
# write
response = channel.update({'field1': 2, 'field2': 1})
# read
read = channel.get({})
print("Read:", read)
except:
print("connection failed")
if __name__ == "__main__":
channel = thingspeak.Channel(id=channel_id, api_key=key)
while True:
measure(channel)
# free account has an api limit of 15sec
time.sleep(15)

2 Comments

Did you upgrade python or any of the libraries? Perhaps you introduced an incompatibility by doing so?
I dont think so, no idea what happended but have ditched 3 methods i found on the net for uploading data to thingspeak so far with no working. I have this working though -
#!/usr/bin/env python#
import time
import os, os.path
import urllib.request
import glob
def read_temp_raw(): # gets the temps one by one
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(): # checks the temp recieved for errors
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
# set proper decimal place for C
temp = float(temp_string) / 1000.0
# Round temp to 2 decimal points
temp = round(temp, 1)
return temp
sensorscount = (len(os.listdir('/sys/bus/w1/devices/'))-1) #count the sensors files in folder and minus one because one is not a sensor
sensorscountstr = str(sensorscount) #cast to string
print("total sensors detected = "+ sensorscountstr)
c1HEADER = ''
c2HEADER = ''
c1key = 'channel1key' # hotwater
c2key = 'channel2key' # heatpump
for sensor in range (1,sensorscount+1):
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[sensor-1]
device_file = device_folder + '/w1_slave'
print ("Sensor ID = " + device_file)
print (sensor)
temp = read_temp()
tempstr = str(temp)
print ("Temperature = " + tempstr)
URl='https://api.thingspeak.com/update?api_key='
if device_file == '/sys/bus/w1/devices/28-000003ebcdd4/w1_slave': #Hot water tank
c1HEADER = c1HEADER + '&field{}={}'.format(1,temp)
if device_file == '/sys/bus/w1/devices/28-000003eba675/w1_slave': # Pre Heat Tank
c1HEADER = c1HEADER + '&field{}={}'.format(2,temp)
if device_file == '/sys/bus/w1/devices/28-000003084a84/w1_slave': #solar flow
c1HEADER = c1HEADER + '&field{}={}'.format(3,temp)
if device_file == '/sys/bus/w1/devices/28-000003084d6d/w1_slave': #solar return
c1HEADER = c1HEADER + '&field{}={}'.format(4,temp)
if device_file == '/sys/bus/w1/devices/28-000003086fb0/w1_slave': #Buffer Tank Top
c2HEADER = c2HEADER + '&field{}={}'.format(1,temp)
if device_file == '/sys/bus/w1/devices/28-000003085f44/w1_slave': #Loops In
c2HEADER = c2HEADER + '&field{}={}'.format(2,temp)
if device_file == '/sys/bus/w1/devices/28-0000030856cd/w1_slave': #Well Loop IN
c2HEADER = c2HEADER + '&field{}={}'.format(3,temp)
if device_file == '/sys/bus/w1/devices/28-000003ebe23e/w1_slave': #Free Sensor
c2HEADER = c2HEADER + '&field{}={}'.format(4,temp)
if device_file == '/sys/bus/w1/devices/28-000003089184/w1_slave': #HP Out To Loops
c2HEADER = c2HEADER + '&field{}={}'.format(5,temp)
if device_file == '/sys/bus/w1/devices/28-000003087113/w1_slave': #UFH Flow
c2HEADER = c2HEADER + '&field{}={}'.format(6,temp)
if device_file == '/sys/bus/w1/devices/28-000003086434/w1_slave': # Buffer Out
c2HEADER =c2HEADER + '&field{}={}'.format(7,temp)
c1NEW_URL = URl+c1key+c1HEADER
c2NEW_URL = URl+c2key+c2HEADER
print("Channel 1 HOTWATER URL = " + c1NEW_URL)
print("Channel 2 HEATPUMP URL = " + c2NEW_URL)
with urllib.request.urlopen(c1NEW_URL) as response:
html = response.read()
htmlstr = str(html)
print("Response Channel 1 = " + htmlstr)
time.sleep(15)
with urllib.request.urlopen(c2NEW_URL) as response:
html = response.read()
htmlstr = str(html)
print("Response Channel 2 = " + htmlstr)

Sign in to comment.

Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Asked:

on 24 Nov 2021

Commented:

on 27 Nov 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!