import serial,time # Can be Downloaded from this Link # https://pypi.python.org/pypi/pyserial # Global Variables ser = 0 # Function to Initialize the Serial Port def init_serial(): COMNUM = 3 # Enter Your COM Port Number Here. global ser # Must be declared in Each Function ser = serial.Serial() ser.baudrate = 9600 ser.port = COMNUM -1 # COM Port Name Start from 0 # ser.port = '/dev/ttyUSB0' #If Using Linux # Specify the TimeOut in seconds, so that SerialPort # Doesn't hangs ser.timeout = 1 ser.open() # Opens SerialPort # print port open or closed if ser.isOpen(): print 'Open: ' + ser.portstr # Function Ends Here # Call the Serial Initilization Function, Main Program Starts from here init_serial() temp = ['AT+CWMODE=2\r'] for x in temp: # temp2=temp[x] ser.flushInput() ser.write(x)# Writes to the SerialPort print ('command sent'+ x) #y= ser.In_waiting #print(y) time.sleep(2) ser.flushOutput() if (ser.isOpen()): bytes = ser.readline() # Read from Serial Port print(bytes) # Print What is Read from Port '''cmd2= "AT+CWMODE=1\r" ser.write(cmd2) if (ser.isOpen()): bytes = ser.readline() # Read from Serial Port print(bytes) # Print What is Read from Port cmd3 = "AT+CWMODE?\r" ser.write(cmd3)''' if (ser.isOpen()): bytes = ser.readline() # Read from Serial Port print(bytes) # Print What is Read from Port # Ctrl+C to Close Python Window