Python code not working

from boltiot import Bolt
api_key=“xxxxxxxxxxxxxxxxxxxxxx”
device_id=“xxxxxxxxxxxx”
mybolt=Bolt(api_key,device_id)
a= input()
if a==1:
responce=mybolt.digitalWrite(‘0’,‘HIGH’)
print(responce)
else:
responce=mybolt.digitalWrite(‘0’,‘LOW’)
print(responce)
print(a)
why the code is not working.

Hi @subhamruhela13

You should not share your API key, because anyone can access your device. So, dont share like this. Once check your code and try again. Can you share the output or what is error.

1 Like

Hi @subhamruhela13,
Check 7, 8, 10, 11 lines. Try using response instead of responce. Also check for the spaces to be given. Input your api key and device ID in the fourth line of your code.

The syntax is as follows:

For LED to switch on:

from boltiot import Bolt
api_key = “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”
device_id = “BOLTXXXXX”
mybolt = Bolt(api_key, device_id)
response = mybolt.digitalWrite(‘0’, ‘HIGH’)
print (response)

To switch off LED:

from boltiot import Bolt
api_key = “XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”
device_id = “BOLTXXXXX”
mybolt = Bolt(api_key, device_id)
response = mybolt.digitalWrite(‘0’, ‘LOW’)

api_key=“xxxxxxxxxxx”
device_id=“BOLTxxxxxx”
mybolt=Bolt(api_key,device_id)
a= input()
a=int(a)=>add this line
if a==1:
responce=mybolt.digitalWrite(‘0’,‘HIGH’)
print(response)
else:
response=mybolt.digitalWrite(‘0’,‘LOW’)
print(response)
print(a)
try this output will come
@subhamruhela13

1 Like

Code is working fine. but led does not giving responce.

Hi @subhamruhela13

Can you attach the screenshot of the output response? It will be clear.

You can also just put
a==“1”
the output will come

it will not turn on the led just gives output

Ohh… The code is correct as it worked on my controller, I used it for buzzer actually. Try checking if the code is entering the “if and else statements” by putting print statements. If not then I guess probably some hardware issue, try running some other code on the same pin like controlling LED project 3.