Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1.  
  2.  
  3. #include <SPI.h>
  4. #include <WiFiNINA.h>
  5. #include <WiFiUdp.h>
  6.  
  7. int status = WL_IDLE_STATUS;
  8.  
  9. char ssid[] = "AUGENV4";        // your network SSID (name)
  10. char pass[] = "PWD";    // your network password (use for WPA, or use as key for WEP)
  11.  
  12.  
  13. IPAddress destinationIP(192, 168, 4, 1);  // Address of target machine
  14. unsigned int destinationPort = 6555;      // Port to send to
  15.  
  16.  
  17.  
  18. // A UDP instance to let us send and receive packets over UDP
  19. WiFiUDP Udp;
  20.  
  21. void setup() {
  22.   // Open serial communications and wait for port to open:
  23.   Serial.begin(9600);
  24.   while (!Serial) {
  25.     ; // wait for serial port to connect. Needed for native USB port only
  26.   }
  27.  
  28.   // check for the WiFi module:
  29.   if (WiFi.status() == WL_NO_MODULE) {
  30.     Serial.println("Communication with WiFi module failed!");
  31.     // don't continue
  32.     while (true);
  33.   }
  34.  
  35.   String fv = WiFi.firmwareVersion();
  36.   if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
  37.     Serial.println("Please upgrade the firmware");
  38.   }
  39.  
  40.   // attempt to connect to Wifi network:
  41.   while (status != WL_CONNECTED) {
  42.     Serial.print("Attempting to connect to SSID: ");
  43.     Serial.println(ssid);
  44.     // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  45.     status = WiFi.begin(ssid, pass);
  46.  
  47.     // wait 10 seconds for connection:
  48.     delay(10000);
  49.   }
  50.  
  51.   Serial.println("Connected to wifi");
  52.   printWifiStatus();
  53.  
  54. }
  55.  
  56. void loop() {
  57.  
  58.   delay(1000);
  59.  
  60.  printWifiStatus();
  61.  
  62.   Udp.beginPacket(destinationIP, destinationPort); //NTP requests are to port 123
  63.   Udp.write("Hello");
  64.   Udp.endPacket();
  65.  
  66. }
  67.  
  68.  
  69.  
  70. void printWifiStatus() {
  71.   // print the SSID of the network you're attached to:
  72.   Serial.print("SSID: ");
  73.   Serial.println(WiFi.SSID());
  74.  
  75.   // print your board's IP address:
  76.   IPAddress ip = WiFi.localIP();
  77.   Serial.print("IP Address: ");
  78.   Serial.println(ip);
  79.  
  80.   // print the received signal strength:
  81.   long rssi = WiFi.RSSI();
  82.   Serial.print("signal strength (RSSI):");
  83.   Serial.print(rssi);
  84.   Serial.println(" dBm");
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement