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

Avatar

Please consider registering
Guest

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
LDR values not being updated to Thingspeak channel
No permission to create posts
November 30, 2017
3:19 pm
Avatar
tia
New Member
Members
Forum Posts: 1
Member Since:
November 30, 2017
sp_UserOfflineSmall Offline

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:
41 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:

JustinaAnoks, JerilynDernnida, JaketripDernnida, KenterDernnida, AlisaMiz, AriurinDernnida

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457