本帖最后由 卤蛋在英国 于 2014-2-14 03:43 编辑
小弟人在英国,课题要做一个使用WiFi发送歌曲的Arduino。我现在只能让我的wifi扩展板连接到路由器上,但是没有办法发送数据(最简单的都发送不了),求大神帮帮忙!小弟条件有限,用的是手机做的路由器。让手机跟wifi扩展板同时连到我的手机上,然后写个一个程序发送一句话给我的电脑。但不成功,我用的是Wireshark来监控我的网络环境的。没有看见192.168.43.8(wifi扩展板的IP)传送数据到192.168.43.5(电脑主机的IP)下面是我的程序:
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
char ssid[] = "AndroidAP7577"; // your network SSID (name)
int status = WL_IDLE_STATUS;
byte remoteIP[4] = {192, 168, 43, 5}; //我主机的IP
unsigned int localPort = 2390; // local port to send
unsigned int remotePort = 1963; // receive port to send
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(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
Udp.beginPacket( remoteIP, 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 shield's 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");
}
下面是一些运行的情况!
还需要提供什么资料尽管提哇!小弟第一次发帖,不知道还需要准备一些啥材料。
|