【发布时间】:2015-02-24 09:08:26
【问题描述】:
我正在使用 arduino uno 上的 ESP8266 wifi 模块进行从 arduino 到 raspberry-pi 的简单 tcp 通信。tcp 服务器在 raspberry-pi 上运行。我可以使用以下 AT 命令进行 TCP 通信在 arduino 串行监视器中,波特率为 9600。
AT+CIPMUX=1
AT+CIPSTART=4,"TCP","192.168.43.150",7777
AT+CIPSEND=4,5
>hai
如何在 arduino 草图中以编程方式执行此操作。我在我的 arduino uno 上使用了以下代码,但仍然没有成功。波特率仅为 9600,因为它直接在串行监视器中工作。
#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
void setup()
{
Serial.begin(9600);
esp8266.begin(9600); // your esp's baud rate might be different
}
void loop()
{
esp8266.println("AT");
if(esp8266.available()) // check if the esp is sending a message
{
while(esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
Serial.write(c);
}
}
}
连接如下
ESP8266 Arduino Uno
Vcc 3.3V
CH_PD 3.3V
RX RX(PIN 2)
TX TX(PIN 3)
GND GND
【问题讨论】:
标签: tcp tcpclient arduino-uno esp8266 arduino-ide