Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MicroCART_17-18
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bbartels
MicroCART_17-18
Commits
aacd886b
Commit
aacd886b
authored
8 years ago
by
David Wehr
Browse files
Options
Downloads
Patches
Plain Diff
Added TCP test scripts
parent
438c0e8a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
WiFiTelnetToSerial_test/WiFiTelnetToSerial_test.ino
+99
-0
99 additions, 0 deletions
WiFiTelnetToSerial_test/WiFiTelnetToSerial_test.ino
WiFiTelnetToSerial_test/tcp_corrup_test.py
+74
-0
74 additions, 0 deletions
WiFiTelnetToSerial_test/tcp_corrup_test.py
with
173 additions
and
0 deletions
WiFiTelnetToSerial_test/WiFiTelnetToSerial_test.ino
0 → 100644
+
99
−
0
View file @
aacd886b
/*
WiFiTelnetToSerial - Example Transparent UART to Telnet Server for esp8266
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the ESP8266WiFi library for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include
<ESP8266WiFi.h>
#include
<algorithm>
//how many clients should be able to telnet to this ESP8266
#define MAX_SRV_CLIENTS 1
const
char
*
ssid
=
"uCart_AP"
;
const
char
*
password
=
"**********"
;
WiFiServer
server
(
8080
);
WiFiClient
serverClients
[
MAX_SRV_CLIENTS
];
int
tcp_buf_size
=
2048
;
byte
*
tcp_buf
=
(
byte
*
)
malloc
(
tcp_buf_size
);
int
ser_buf_size
=
1024
;
byte
*
serial_buf
=
(
byte
*
)
malloc
(
ser_buf_size
);
void
setup
()
{
Serial1
.
begin
(
115200
);
//WiFi.begin(ssid, password);
// Configure chip to be access point
WiFi
.
mode
(
WIFI_AP
);
// Wait for Access point to be created
while
(
!
WiFi
.
softAP
(
ssid
))
{
delay
(
500
);
// Wait half a second before re-trying
}
//start UART and the server
Serial
.
begin
(
921600
);
Serial
.
setRxBufferSize
(
1024
);
server
.
begin
();
server
.
setNoDelay
(
true
);
}
void
loop
()
{
uint8_t
i
,
j
;
//check if there are any new clients
if
(
server
.
hasClient
()){
for
(
i
=
0
;
i
<
MAX_SRV_CLIENTS
;
i
++
){
//find free/disconnected spot
if
(
!
serverClients
[
i
]
||
!
serverClients
[
i
].
connected
()){
if
(
serverClients
[
i
])
serverClients
[
i
].
stop
();
serverClients
[
i
]
=
server
.
available
();
continue
;
}
}
serialFlush
();
//no free/disconnected spot so reject
WiFiClient
serverClient
=
server
.
available
();
serverClient
.
stop
();
}
//check clients for data
if
(
serverClients
[
0
]
&&
serverClients
[
0
].
connected
()){
//delay(1);
while
(
serverClients
[
0
].
available
()){
int
aval
=
std
::
min
(
serverClients
[
0
].
available
(),
tcp_buf_size
);
int
retval
=
serverClients
[
0
].
read
(
tcp_buf
,
aval
);
Serial
.
write
(
tcp_buf
,
aval
);
}
}
if
(
Serial
.
available
())
{
size_t
len
=
std
::
min
(
Serial
.
available
(),
ser_buf_size
);
Serial
.
readBytes
(
serial_buf
,
len
);
int
written
=
serverClients
[
0
].
write
((
const
uint8_t
*
)
serial_buf
,
len
);
//Serial.write(serial_buf, len);
}
}
void
serialFlush
(){
while
(
Serial
.
available
()
>
0
)
{
char
t
=
Serial
.
read
();
}
}
This diff is collapsed.
Click to expand it.
WiFiTelnetToSerial_test/tcp_corrup_test.py
0 → 100644
+
74
−
0
View file @
aacd886b
import
socket
import
time
import
csv
TCP_IP
=
"
192.168.4.1
"
TCP_PORT
=
8080
# sock.bind(('', UDP_PORT))
send_size
=
350
message
=
bytes
(
i
%
256
for
i
in
range
(
send_size
))
times_full
=
[]
times_network
=
[]
dropped
=
True
response
=
bytes
(
"
initial
"
,
'
ASCII
'
)
recvd_data
=
[]
n_matched
=
0
for
i
in
range
(
20000
):
if
dropped
:
attempts
=
0
while
attempts
<
5
:
print
(
"
Trying to connect
"
)
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
sock
.
settimeout
(
2
)
try
:
sock
.
connect
((
TCP_IP
,
TCP_PORT
))
dropped
=
False
break
except
:
attempts
+=
1
if
dropped
:
print
(
"
Failed to connect
"
)
break
print
(
"
connected
"
)
send_msg
=
message
sock
.
send
(
send_msg
)
try
:
# while len(recvd_data) < send_size+4:
response
=
sock
.
recv
(
1024
)
recvd_data
.
extend
(
response
)
except
:
print
(
"
timed out
"
)
dropped
=
True
sock
.
close
()
if
len
(
recvd_data
)
>=
send_size
or
dropped
:
response
=
bytes
(
recvd_data
[
0
:
send_size
])
if
response
!=
message
:
print
(
"
Don
'
t match
"
)
print
(
"
:
"
.
join
(
"
{:02x}
"
.
format
(
c
)
for
c
in
message
))
print
(
"
:
"
.
join
(
"
{:02x}
"
.
format
(
c
)
for
c
in
response
))
else
:
n_matched
+=
1
recvd_data
=
recvd_data
[
send_size
:]
# written = int.from_bytes(recvd_data[0:4], byteorder='little')
# recvd_data = recvd_data[4:]
# print("ESP said wrote " + str(written))
# print(":".join("{:02x}".format(c) for c in response))
if
dropped
:
recvd_data
=
[]
print
(
""
)
# break
time
.
sleep
(
0.01
)
if
i
%
1000
==
0
:
print
(
i
)
print
(
"
Successfully received
"
+
str
(
n_matched
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment