brendan-myers/rpi3-wifi-conf

NameError: name 'BluetoothSocket' is not defined

syrj2112 opened this issue · 5 comments

For some reason when trying to replicate your code, I run across this error at the of the code.
File "test2.py", line 122, in
server_sock=BluetoothSocket( RFCOMM )
NameError: name 'BluetoothSocket' is not defined
Can you enlighten me on why this is occuring when trying to run this code.

BluetoothSocket is part of the bluetooth package that's imported at the start of the script.

It'll make it easier to help if you could answer a few questions;

  • Have you installed the blutooth package? (sudo apt-get install python-bluez) You can check with pip freeze)
  • Which version of python are you using? (python --version)
  • Have you changed anything in the code? You've copied the code into a new file (test2.py), and the line number is different than what's in the repo (122 instead of 124, although, my whitespacing is a bit messy in that script!)

When I run the command pip freeze, I get the following list:
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Pillow==2.6.1
PyBluez==0.18 <----------------------------------------------------------- Is this the correct package?
RPi.GPIO==0.6.3
RTIMULib==7.2.1
Werkzeug==0.9.6
argparse==1.2.1
blinker==1.3
chardet==2.3.0
colorama==0.3.2
gpiozero==1.3.1
html5lib==0.999
itsdangerous==0.24
lxkeymap==0.1
mcpi==0.1.1
ndg-httpsclient==0.3.2
numpy==1.8.2
pbkdf2==1.3
picamera==1.12
picraft==1.0
pifacecommon==4.2.1
pifacedigitalio==3.1.0
pigpio==1.35
pyOpenSSL==0.13.1
pyasn1==0.1.7
pygame==1.9.2a0
pygobject==3.14.0
pyinotify==0.9.4
pyserial==2.6
python-apt==0.9.3.12
requests==2.4.3
rpi-ws281x==1.0.0
sense-emu==1.0
sense-hat==2.2.0
six==1.8.0
smbus==1.1
spidev==3.0
twython==3.1.2
urllib3==1.9.1
wheel==0.24.0
wifi==0.3.8
wsgiref==0.1.2

I'm not sure if included all the other packages is necessary but maybe there are packages that are cancelling each other out or something.

The version of python I am current using is Python 2.7.9

I got the error just from copying and pasting the code into python, script but I have made a couple different files and made some modifications to see if they would fix it but no luck.

That's the version I have installed. Hmmm.

2 things to try next;

  1. Run through all the steps in the readme again, to double check that everything is installed/setup properly.
  2. Open a python shell, import bluetooth, and double check that the bluez package is definitely being imported.
>>> import bluetooth
>>> bluetooth
<module 'bluetooth' from '/usr/lib/python2.7/dist-packages/bluetooth/__init__.pyc'>

Also, are you running Raspian, and if so, which version?

For some strange reason, i simply made a copy of my sample rfcomm-server.py file and implemented the wifi code into that and everything works just fine now. I'm not sure what was causing the error but it is working now like a charm! Thumbs up for the awesome code. Quick question, is there any way to modify the code to check if a config being sent is already stored?

Weird. Did you have to reinstall the bluez package?

is there any way to modify the code to check if a config being sent is already stored?
You could implement it a number of different ways. I'm not sure why you'd want to though, as the app sends both the ssid and psk.

I don't think we've solved the problem, but as you're not having the problem anymore. I'll close the issue.