我正在TI使用Code Composer Studio v6.1使用Energia 15在CC3200 LaunchPad上进行一些开发。我在CC3200上成功运行了WiFiUdpSendReceiveString示例但是当我发送时我遇到了一些奇怪的行为来自客户的消息。
以下是我的CC3200上的代码
#ifndef __CC3200R1M1RGC__
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>
// your network name also called SSID
char ssid[] = "xxxxx";
// your network password
char password[] = "xxxxxxx";
unsigned int localPort = 2390; // local port to listen on
char packetBuffer[255]; //buffer to hold incoming packet
char ReplyBuffer[] = "acknowledged"; // a string to send back
WiFiUDP Udp;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
// WiFi.deleteProfileSmartConfig();
// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(1000);
WiFi.begin(ssid, password);
}
Serial.println("\nYou're connected to the network");
Serial.println("Waiting for an ip address");
while (WiFi.localIP() == INADDR_NONE) {
// print dots while we wait for an ip addresss
Serial.print(".");
delay(300);
}
Serial.println("\nIP Address obtained");
printWifiStatus();
Serial.println("\nWaiting for a connection from a client...");
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
我正在使用我的Macbook终端作为客户端通过UDP发送消息,我发送了一系列命令来显示UDP问题:
echo -n "CAF99C4751FB1FD18F8A34BEBA411" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115BFC76" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115BFC76_199A88DF84A77684D148F8D9625B9" | nc -4u -w1 192.168.1.57 2390
echo -n "CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115BFC76_199A88DF84A77684D148F8D9625B9_3B4BD168F7A8D227EAB46FD442A63" | nc -4u -w1 192.168.1.57 2390
这是控制台输出:
Received packet of size 29
From 192.168.1.165, port 49634
Contents:
CAF99C4751FB1FD18F8A34BEBA411
Received packet of size 59
From 192.168.1.165, port 55833
Contents:
CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764
Received packet of size 89
From 192.168.1.165, port 59556
Contents:
CAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7
Received packet of size 119
From 192.168.1.165, port 59331
Contents:
CAFCAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1B78
Received packet of size 149
From 192.168.1.165, port 51635
Contents:
CAFCAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115B6
Received packet of size 179
From 192.168.1.165, port 54811
Contents:
CAFCAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115BFC76_199A88DF84A77684D148F8D5B9
Received packet of size 209
From 192.168.1.165, port 49242
Contents:
CAFCAF99C4751FB1FD18F8A34BEBA411_E622319E55D4E871D2D787DDF5764_6CFE84A6C76C437714C2C329C86C7_46AD7EDE29FA7CB319F71F1EEDB78_6723127C14F6254B149C7115BFC76_199A88DF84A77684D148F8D9625B9_3B4BD168F7A8D227EAB46FD443
在第四条消息上,它开始重复前3个字符,然后在某处附近截断3个字符。在第五条消息上,3个字符返回,但重复的前3个仍然存在。我不知道为什么会这样。似乎我的缓冲区大小在255(我已经尝试了1024)。有什么想法吗?
答案 0 :(得分:1)