WIFI button

Kuo, Li-Wen
2 min readApr 13, 2021

--

#include <SPI.h>
#include <WiFiNINA.h>

#include “arduino_secrets.h”
///////please enter your sensitive data in the Secret tab/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)
int keyIndex = 0; // your network key index number (needed only for WEP)
int pushButton = 2;
int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
//Initialize serial 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);
}
server.begin();
// you’re connected now, so print out the status:

}

void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println(“new client”);
// an HTTP request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the HTTP request has ended,
// so you can send a reply
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard HTTP response header
client.println(“HTTP/1.1 200 OK”);

--

--