2025年9月30日火曜日

UNO R4 TUTORIAL 4(RTC,BLE2,HC-SR,LEDstrip)

 https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/new_feature_projects/03_rtc.html はTIME SETして時間ごとに仕事する

残念ながら、TIME取得の方法がなかった

https://garretlab.web.fc2.com/arduino.cc/docs/tutorials/uno-r4-wifi/rtc/  にあった

----------------------------------------------------------------

https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/iot_projects/07_iot_ble_lcd.html に成功

LIGHT BLUEでは、READ,WRITEをタップして、WRITEにすすみHEXバーをタップして

UTF8にフォーマット変更する!(saveボタンで)

------------------------------------------------------------------------------

HC-SR04 ultrasonic distance meter:: LCDをつながないときは操作部分をコメントアウト!

そうでないと動かんみたいだ、これ案外重要かも


#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // initialize the Liquid Crystal Display object with the I2C address 0x27, 16 columns and 2 rows

// Define the pin numbers for the ultrasonic sensor
const int echoPin = 3;
const int trigPin = 4;

void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println("start");
pinMode(echoPin, INPUT); // Set echo pin as input
pinMode(trigPin, OUTPUT); // Set trig pin as output

//lcd.init(); // initialize the LCD
//lcd.clear(); // clear the LCD display
//lcd.backlight(); // Make sure backlight is on
}

void loop() {
float distance = readDistance(); // Call the function to read the sensor data and get the distance

//lcd.setCursor(0, 0); //Place the cursor at Line 1, Column 1. From here the characters are to be displayed
//lcd.print("Distance:"); ////Print Distance: on the LCD
//lcd.setCursor(0, 1); //Set the cursor at Line 1, Column 0
//lcd.print(" "); //Here is to leave some spaces after the characters so as to clear the previous characters that may still remain.
//lcd.setCursor(7, 1); //Set the cursor at Line 1, Column 7.
//lcd.print(distance); // print on the LCD the value of the distance converted from the time between ping sending and receiving.
//lcd.setCursor(14, 1); //Set the cursor at Line 1, Column 14.
// lcd.print("cm"); //print the unit "cm"
Serial.println(distance);
delay(800); // Delay for 800 milliseconds before repeating the loop
}

// Function to read the sensor data and calculate the distance
float readDistance() {
digitalWrite(trigPin, LOW); // Set trig pin to low to ensure a clean pulse
delayMicroseconds(2); // Delay for 2 microseconds
digitalWrite(trigPin, HIGH); // Send a 10 microsecond pulse by setting trig pin to high
delayMicroseconds(10);
digitalWrite(trigPin, LOW); // Set trig pin back to low

// Measure the pulse width of the echo pin and calculate the distance value
float distance = pulseIn(echoPin, HIGH) / 58.00; // Formula: (340m/s * 1us) / 2
return distance;
}
---------------------------------------------------------------------
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); is a FastLED library function that configures the LED strip

2025年9月29日月曜日

UNO R4 TUTORIAL3(ARDUINO IOT CLOUD:Blynk-like)

 Arduino IoTクラウド — SunFounder Elite Explorer Kit ドキュメント に成功

(ウィンドウズ11にて成功、リナックスでもいけた!

Wifi設定は一回やっとけば、thingsを作り直しても自動オンラインになった

Wifi設定は多分クラウド上に保管されている。。。。?  すこし違うみたい?

ThingsにDeviceを紐づける!シークレットキーはいらんかった

Wifi設定にすすむ ssidを選択して、パスワードをいれる 

ここでR4 Wifiがオンラインになってないと以下が成功しない

次にクラウド変数を設定をして、スケッチにすすむ 

DHTセンサーライブラリを検索し、チェック

あとは->をクリックしてマイコンにアップロードする

go to iot cloudが出てこんので、metadataをクリックしたらメニューボタンがでた!

ダッシュボードをつくりクラウド変数をvalude widgetに紐づける これで完成した

オンラインのままなら、ほかのpcからもダッシュボードが見れるはず(他日を期す)

注:Raspberry Pi Pico WのBlynkと動作概念は同一だった

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

https://qiita.com/macole/items/ba3fcbcc5945423984ac 上はセンサ表示、ここは操作

コピペする場合はを除いてください。ledはクラウド変数!

sketch
/*
  Sketch generated by the Arduino IoT Cloud Thing "Cloud Blink"

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool led;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
+ pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  ArduinoCloud.update();
+ digitalWrite(LED_BUILTIN, led);
}

/*
  Since Led is READ_WRITE variable, onLedChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLedChange()  {
+ Serial.print("Led status changed:");
+ Serial.println(led);
}

2025年9月28日日曜日

UNO R4 TUTORIAL2(DACwithPassiveBuzzer,)

active buzzerは内部に発振をそなえ単純なブザー機能をもつ メロディ可能なるも音ひどい

passive buzzerは外部電圧で発振するのでメロディが可能(±逆でも音がでる)

https://www.denshi.club/cookbook/arduino/r4/10-2-d-a.htmlを参考に

https://cediablog.com/arduinor4-minima-dac/を修正

#include "analogWave.h"

analogWave wave(DAC);

#define NOTE_A4 69 // MIDI note value for middle A

#define FREQ_A4 440 // frequency for middle A

// the tonic, or first note of the key signature for the song:
int tonic = 65;
// the melody sequence. Note values are relative to the tonic:
int melody[] = {1, 3, 5, 1,
1, 3, 5, 1,
5, 6, 8, 5, 6, 8,
8, 10, 8, 6, 5, 1,
8, 10, 8, 6, 5, 1,
1, -4, 1,
1, -4, 1
};
// the rhythm sequence. Values are 1/note, e.g. 4 = 1/4 note:
int rhythm[] = {4, 4, 4, 4,
4, 4, 4, 4,
4, 4, 2,
4, 4, 2,
8, 8, 8, 8, 4, 4,
8, 8, 8, 8, 4, 4,
4, 4, 2,
4, 4, 2
};
// which note of the melody to play:
int noteCounter = 0;

int bpm = 120; // beats per minute
// duration of a beat in ms
float beatDuration = 60.0 / bpm * 1000;

void setup() {
// start the sine wave generator:
wave.sine(10);
}

void loop() {
// current note is an element of the array:
int currentNote = melody[noteCounter] + tonic;
// play a note from the melody:
// convert MIDI note number to frequency:
float frequency = FREQ_A4 * pow(2, ((currentNote - NOTE_A4) / 12.0));

// all the notes in this are sixteenth notes,
// which is 1/4 of a beat, so:
float noteDuration = beatDuration * (4.0 / rhythm[noteCounter]);
// turn the note on:
wave.freq(frequency);
// tone(speakerPin, frequency, noteDuration * 0.85);
// keep it on for the appropriate duration:
delay(noteDuration * 0.85);
wave.stop();
delay(noteDuration * 0.15);
// turn the note off:
// noTone(speakerPin);
// increment the note number for next time through the loop:
noteCounter++;
// keep the note in the range from 0 – 32 using modulo:
noteCounter = noteCounter % 32;

}

2025年9月27日土曜日

UNO R4 TUTORIAL1(LCD1602,SDCARD,)

 LCD1602はAVR用のライブラリと警告あるが無事に動いた  MICROBIT用でない6X4!

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()

{

lcd.begin(16,2);

lcd.init(); 

lcd.backlight(); 

lcd.setCursor(2, 0); 

lcd.print("Hello World!");

delay(1000);

}


void loop() {

lcd.setCursor(5, 1); 

lcd.print(millis()/1000);

}

-----------------------------------------------------------------------------------------


#include <SD.h>

#define PIN_SPI_CS 4 // The Arduino UNO R4 pin connected to the CS pin of SDcard module

File myFile;

void setup() {
Serial.begin(9600);

if (!SD.begin(PIN_SPI_CS)) {
Serial.println(F("SD Card is either missing or has failed!"));
while (1); // don't do anything more:
}

Serial.println(F("SD Card is ready"));

// open file for writing
myFile = SD.open("arduino.txt", FILE_WRITE);

if (myFile) {
myFile.println("Created by newbiely.com"); // write a line to Arduino
myFile.println("Learn Arduino and SD Card"); // write another line to Arduino
myFile.close();
} else {
Serial.print(F("Error: Unable to open file arduino.txt"));
}

// open file for reading
myFile = SD.open("arduino.txt", FILE_READ);
if (myFile) {
while (myFile.available()) {
char ch = myFile.read(); // read characters one by one from Micro SD Card
Serial.print(ch); // print the character to Serial Monitor
}
myFile.close();
} else {
Serial.print(F("Error: Unable to open file arduino.txt"));
}
}

void loop() {
}




2025年9月26日金曜日

UNO R4 TUTORILAL0(BLE)

 /* BLE LEDオンオフ サンファウンダのサイト*/

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service

// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central

BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);  // バイト単位の読み書きが可能となる

