|
1 |
| -# Raspberry Pi Pico Micropython ESP8266 Lib |
2 |
| -This is a Micropython Library from communicate with ESP8266 AT command using RaspberryPi-Pico |
| 1 | +# Raspberry Pi Pico Micropython ESP8266 Library |
| 2 | + |
| 3 | +[](lib-release) |
| 4 | +[](lib-release) |
| 5 | +[](lib-stars) |
| 6 | +[](lib-issues) |
| 7 | +[](lib-licence) |
| 8 | + |
| 9 | +## Description |
| 10 | +This is a Micropython Library for RaspberryPi-Pico to communicate with ESP8266 using AT command. |
| 11 | + |
| 12 | +## Hardware Connection |
| 13 | + |
| 14 | + |
| 15 | +## Getting Started with Examples |
| 16 | +The best way to learn **Raspberry Pi Pico Micropython ESP8266 Library** is to understand the examples. |
| 17 | +In the `examples` directory there are an example of complete a HTTP Get/Post Operation using ESP8266. |
| 18 | + |
| 19 | +### How to Use Library |
| 20 | +```python |
| 21 | +from machine import Pin |
| 22 | +from esp8266 import ESP8266 |
| 23 | +import time, sys |
| 24 | + |
| 25 | +print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |
| 26 | +print("RPi-Pico MicroPython Ver:", sys.version) |
| 27 | +print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") |
| 28 | + |
| 29 | +## Create On-board Led object |
| 30 | +led=Pin(25,Pin.OUT) |
| 31 | + |
| 32 | +## Create an ESP8266 Object |
| 33 | +esp01 = ESP8266() |
| 34 | + |
| 35 | +print("StartUP",esp01.startUP()) |
| 36 | +print("Echo-Off",esp01.echoING()) |
| 37 | +print("\r\n") |
| 38 | + |
| 39 | +''' |
| 40 | +Print ESP8266 AT comand version and SDK details |
| 41 | +''' |
| 42 | +esp8266_at_var = esp01.getVersion() |
| 43 | +if(esp8266_at_var != None): |
| 44 | + print(esp8266_at_var) |
| 45 | + |
| 46 | +''' |
| 47 | +set the current WiFi in SoftAP+STA |
| 48 | +''' |
| 49 | +print("WiFi Current Mode:",esp01.setCurrentWiFiMode() |
| 50 | + |
| 51 | +print("\r\n\r\n") |
| 52 | + |
| 53 | +''' |
| 54 | +Connect with the WiFi |
| 55 | +''' |
| 56 | +print("Try to connect with the WiFi..") |
| 57 | +while (1): |
| 58 | + if "WIFI CONNECTED" in esp01.connectWiFi("ssid","pwd"): |
| 59 | + print("ESP8266 connect with the WiFi..") |
| 60 | + break; |
| 61 | + else: |
| 62 | + print(".") |
| 63 | + time.sleep(2) |
| 64 | + |
| 65 | + |
| 66 | +print("\r\n\r\n") |
| 67 | +print("Now it's time to start HTTP Get/Post Operation.......\r\n") |
| 68 | + |
| 69 | +while(1): |
| 70 | + led.toggle() |
| 71 | + time.sleep(1) |
| 72 | + |
| 73 | + ''' |
| 74 | + Going to do HTTP Get Operation with www.httpbin.org/ip, It return the IP address of the connected device |
| 75 | + ''' |
| 76 | + httpCode, httpRes = esp01.doHttpGet("www.httpbin.org","/ip","RaspberryPi-Pico", port=80) |
| 77 | + print("------------- www.httpbin.org/ip Get Operation Result -----------------------") |
| 78 | + print("HTTP Code:",httpCode) |
| 79 | + print("HTTP Response:",httpRes) |
| 80 | + print("-----------------------------------------------------------------------------\r\n\r\n") |
| 81 | + |
| 82 | + |
| 83 | + ''' |
| 84 | + Going to do HTTP Post Operation with www.httpbin.org/post |
| 85 | + ''' |
| 86 | + post_json="abcdefghijklmnopqrstuvwxyz" #"{\"name\":\"Noyel\"}" |
| 87 | + httpCode, httpRes = esp01.doHttpPost("www.httpbin.org","/post","RPi-Pico", "application/json",post_json,port=80) |
| 88 | + print("------------- www.httpbin.org/post Post Operation Result -----------------------") |
| 89 | + print("HTTP Code:",httpCode) |
| 90 | + print("HTTP Response:",httpRes) |
| 91 | + print("--------------------------------------------------------------------------------\r\n\r\n") |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +## Contributing |
| 98 | +You are very welcome to contribute: stability bugfixes, new hardware support, or any other improvements. Please. |
| 99 | +[](lib-stars) |
| 100 | +[](lib-network) |
0 commit comments