Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <WiFiNINA.h>
- #include <WiFiUdp.h>
- int status = WL_IDLE_STATUS;
- char ssid[] = "AUGENV4"; // your network SSID (name)
- char pass[] = "PWD"; // your network password (use for WPA, or use as key for WEP)
- IPAddress destinationIP(192, 168, 4, 1); // Address of target machine
- unsigned int destinationPort = 6555; // Port to send to
- // A UDP instance to let us send and receive packets over UDP
- WiFiUDP Udp;
- void setup() {
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- // check for the WiFi module:
- if (WiFi.status() == WL_NO_MODULE) {
- Serial.println("Communication with WiFi module failed!");
- // don't continue
- while (true);
- }
- String fv = WiFi.firmwareVersion();
- if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
- Serial.println("Please upgrade the firmware");
- }
- // 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, pass);
- // wait 10 seconds for connection:
- delay(10000);
- }
- Serial.println("Connected to wifi");
- printWifiStatus();
- }
- void loop() {
- delay(1000);
- printWifiStatus();
- Udp.beginPacket(destinationIP, destinationPort); //NTP requests are to port 123
- Udp.write("Hello");
- Udp.endPacket();
- }
- void printWifiStatus() {
- // print the SSID of the network you're attached to:
- Serial.print("SSID: ");
- Serial.println(WiFi.SSID());
- // print your board'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");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement