esp8266能当作wifi串口使用
This commit is contained in:
@@ -202,7 +202,7 @@ void ESP8266_Uart_Callback(void)
|
||||
else
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
isr_uart0_rx_interrupt_hook_back(rev_tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,22 +15,35 @@ const uint16_t port = 1347;
|
||||
|
||||
WiFiClient client;
|
||||
|
||||
uint8_t uart_rx_buffer[1024];
|
||||
size_t uart_rx_buffer_index = 0;
|
||||
|
||||
uint8_t uart_tx_buffer[1024];
|
||||
size_t uart_tx_buffer_index = 0;
|
||||
|
||||
// static uint8_t test_buff[40960] = {0};
|
||||
|
||||
|
||||
void connectToServer() {
|
||||
// Serial.print("connecting to ");
|
||||
// Serial.print(host);
|
||||
// Serial.print(':');
|
||||
// Serial.println(port);
|
||||
|
||||
|
||||
if (!client.connect(host, port)) {
|
||||
// Serial.println("connection failed");
|
||||
return;
|
||||
}
|
||||
client.keepAlive();
|
||||
client.setTimeout(1);
|
||||
// Serial.println("connected");
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.setTimeout(1);
|
||||
Serial.setRxBufferSize(1024);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
@@ -44,6 +57,7 @@ void setup() {
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// static bool wait = false;
|
||||
|
||||
// Serial.print("connecting to ");
|
||||
@@ -55,34 +69,43 @@ void loop() {
|
||||
|
||||
// This will send a string to the server
|
||||
// Serial.println("sending data to server");
|
||||
uart_rx_buffer_index = Serial.readBytes(uart_rx_buffer,64);
|
||||
if (client.connected()) {
|
||||
while(Serial.available()) {
|
||||
char ch = static_cast<char>(Serial.read());
|
||||
client.print(ch);
|
||||
}
|
||||
client.write(uart_rx_buffer,uart_rx_buffer_index);
|
||||
// while(1){
|
||||
// client.write(test_buff,40960);
|
||||
// }
|
||||
// while(Serial.available()) {
|
||||
// char ch = static_cast<char>(Serial.read());
|
||||
// client.print(ch);
|
||||
// }
|
||||
// client.println("hello from ESP8266");
|
||||
}
|
||||
else {
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
unsigned long timeout = millis();
|
||||
while (client.available() == 0) {
|
||||
if (millis() - timeout > 5000) {
|
||||
// Serial.println(">>> Client Timeout !");
|
||||
client.stop();
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
while (client.available()) {
|
||||
// char ch = static_cast<char>(client.read());
|
||||
// Serial.print(ch);
|
||||
uart_tx_buffer_index = client.read(uart_tx_buffer,32);
|
||||
Serial.write(uart_tx_buffer,uart_tx_buffer_index);
|
||||
}
|
||||
|
||||
// unsigned long timeout = millis();
|
||||
// while (client.available() == 0) {
|
||||
// if (millis() - timeout > 5000) {
|
||||
// // Serial.println(">>> Client Timeout !");
|
||||
// client.stop();
|
||||
// delay(1000);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Read all the lines of the reply from server and print them to Serial
|
||||
// Serial.println("receiving from remote server");
|
||||
// not testing 'client.connected()' since we do not need to send data here
|
||||
while (client.available()) {
|
||||
char ch = static_cast<char>(client.read());
|
||||
Serial.print(ch);
|
||||
}
|
||||
|
||||
|
||||
// Close the connection
|
||||
// Serial.println();
|
||||
|
||||
39
esp8266/espdata.txt
Normal file
39
esp8266/espdata.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
|
||||
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
C0 00 08 24 00 00 00 00 00 07 07 12 20 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 C0
|
||||
U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U U
|
||||
Reference in New Issue
Block a user