BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Unable to get the print statement on when the value is 1

#1

this is the code am writing to turn on the switch on and off but here unable to get the print statement on when the value is 1 everytime only the off statement is getting print at any situation

# !/usr/bin/python



import RPi.GPIO as GPIO

import blynklib

import time



GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(2, GPIO.OUT)



auth_token = "Blynk Auth Code Here"



# Initialize Blynk



def write_handler_pin_handler(pin, value):

    switch = (format(value[0]))

    if switch == 1:

        print("On")

    else:

        print("Off")

   

try:

    while True:

        blynk.run()

       

except KeyboardInterrupt:

    print("Quit")



# Reset GPIO settings

GPIO.cleanup()
0 Likes

Problem with Raspberry Pi 3 blynk for python
#2

Take a look at my code here…https://community.blynk.cc/t/server-code-communication-issue-python/35703/3

0 Likes

#3

@aravind.doha I moved your post into your own topic as the one you put your “me too” into was almost a year old.

I also properly formatted your code as required in the Welcome Topic… please read it thoroughly.

0 Likes

#4

i have rectified issue…i would like to join your team.

frankly speaking am not a experienced developer but like to learn more. if possible let me know if you have any project in python where i can help you

0 Likes

#5

How?

Aside from the actual Blynk Development team, we are all Blynk users and forum volunteers here, so feel free to assist with any Python related topics that pop up.

0 Likes

#6

its was a typo error instead of if value ==“1” i had mentioned value ==1 if statement

1 Like

#7

rectified and solved code

import RPi.GPIO as GPIO

import blynklib

import time



GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(2, GPIO.OUT)



auth_token = "Blynk Auth Code Here"



# Initialize Blynk



def write_handler_pin_handler(pin, value):

    switch = (format(value[0]))

    if switch == "1":
        GPIO.output(2,GPIO.HIGH)
        print("On")

    else:
        GPIO.output(2, GPIO.LOW)
        print("Off")

   

try:

    while True:

        blynk.run()

       

except KeyboardInterrupt:

    print("Quit")



# Reset GPIO settings

GPIO.cleanup()
0 Likes

#8

will i able to post the code in my GITHUB

0 Likes

#9

Again!! Please properly format all posted code, else it looks bad…

Read the Welcome Topic I posted above!!!

0 Likes

#10

Please find the solved code

import RPi.GPIO as GPIO

import blynklib

import time


GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(2, GPIO.OUT)

auth_token = "Blynk Auth Code Here"

# Initialize Blynk

def write_handler_pin_handler(pin, value):

    switch = (format(value[0]))

    if switch == "1":
        GPIO.output(2,GPIO.HIGH)
        print("On")

    else:
        GPIO.output(2, GPIO.LOW)
        print("Off")

try:

    while True:

        blynk.run()

    
except KeyboardInterrupt:

    print("Quit")



# Reset GPIO settings

GPIO.cleanup()

1 Like