Go Down

Topic: UDP.write() failure? (Read 581 times) previous topic - next topic

mbmosher

Hey Folks, I'm having an issue getting udp to write on my arduino MKR1000.  I've tried using a for loop to write each character individually, I've tried udp.print(), everything hangs.  here;s the code:
Code: [Select]
#include <WiFi101.h>
#include <WiFiUdp.h>

int vals[6];
// int inByte = 0;

char ssid[] = "XXXXXXXXX";  //  your network SSID (name)
char password[] = "XXXXXXXXX";       // your network password
WiFiUDP UDP;
IPAddress broadcast(255, 255, 255, 255);

void setup() {
  Serial.begin(9600);
  for(int i = 0; i < 7; i++) {
    vals[i] = 0;
  }

  WiFi.begin(ssid, password);
    Serial.print("Connecting to wifi");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to wifi");
  //printWiFiStatus();
}

void loop() {
  for(int i = 0; i < 6; i++) {
    vals[i] = analogRead(i);
  }
  char data[50];
  sprintf(data, "/wek/inputs %d %d %d %d %d %d", vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
  Serial.println(data);
  Serial.flush();
  delay(10);
  Serial.println("udp");
  Serial.println(UDP.beginPacket(broadcast, 6448));
  Serial.println("udp begun");
  Serial.println(UDP.write(data, 50));
  Serial.println("udp written");
  Serial.println(UDP.endPacket());
  Serial.println("UDP Sent");
}


And here's what I get on the serial:
Code: [Select]
Connecting to wifiConnected to wifi
/wek/inputs 381 502 395 144 312 248
udp
1
udp begun


And that's it, it just hangs as soon as it gets to UDP.write.  Thoughts?  Thanks for the help.

Go Up