Disconnect from wifi

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

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)


read forum's guidelines too.... Are we supposed to guess what arduino you are using for example or what does "every-time I push on 5V" means ...

I can't see any call to client.stop() which I believe should come after your client.println("Connection: close");
status is a global that does not appear to be rest anywhere other then the call to begin which won't be called if status is already set to connected.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.