Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fedede

Browse filesBrowse files
committed
Initial Commit
0 parents  commit 8fedede
Copy full SHA for 8fedede

File tree

Expand file treeCollapse file tree

5 files changed

+279
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+279
-0
lines changed

‎.gitignore

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.ipynb_checkpoints

‎LICENSE

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Seyyed Mohammad Hossein Nabavi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎esp8266-serial.ipynb

Copy file name to clipboard
+91Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from serial import Serial"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"router_SSID, router_PASSWORD=\"********\", \"********\" # Router Wi-Fi information\n",
19+
"module_SSID, module_PASSWORD=\"ESP8266\", \"12345678\" # Module Wi-Fi information\n",
20+
"PORT, BAUDRATE= 'COMx', 115200 # Serial information\n",
21+
"serial = Serial(PORT, BAUDRATE)"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 3,
27+
"metadata": {},
28+
"outputs": [
29+
{
30+
"name": "stdout",
31+
"output_type": "stream",
32+
"text": [
33+
"Now you can connect to ESP8266 module with TCP connection at: 192.168.203.136\n"
34+
]
35+
}
36+
],
37+
"source": [
38+
"serial.write(b'AT+RST\\r\\n')\n",
39+
"serial.read_until(b'ready\\r\\n')\n",
40+
"serial.write(b'AT\\r\\n')\n",
41+
"serial.read_until(b'OK\\r\\n')\n",
42+
"serial.write(b'AT+CWMODE=3\\r\\n')\n",
43+
"serial.read_until(b'OK\\r\\n')\n",
44+
"serial.write(f'AT+CWSAP=\"{module_SSID}\",\"{module_PASSWORD}\",5,4\\r\\n'.encode())\n",
45+
"serial.read_until(b'OK\\r\\n')\n",
46+
"serial.write(f'AT+CWJAP=\"{router_SSID}\",\"{router_PASSWORD}\"\\r\\n'.encode())\n",
47+
"serial.read_until(b'OK\\r\\n')\n",
48+
"serial.write(b'AT+CIPMUX=1\\r\\n')\n",
49+
"serial.read_until(b'OK\\r\\n')\n",
50+
"serial.write(b'AT+CIPSERVER=1,80\\r\\n')\n",
51+
"serial.read_until(b'OK\\r\\n')\n",
52+
"serial.write(b'AT+CIPSTA?\\r\\n')\n",
53+
"ip_result = serial.read_until(b'OK\\r\\n').decode().split('\"')[1]\n",
54+
"print(f'Now you can connect to ESP8266 module with TCP connection at: {ip_result}')"
55+
]
56+
},
57+
{
58+
"cell_type": "markdown",
59+
"metadata": {},
60+
"source": [
61+
"#### Local ip: 192.168.4.1"
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "Python 3 (ipykernel)",
68+
"language": "python",
69+
"name": "python3"
70+
},
71+
"language_info": {
72+
"codemirror_mode": {
73+
"name": "ipython",
74+
"version": 3
75+
},
76+
"file_extension": ".py",
77+
"mimetype": "text/x-python",
78+
"name": "python",
79+
"nbconvert_exporter": "python",
80+
"pygments_lexer": "ipython3",
81+
"version": "3.10.4"
82+
},
83+
"vscode": {
84+
"interpreter": {
85+
"hash": "3f74628874e72a69f25fba1beeb97e633df0f5a9e3b9a803942cc96884bee9ff"
86+
}
87+
}
88+
},
89+
"nbformat": 4,
90+
"nbformat_minor": 2
91+
}

‎esp8266-socket.ipynb

