Hello everybody!
Big problem for me at this time: I try to restart a wifi connection everytime I push on 5V. Everyxthing is working well, but I tried to simulate a wifi connection problem, and here's the problem: my arduino "believes" that it's still connected to the wifi, and starts it's connection to the servor. After 20sec it's says "connexion impossible", but it doesn't try to connect to the wifi again when I push on 5v. It says "connected to wifi", even it's not.
Do you have an idea where my code could be wrong?
THanks
#include <SPI.h>
#include <WiFiNINA.h>
#include <utility/wifi_drv.h>
#include "secrets.h"
#include "RTClib.h"
RTC_DS3231 rtc;
///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)
// définit l'intensité
int intensity = 15;
int status = WL_IDLE_STATUS;
int pin5v = 9; // ENTREE SIGNAL 5V
int read5v = 0; //INITILISATION DE LA VALEU RDE LECTURE
int panne = 11;
int i = 0;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "lesed.ch"; // name address for Google (using DNS)
char host[] = "www.lesed.ch";
char url[] = "test.php";
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;
void setup() {
// définit les sorties LED RGB
WiFiDrv::pinMode(25, OUTPUT); // rouge
WiFiDrv::pinMode(26, OUTPUT); // vert
WiFiDrv::pinMode(27, OUTPUT); // bleu
// éteint les 3 LED de couleur
WiFiDrv::analogWrite(25, 0);
WiFiDrv::analogWrite(26, 0);
WiFiDrv::analogWrite(27, 0);
//Initialise et ouvre le port série
Serial.begin(9600);
pinMode(pin5v, INPUT);
}
// FIN SETUP
void loop() {
DateTime now = rtc.now();
int annee = (now.year(), DEC);
read5v=digitalRead(pin5v);
if (read5v == HIGH){
Serial.print(status);
WiFiDrv::analogWrite(27, intensity);
WiFiDrv::analogWrite(25, intensity);
// attempt to connect to WiFi network:
while (status != WL_CONNECTED and i<4) {
Serial.print("Connexion au WIFI: ");
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(5000);
i++;
}
WiFiDrv::analogWrite(26, 0);
WiFiDrv::analogWrite(25, 0);
WiFiDrv::analogWrite(27, intensity);
Serial.println("Connected to wifi");
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connectSSL(server, 443)) {
client.setTimeout(5000);
WiFiDrv::analogWrite(27, 0);
WiFiDrv::analogWrite(25, 0);
WiFiDrv::analogWrite(26, intensity);
Serial.println("connected to server");
Serial.print(client.print("GET /location/add_log_entree.php?panne_log="));
Serial.print(client.print(panne));
Serial.print(client.print("&date_panne_log="));
Serial.print(client.print(annee));
Serial.println(client.println(" HTTP/1.1"));
Serial.println(client.println("Host: lesed.ch"));
Serial.println(client.println("Authorization: --------------------------"));
Serial.println(client.println("User-Agent: arduino"));
char c = client.read();
Serial.write (c);
Serial.println(client.println("Connection: close"));
client.println();
client.println("Connection: close");
client.println();
status = 0;
delay(3000);
WiFiDrv::analogWrite(27, 0);
WiFiDrv::analogWrite(25, 0);
WiFiDrv::analogWrite(26, 0);
exit;} // ENDIF CONNECTE SERVEUR
if (!client.connectSSL(server, 443)) {
Serial.println("Connexion au serveur impossible...");
WiFiDrv::analogWrite(27, 0);
WiFiDrv::analogWrite(25, intensity);
WiFiDrv::analogWrite(26, 0);
status = 0;
delay(3000);
WiFiDrv::analogWrite(27, 0);
WiFiDrv::analogWrite(25, 0);
WiFiDrv::analogWrite(26, 0);
exit;} // ENDIF NOT CONNECTE SERVEUR
exit;} // ENDIF 5V
exit;} // ENDIF LOOP