LDR values not being updated to Thingspeak channel | Raspberry Pi | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





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

Register Lost password?
sp_Feed sp_TopicIcon
LDR values not being updated to Thingspeak channel
Avatar
tia
New Member
Forum Posts: 1
sp_UserOfflineSmall Offline
1
November 30, 2017 - 3:19 pm
sp_Permalink sp_Print

I have run the following program to read LDR values from the LDR connected to my Raspberry Pi 3 and send the data to my Thingspeak channel but no update is being made to the channel. I am using Python 2.7 on Raspbian.

 

#!/usr/local/bin/python#!/usr/local/bin/python

import sysimport RPi.GPIO as GPIO

from time import sleep import urllib2

myAPI= "Y1087HT5ECTD8U6P"
GPIO.setmode(GPIO.BOARD)
pin_to_circuit=7
def rc_time (pin_to_circuit):   

count=0   

GPIO.setup(pin_to_circuit, GPIO.OUT)   

GPIO.output(pin_to_circuit, GPIO.LOW)   

time.sleep(0.1)

GPIO.setup(pin_to_circuit, GPIO.IN)     

while(GPIO.input(pin_to_circuit) == GPIO.LOW):         

count +=1   

return count

try:   

while True:       

print rc_time(pin_to_circuit)

except KeyboardInterrupt:     

pass

finally:     

GPIO.cleanup()
def main():   

print 'starting...'   

baseURL= 'https://api.thingspeak.com/update?api_key=%s' % myAPI   

while True:

try:           

ldrData= rc_time(pin_to_circuit)    

f=urllib2.urlopen(baseURL + "&field1=%s" %(ldrData))       

print f.read()       

f.close()       

sleep(15)

except:    

print 'exiting.'    

break

#call main

if _name_=='__main__':  main()

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

donj51

trilee

Bfletche

stuartWAI

shivmkatiyar

AidanThing

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee