GithubHelp home page GithubHelp logo

willee / esp8266_at_cmd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miraenator/esp8266_at_cmd

0.0 2.0 0.0 12 KB

A simple python3 library for working with ESP8266 AT commands

License: MIT License

Python 100.00%

esp8266_at_cmd's Introduction

ESP8266_AT_cmd

A simple python3 library for working with ESP8266 AT commands

Command reference: https://room-15.github.io/blog/2015/03/26/esp8266-at-command-reference/

I've recently acquired the ESP8266 ESP-201 module... And found manually entering the AT commands fatiguing.

Therefore I tried to make a python3 library.

So far it works under Linux only and still did not manage to connect to an AP (client mode). (TODO)

Problems:

  • Upon start the module tries to connect, spontaneously resets multiple times (?power issue)
  • AT+RST resets multiple times, outputs a lot of garbage
  • AT+CWLAP hangs sometimes (after AT+CWJAP?), maybe: http://www.esp8266.com/viewtopic.php?f=6&t=571

Connection

ESP-201

Serial connection (PC(USBtoSerial) <--> ESP8266): 3.3V, GND, RX-TX, TX-RX
Chip enable (ESP8266): CHIP_EN -> 3.3V
Boot flom flash (ESP8266): GPIO15 (IO15) -> GND

ESP-01

Serial connection (PC(USBtoSerial) <--> ESP8266): 3.3V, GND, RX-TX, TX-RX
RESET (ESP8266): 3.3 V

Power supply

Power supply: Used second USBtoSerial to supply more power (needs around 300-400mA peak). Some resources state that Arduiono/USBtoSerial does not provide enough power.

For me worked the speed of 115200 baud, some people reported speeds like 9600, 86400, 57600, ...

Info about the connection (from the serial.Serial object):

Serial: (port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)

Example code

Make sure you are not connected via minicom, or any other. (I.e. the /dev/ttyUSBX is not used by any other program)

Autodetect the ttyUSB device

import ESP8266_ESP201
from time import sleep

e = ESP8266_ESP201.ESP8266_ESP201()
if e.find_device():
  print("----------AT------------")
  print(e.cmd_at())
  print("----------VERSION----")
  print(e.get_version())
  print("---------WIFI MODE-----")
  mode = e.get_wifi_mode()
  
else: 
  print("No ttyUSB devices found...")

Use your own device

Without this lib

You can use it as a simple test for your device.

import serial

with serial.Serial(port="/dev/ttyUSB0", baudrate=115200) as ser:
    if ser.isOpen():
        ser.write(b'AT\r\n')
        ser.readline()  #Echoed command 
        ser.readline()  #empty line
        ser.readline()  #response, should be OK/ERROR

With this lib

import serial
ser = serial.Serial(port="/dev/ttyUSB0", baudrate=115200)
ser.isOpen()
# Should output: True

import ESP8266_ESP201
e = ESP8266_ESP201.ESP8266_ESP201(serial_dev = ser)
e.cmd_at()
# Should output: {'status': True, 'data': []}

Using minicom

Use after typing the command (without Enter). Or and .

minicom -b 115200 -D /dev/ttyUSB0
AT<Ctrl-m><Ctrl-j>

#<Ctrl-A> <X> to exit

Installation (Debian Jessie)

# Install packages (under root)
sudo apt-get install python3 python3-serial
sudo apt-get install git

# Clone the repository
git clone https://github.com/miraenator/ESP8266_AT_cmd.git

# Change the dir and run the example
cd ESP8266_AT_cmd
python3 test_esp8266.py

# Alternatively, you can set the execution permission
chmod u+x ./test_esp8266.py
# and from then you can run it as an executable file
./test_esp8266.py

esp8266_at_cmd's People

Contributors

miraenator avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.