Unable to get the print statement on when the value is 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()

Take a look at my code here…https://community.blynk.cc/t/server-code-communication-issue-python/35703/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.

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

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.

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

1 Like

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()

will i able to post the code in my GITHUB

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

Read the Welcome Topic I posted above!!!

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