const int ledPin = LED_BUILTIN; // pin to use for the LED

void setup() {

  Serial.begin(9600);

  while (!Serial);

  // set LED pin to output mode

  pinMode(ledPin, OUTPUT);

  // begin initialization

  if (!BLE.begin()) {

    Serial.println("starting Bluetooth® Low Energy module failed!");

    while (1);

  }

  // set advertised local name and service UUID:

  BLE.setLocalName("UNO R4 LED");

  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service

  ledService.addCharacteristic(switchCharacteristic);

  // add service

  BLE.addService(ledService);

  // set the initial value for the characeristic:

  switchCharacteristic.writeValue(0);

  // start advertising

  BLE.advertise();

  Serial.println("BLE LED Peripheral");

}


void loop() {

  // listen for Bluetooth® Low Energy peripherals to connect:

  BLEDevice central = BLE.central();

  // if a central is connected to peripheral:

  if (central) {

    Serial.print("Connected to central: ");

    // print the central's MAC address:

    Serial.println(central.address());

    // while the central is still connected to peripheral:

    while (central.connected()) {

      // if the remote device wrote to the characteristic,

      // use the value to control the LED:

      if (switchCharacteristic.written()) {

        if (switchCharacteristic.value()) {   // any value other than 0

          Serial.println("LED on");

          digitalWrite(ledPin, HIGH);         // will turn the LED on

        } else {                              // a 0 value

          Serial.println(F("LED off"));

          digitalWrite(ledPin, LOW);          // will turn the LED off

        }

      }

    }

    // when the central disconnects, print it out:

    Serial.print(F("Disconnected from central: "));

    Serial.println(central.address());

  }

}

注:Light Blueでbuiltin ledをオンオフできる

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー


2025年9月24日水曜日

php buitin serverにR4からget reqをなげる

 PHPビルトインサーバーで特定のIPアドレスにサーバーを公開するには、コマンドの最後にIPアドレスとポート番号を指定します具体的には「php -S IPアドレス:ポート番号という形式で実行します。IPアドレスを指定しない場合、デフォルトで127.0.0.1(ローカルホスト)にバインドされます。

php -S 192.168.11.8:8000 -t php_public_html

test.php::  getをうけてsample.txtに書き込む 測定結果表示はtest2.phpでおこなう

<?php echo "Hello World!\n"; $data="temp=".$_GET['temp']." humidity=".$_GET['humidity']; ・・・文字連結が特殊! echo $data; file_put_contents("sample.txt", $data); ?>

test2.php::  逐次測定結果を表示

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>自動リロード</title>
    <!-- 10秒ごとにページをリロード -->
    <meta http-equiv="refresh" content="10">
</head>
<body>
    <p>このページは10秒ごとに自動で更新されます。</p>
    <?php $tempc_humidity = file_get_contents( './sample.txt');
          echo $tempc_humidity;
    ?>
</body>
</html>

----------------------------------------------------------------------------

#include <DHT.h>

#define DHT11_PIN 2 // The Arduino UNO R4 pin connected to DHT11

#include "WiFiS3.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 status = WL_IDLE_STATUS

// Initialize the WiFi client library

WiFiClient client;

// setup DHT11

DHT dht11(DHT11_PIN, DHT11);

// server address:

char server[] = "192.168.11.8";


unsigned long lastConnectionTime = 0;

// last time you connected to the server, in milliseconds

const unsigned long postingInterval = 10L * 1000L;

 // delay between updates, in milliseconds


/* -------------------------------------------------------------------------- */

void setup() {

/* -------------------------------------------------------------------------- */  

   dht11.begin(); // initialize the sensor

  //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);

  }

  // you're connected now, so print out the status:

  printWifiStatus();

}


/* just wrap the received data up to 80 columns in the serial print*/

/* -------------------------------------------------------------------------- */

void read_request() {

/* -------------------------------------------------------------------------- */  

  uint32_t received_data_num = 0;


  while (client.available()) {

    /* actual data reception */

    char c = client.read();

    /* print data to serial port */

    Serial.print(c);

    /* wrap data to 80 columns*/

    received_data_num++;

    if(received_data_num % 80 == 0) {     

    }

  }  

}


/* -------------------------------------------------------------------------- */

void loop() {

/* -------------------------------------------------------------------------- */  

  // if there's incoming data from the net connection.

  // send it out the serial port.  This is for debugging

  // purposes only:

  read_request();

  

  // if ten seconds have passed since your last connection,

  // then connect again and send data:

  if (millis() - lastConnectionTime > postingInterval) {

    httpRequest();

  }


}


