Hey everyone,
I have some issues with connecting my Arduino to the WI-FI, the code looks fine, while compiling no errors. What maybe important to know is that I use Mobile Hotspot for this. So, when I turn on Mobile Hotspot on my phone and see this connection on the computer, I don't see any sign that Arduino connected to it. How to check or know that it was connected or no eventually? Is there any good tutorial for that you could share? Here is the code:
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>
#include <CapacitiveSensor.h>
// WiFi credentials
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
// CapacitiveSensor setup
CapacitiveSensor cs_2_4 = CapacitiveSensor(2, 4); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
// UDP setup
int status = WL_IDLE_STATUS;
unsigned int localPort = 2390; // local port to listen on
char packetBuffer[256]; // buffer to hold incoming packet
char ReplyBuffer[] = "acknowledged"; // a string to send back
WiFiUDP Udp;
void setup() {
Serial.begin(9600);
// CapacitiveSensor setup
cs_2_4.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
// WiFi setup
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000); // wait 10 seconds for connection
}
Serial.println("Connected to WiFi");
// UDP setup
Udp.begin(localPort);
printWifiStatus();
Serial.println("\nStarting connection to server...");
}
void loop() {
// CapacitiveSensor reading
long total1 = cs_2_4.capacitiveSensor(30);
// UDP packet handling
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());
int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
Serial.println("Contents:");
Serial.println(packetBuffer);
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
// Serial print total1 (CapacitiveSensor reading)
Serial.print(total1); // check on performance in milliseconds
Serial.print("\n"); // tab character for debug window spacing
delay(10); // arbitrary delay to limit data to serial port
}
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");
}
Thank you a lot in advance!