Hi lovely people!
I have a Arduino MKR Wifi 1010 that controls two heating elements for a microbrewery. If the température is below a set température it starts the heating element via a relay.
All of this is conected to IOT cloud. And last night someone unpluged the router before leaving, tehrefore the Arduino was not connect all night. When I came bac this morning despite reconneting the router and having the wifi back on the arduino didn't seem to reconect, I had to rest it manualy with the built in button.
I dont see any code in the loop that tries to reconnect to wifi if it disconnect despite the " ArduinoCloud.update();" Is it suposed to be enough?
Should I add a certain code to reconect to wifi anytime it's disconected?
Thank you for your help, following is my code.
<3
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
https://create.arduino.cc/cloud/things/02da3b5b-09a0-497d-a962-155dbb6edbe0
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String message;
String message_to_turn_on;
float boil_temp_target;
float sparge_temp_target;
CloudTemperatureSensor temp_boil;
CloudTemperatureSensor temp_boil_return;
CloudTemperatureSensor temp_Sparge;
bool resitance_boil_stauts;
bool resitance_spage_status;
bool securite_allumage;
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"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiNINA.h>
int status = WL_IDLE_STATUS;
// 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[] = "hook.eu1.make.com";
// 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):
WiFiSSLClient client;
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS A1
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Addresses of DS18B20s
DeviceAddress sensor1 = { 0x28, 0x68, 0xFC, 0x49, 0xF6, 0x48, 0x3C, 0x24 }; //Boil
DeviceAddress sensor2 = { 0x28, 0x43, 0x1B, 0x11, 0x00, 0x00, 0x00, 0x89 }; //Sparge
DeviceAddress sensor3 = { 0x28, 0x8A, 0x06, 0x49, 0xF6, 0xC1, 0x3C, 0xE5 }; //Boil Return
/*///////////////
PINS
///////////////*/
int resistance_sparge = 7;
int resistance_boil = 6;
/*//////////////
Variables
//////////////*/
int temp_interval = 1000; //interval betzeen two temperature check
int temp_time_mark; //store the millis of the last temperature check
void setup() {
/*/////////////
Pins Mode
//*///////////*/
pinMode(resistance_sparge, OUTPUT);
pinMode(resistance_boil, OUTPUT);
// Initialize serial and wait for port to open:
Serial.begin(9600);
sensors.begin();
// sonde activée
// 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();
//Start with resistance "off"
resitance_spage_status = false;
//Start with security OFF
securite_allumage = false;
}
void loop() {
ArduinoCloud.update();
//Every intervale check the teméprature
if ( millis() - temp_time_mark >= temp_interval) {
//Verification des températures
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
temp_Sparge = sensors.getTempC(sensor2);
temp_boil = sensors.getTempC(sensor1);
temp_boil_return = sensors.getTempC(sensor2);
Serial.print(temp_Sparge);
Serial.println( "C");
// ONLY if se security is turn ON by he messenger it should turn on resistances
if (securite_allumage == true){
//If temperature of Sparge tank is lower than the target change the sparge status to "on"
if (temp_Sparge <= sparge_temp_target) {
resitance_spage_status = true;
}
else {
resitance_spage_status = false;
}
//If the Sparge status is "on" turn on the resistance
if (resitance_spage_status == true ) {
digitalWrite(resistance_sparge, HIGH);
}
else {
digitalWrite(resistance_sparge, LOW);
}
//If temperature of BOIL tank is lower than the target change the sparge status to "on"
if (temp_boil <= boil_temp_target) {
resitance_boil_stauts = true;
}
else {
resitance_boil_stauts = false;
}
//If the Sparge status is "on" turn on the resistance
if (resitance_boil_stauts == true ) {
digitalWrite(resistance_boil, HIGH);
}
else {
digitalWrite(resistance_boil, LOW);
}
}
else{
//Switch off sparge
resitance_spage_status = false;
digitalWrite(resistance_sparge, LOW);
//Switch off boil
resitance_boil_stauts = false;
digitalWrite(resistance_boil, LOW);
}
}
}
// Foloowing funcion is to send a WebHook to manage potentialy send push nottifications
void push_notif() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 443)) {
Serial.println("connected to server");
// Make a HTTP request:
String getRequest = "GET /fcjdjljn0quvvyv5f8wmy4yhj4cmolk0";
//getRequest += String(temp_TAL, 2); // if tempValue is a float and you want 2 digits
getRequest += " HTTP/1.1";
Serial.println("Le getRequest est: ");
Serial.println(getRequest);
client.println(getRequest);
client.println("Host: hook.eu1.make.com");
client.println("Connection: close");
client.println();
/* requette html sans variable
client.println("GET /mbvbogobieo7n3m18y8ps9bs7wwu6ozc HTTP/1.1");
client.println("Host: hook.eu1.make.com");
client.println("Connection: close");
client.println();
*/
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
}
}
}
/*
Since ResitanceStauts is READ_WRITE variable, onResitanceStautsChange() is
executed every time a new value is received from IoT Cloud.
*/
void onResitanceStautsChange() {
// Add your code here to act upon ResitanceStauts change
}
/*
Since PumpStatus is READ_WRITE variable, onPumpStatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onPumpStatusChange() {
// Add your code here to act upon PumpStatus change
}
/*
Since ResitanceSpageStauts is READ_WRITE variable, onResitanceSpageStautsChange() is
executed every time a new value is received from IoT Cloud.
*/
void onResitanceSpageStautsChange() {
// Add your code here to act upon ResitanceSpageStauts change
}
/*
Since ResitanceBoilStauts is READ_WRITE variable, onResitanceBoilStautsChange() is
executed every time a new value is received from IoT Cloud.
*/
void onResitanceBoilStautsChange() {
// Add your code here to act upon ResitanceBoilStauts change
}
/*
Since ResitanceSpageStatuts is READ_WRITE variable, onResitanceSpageStatutsChange() is
executed every time a new value is received from IoT Cloud.
*/
void onResitanceSpageStatutsChange() {
// Add your code here to act upon ResitanceSpageStatuts change
}
/*
Since ResitanceSpageStatus is READ_WRITE variable, onResitanceSpageStatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onResitanceSpageStatusChange() {
// Add your code here to act upon ResitanceSpageStatus change
}
/*
Since SpargeTempTarget is READ_WRITE variable, onSpargeTempTargetChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSpargeTempTargetChange() {
// Add your code here to act upon SpargeTempTarget change
}
/*
Since BoilTempTarget is READ_WRITE variable, onBoilTempTargetChange() is
executed every time a new value is received from IoT Cloud.
*/
void onBoilTempTargetChange() {
// Add your code here to act upon BoilTempTarget change
}
/*
Since Message is READ_WRITE variable, onMessageChange() is
executed every time a new value is received from IoT Cloud.
*/
void onMessageChange() {
if (message == message_to_turn_on){
securite_allumage = true;
}
else
{
securite_allumage = false;
}
}
/*
Since SecuriteAllumage is READ_WRITE variable, onSecuriteAllumageChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSecuriteAllumageChange() {
// Add your code here to act upon SecuriteAllumage change
}
/*
Since MessageToTurnOn is READ_WRITE variable, onMessageToTurnOnChange() is
executed every time a new value is received from IoT Cloud.
*/
void onMessageToTurnOnChange() {
// Add your code here to act upon MessageToTurnOn change
}