I have connected my galaxy on7 with Raspberry pi zero's bluetooth onboard.i could connected pi with my phone. In my phone i installed blue term(terminal).The problem is not my code(python) running on my pi.

I get this error when I run the script:

File "bluetooth.py"

data = client_socket.recv(1024)
IndentationError:expected an indented block

Here is my code:

import bluetooth
import RPi.GPIO as GPIO
GPIO.setup(40, GPIO.OUT)

server_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)

port = 1
server_socket.bind(("", port))

client_socket, address = server_socket.accept()
print "Accepted connection from ", address
    while 1:
        data = client_socket.recv(1024)
        print "Received: %s" % data
        if (data == "0"):
            GPIO.output(40, 0)
        if (data == "1"):
            GPIO.output(40, 0)
    print("Cleaning Up!")
  • The error message say itself, your code is not indent correctly. – hcheung Apr 16 '18 at 7:59
  • I’d recommend you try using tab instead of spaces and to ensure you are consistent with indentation – Mohammad Ali Apr 18 '18 at 14:43
  • Python uses indents as part of its syntax. (peachpit.com/articles/article.aspx?p=1312792&seqNum=3) Your editor probably has an option to show tabs and spaces (so you can see where your tabs are and get rid of the weird one that's causing the syntax error). I know vim and emacs both have ways to represent tabs as a visible symbol – Hunter Akins Apr 25 '18 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.