// this method makes a HTTP connection to the server:

/* -------------------------------------------------------------------------- */

void httpRequest() {

/* -------------------------------------------------------------------------- */  

  // close any connection before send a new request.

  client.stop();

  // read humidity

  float humidity  = dht11.readHumidity();

  // read temperature as Celsius

  float tempc = dht11.readTemperature();

  Serial.println(tempc);

  Serial.println(humidity);

  String req;

  String d= "GET /test.php?temp=";

  String e= " HTTP/1.1";

  String f= "&humidity=";

  req=d+tempc+f+humidity+e;

  Serial.println(req);

  // if there's a successful connection:

  if (client.connect(server, 8000)) {

    Serial.println("connecting...");

    // send the HTTP GET request:

     client.println(req);

    client.println("Host: 192.168.11.8");

    client.println("User-Agent: ArduinoWiFi/1.1");

    client.println("Connection: close");

    client.println();

    // note the time that the connection was made:

    lastConnectionTime = millis();

  } else {

    // if you couldn't make a connection:

    Serial.println("connection failed");

  }

}


/* -------------------------------------------------------------------------- */

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");

}


2025年9月23日火曜日

UnoR4Tutoral-1::wifiでled-onoffをする二方法

 https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/new_feature_projects/01_2_ap.htmlはUNOに独自のアクセスポイントをつくるのでsecrets.hに独自の情報をいれる(ap-uno4,9999111 etc) デフォルトでは192.168.4.9にしておく

/*
WiFi Web Server LED Blink

A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi module (once connected)
to the Serial Monitor. From there, you can open that address in a web browser
to turn on and off the LED_BUILTIN.

If the IP address of your board is yourAddress:
http://yourAddress/H turns the LED on
http://yourAddress/L turns it off

This example is written for a network using WPA encryption. For
WEP or WPA, change the WiFi.begin() call accordingly.

Circuit:
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and Uno WiFi Rev.2)
* LED attached to pin 9

created 25 Nov 2012
by Tom Igoe

Find the full UNO R4 WiFi Network documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#simple-webserver
*/

#include "WiFiS3.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 led = LED_BUILTIN;
int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(led, OUTPUT); // set the LED pin mode

// 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 Network named: ");
Serial.println(ssid); // print the network name (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(); // start the web server on port 80
printWifiStatus(); // you're connected now, so print out the status
}


void loop() {
WiFiClient client = server.available(); // listen for incoming clients

if (client) { // if you get a client,
Serial.println("new client"); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out to the serial monitor
if (c == '\n') { // if the byte is a newline character

// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();

// the content of the HTTP response follows the header:
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/H\">here</a> turn the LED on<br></p>");
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/L\">here</a> turn the LED off<br></p>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}

// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
}
}
}
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}

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");
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}

https://blog.goo.ne.jp/jh7ubc/e/900d12b891d64d329bb2279000e64204をもとに以下で成功

/*
WiFi Web Server LED Blink

A simple web server that lets you blink an LED via the web.
This sketch will print the IP address of your WiFi module (once connected)
to the Serial Monitor. From there, you can open that address in a web browser
to turn on and off the LED_BUILTIN.

If the IP address of your board is yourAddress:
http://yourAddress/H turns the LED on
http://yourAddress/L turns it off

This example is written for a network using WPA encryption. For
WEP or WPA, change the WiFi.begin() call accordingly.

Circuit:
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and Uno WiFi Rev.2)
* LED attached to pin 9

created 25 Nov 2012
by Tom Igoe

Find the full UNO R4 WiFi Network documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#simple-webserver
*/

#include "WiFiS3.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 led = LED_BUILTIN;
int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(led, OUTPUT); // set the LED pin mode

// 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 Network named: ");
Serial.println(ssid); // print the network name (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(); // start the web server on port 80
printWifiStatus(); // you're connected now, so print out the status
}


void loop() {
WiFiClient client = server.available(); // listen for incoming clients

if (client) { // if you get a client,
Serial.println("new client"); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out to the serial monitor
if (c == '\n') { // if the byte is a newline character

// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();

// the content of the HTTP response follows the header:
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/H\">here</a> turn the LED on<br></p>");
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/L\">here</a> turn the LED off<br></p>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}

// Check to see if the client request was "GET /H" or "GET /L":
if (currentLine.endsWith("GET /H")) {
digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on
}
if (currentLine.endsWith("GET /L")) {
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
}
}
}
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}

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");
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}