Copy file name to clipboard
+106Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "3e37b3ed",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from socket import socket as Socket"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"id": "b2944d37",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"HOST, PORT = '192.168.4.1', 80\n",
21+
"socket = Socket()"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": 3,
27+
"id": "c28fd5b4",
28+
"metadata": {},
29+
"outputs": [
30+
{
31+
"data": {
32+
"text/plain": [
33+
"5"
34+
]
35+
},
36+
"execution_count": 3,
37+
"metadata": {},
38+
"output_type": "execute_result"
39+
}
40+
],
41+
"source": [
42+
"socket.connect((HOST, PORT))\n",
43+
"socket.send(f'salam'.encode())"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 4,
49+
"id": "ed0af248",
50+
"metadata": {},
51+
"outputs": [
52+
{
53+
"data": {
54+
"text/plain": [
55+
"1"
56+
]
57+
},
58+
"execution_count": 4,
59+
"metadata": {},
60+
"output_type": "execute_result"
61+
}
62+
],
63+
"source": [
64+
"# socket.send(f'*90*'.encode()) # Send data with socket connection\n",
65+
"socket.send(bytes('1', 'UTF-8'))\n",
66+
"# socket.sendall(f'SSSS'.encode())"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 6,
72+
"id": "9a3f9ca2",
73+
"metadata": {},
74+
"outputs": [],
75+
"source": [
76+
"socket.recv(2).decode() # Receive data with socket connection"
77+
]
78+
}
79+
],
80+
"metadata": {
81+
"kernelspec": {
82+
"display_name": "Python 3 (ipykernel)",
83+
"language": "python",
84+
"name": "python3"
85+
},
86+
"language_info": {
87+
"codemirror_mode": {
88+
"name": "ipython",
89+
"version": 3
90+
},
91+
"file_extension": ".py",
92+
"mimetype": "text/x-python",
93+
"name": "python",
94+
"nbconvert_exporter": "python",
95+
"pygments_lexer": "ipython3",
96+
"version": "3.10.4"
97+
},
98+
"vscode": {
99+
"interpreter": {
100+
"hash": "3f74628874e72a69f25fba1beeb97e633df0f5a9e3b9a803942cc96884bee9ff"
101+
}
102+
}
103+
},
104+
"nbformat": 4,
105+
"nbformat_minor": 5
106+
}

‎esp8266_at_tcp.py

Copy file name to clipboard
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import sys
2+
from serial import Serial
3+
4+
5+
def serial_init(PORT: str, BAUDRATE: int) -> Serial:
6+
"""Returns a connected Serial object"""
7+
try:
8+
serial = Serial(PORT, BAUDRATE)
9+
except:
10+
print("Can not connect to this port!")
11+
sys.exit(1)
12+
return serial
13+
14+
15+
def create_tcp_server(serial: Serial) -> int:
16+
serial.write(b'AT+RST\r\n')
17+
serial.read_until(b'ready\r\n')
18+
serial.write(b'AT\r\n')
19+
serial.read_until(b'OK\r\n')
20+
serial.write(b'AT+CWMODE=3\r\n')
21+
serial.read_until(b'OK\r\n')
22+
serial.write(
23+
f'AT+CWSAP="{module_SSID}","{module_PASSWORD}",5,4\r\n'.encode()
24+
)
25+
serial.read_until(b'OK\r\n')
26+
serial.write(f'AT+CWJAP="{router_SSID}","{router_PASSWORD}"\r\n'.encode())
27+
serial.read_until(b'OK\r\n')
28+
serial.write(b'AT+CIPMUX=1\r\n')
29+
serial.read_until(b'OK\r\n')
30+
serial.write(b'AT+CIPSERVER=1,80\r\n')
31+
serial.read_until(b'OK\r\n')
32+
serial.write(b'AT+CIPSTA?\r\n')
33+
ip_result = serial.read_until(b'OK\r\n').decode().split('"')[1]
34+
return ip_result
35+
36+
37+
router_SSID = input("Enter router SSID: ")
38+
router_PASSWORD = input("Enter router password: ")
39+
if len(router_PASSWORD) < 8:
40+
print("Password must be at least 8 characters long!")
41+
sys.exit(1)
42+
43+
module_SSID = input("Enter module SSID: ")
44+
module_PASSWORD = input("Enter module password: ")
45+
if len(module_PASSWORD) < 8:
46+
print("Password must be at least 8 characters long!")
47+
sys.exit(1)
48+
49+
50+
PORT = input("Enter serial port: ")
51+
BAUDRATE = input("Enter serial baudrate:(default is 115200) ") or 115200
52+
53+
54+
serial = serial_init(PORT, BAUDRATE)
55+
router_ip = create_tcp_server(serial)
56+
local_ip = '192.168.4.1'
57+
58+
print(
59+
f"Server is running on: {router_ip}:80 in router & on: {router_ip}:80 on module"
60+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.