SolArduino - Camping solar heater panels control with Arduino

You don’t have to make it fast :slight_smile: Have a nice day :slight_smile:

Hi @gchiaretta,

Cool project, excited to see the pics! Good luck my friend.

-Benny

I like the updated pics and screenshots! Looks good.

Cheers,

-B

As I had to move to a new account, I have waited for the MQTT changeover and I have then completed the migration. The project is now moved to the “Camping” account.
I am encountering some important issue on the new MQTT setup. Some slow response of the dashboard and, most important and critical, the fact that relays command do not keep as set in case of Arduino reset o power down. This is extremely critical and, if not resolved, it will cancel the entire project as it is crucial that settings remain even in case of (frequent) momentary power cut.
I have already posted a bug report for this issue, with the Camping account.
Regards, Giorgio

Unfortunately the bug posting has been hidden by the antispam system…

this is because Sending MQTT messages within rate limits

you can store the value of eeprom and on reset write the value to the relay as well to the dashboard. do a search of eeprom in community and you will find plenty of topics on it

Thank you, but this way it will still not ensure the dashboard state and the local state are always aligned. This can cause big problems.

Thank you for pointing out “Sending MQTT messages within rate limits”, I had actually missed this. Much obliged.

This is interesting.

  Can you point out some links for me, I would like to learn more

about it.

Thank you

yes sure it can be aligned. the value stored in eeprom can be assigned to both cayenne dashboard and relay in void setup ,

Hi, I have tried to do that, but it did not seem to work. Plus I am still experiancing a very, very, very, slow response from the dashboard…

This is the code of the setup after modification to do “… assigned to both cayenne dashboard and relay in void setup ,”.
void setup()
{
// set digital pin to output
pinMode(RELAY_DIGITAL_PIN1, OUTPUT);// relè pin
pinMode(RELAY_DIGITAL_PIN2, OUTPUT);// relè pin
pinMode(RELAY_DIGITAL_PIN3, OUTPUT);// relè pin
digitalWrite(RELAY_DIGITAL_PIN1, LOW);// set relay to off at startup
digitalWrite(RELAY_DIGITAL_PIN2, HIGH);// set relay to off at startup
digitalWrite(RELAY_DIGITAL_PIN3, HIGH);// set relay to off at startup

// Serial.begin(9600);
Cayenne.begin(username, password, clientID);// not used: arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac
delay (100);
Cayenne.virtualWrite(1, 0, “digital_sensor”, “d”);
Cayenne.virtualWrite(2, 1, “digital_sensor”, “d”);
Cayenne.virtualWrite(3, 1, “digital_sensor”, “d”);

sensors1.begin();
sensors2.begin();
sensors3.begin();
sensors4.begin();
sensors5.begin();
}

Sorry, just saw my own error (I must be getting tired…).

Here is the correct code, and it seems to work:
void setup()
{
// set digital pin to output
pinMode(RELAY_DIGITAL_PIN1, OUTPUT);// relè pin
pinMode(RELAY_DIGITAL_PIN2, OUTPUT);// relè pin
pinMode(RELAY_DIGITAL_PIN3, OUTPUT);// relè pin
digitalWrite(RELAY_DIGITAL_PIN1, LOW);// set relay to off at startup
digitalWrite(RELAY_DIGITAL_PIN2, HIGH);// set relay to off at startup
digitalWrite(RELAY_DIGITAL_PIN3, HIGH);// set relay to off at startup

// Serial.begin(9600);
Cayenne.begin(username, password, clientID);// not used: arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac
delay (100);
Cayenne.virtualWrite(7, 0, “digital_actuator”, “d”);
Cayenne.virtualWrite(8, 1, “digital_actuator”, “d”);
Cayenne.virtualWrite(9, 1, “digital_actuator”, “d”);

sensors1.begin();
sensors2.begin();
sensors3.begin();
sensors4.begin();
sensors5.begin();
}

first remove all the widget from your dashboard, add 3 button on dashboard from add new > widget/device > custom widget > button and use correct channel (7, 8 , 9).
then in your code change this

to

Cayenne.virtualWrite(7, 0);
Cayenne.virtualWrite(8, 0);
Cayenne.virtualWrite(9, 0);

Thank you shramiksalgaonkar for your kind advice, I will try this.

Hello shramiksalgaonkar,
I have tried your suggestion but I seem to get a very strange and erratic behavior.
If I reset the Arduino, then the dashboard seem to get in line OK, but then, if I refresh the browser, the widgets all fall back into OFF position, regardless of what was their original state.

Moreover, I still experience a very, very, very slow response from dashboard commands. That is, if I click on one of the actuator icons, it can act immediately or it can take lots of seconds, even one minute, before it sends the relevant command back to Arduino. Much, much to slow.

Finally, I can get the App of the smartphone (Android) and the dashboard on the PC totally misaligned . So I can have, for example, all icon on the off state on the dashboard and some on some off on the Applet. This is totally confusing and creates problems. In short, I will never be sure of what the situation is from a remote location, I may believe the pump is ON while in fact it is off or vice versa. This, if not fixed, makes the system totally useless.

I believe Cayenne staff should not have force the move over to the new system until all such aspect where fixed, it was, in may view, a little rushed decision that could really cause lots of unhappy users, such as myself :frowning:
Do hope a complete fix is done or that they consider rolling back to the previous system until a more stable situation is found.
Sorry, cannot be optimistic as for now.

can you post your entire code.

/*
  Solarduino main
  From "Cayenne DS18B20 Example"and other examples

                                                          "cayenne5MQTT_SolArduino1Main_camping"


  This sketch shows how to send temperature data to a DS18B20 Sensor in the Cayenne Dashboard.

  The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

  Steps:
  1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
  2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
  3. In the Cayenne Dashboard add a new DS18B20 widget.
  4. Set the widget to Value Display.
  5. Select Virtual Pins and a virtual pin number.
  6. Set VIRTUAL_CHANNEL to the pin number you selected.
  7. Attach a DS18B20 to an digital pin on your Arduino.
  Schematic:
  [Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
                 |______________|
                 |
            Digital Pin
  8. Set the tmpPin variable to match the pin used to connect the DS18B20.
  9. Set the token variable to match the Arduino token from the Dashboard.
  10. Compile and upload this sketch.
  11. Once the Arduino connects to the Dashboard it should automatically update the DS18B20 widget with data.
*/

// SETTING FOT THE SOLARDUINO MAIN FOR CAMPING VERNA SOLAR PANELS SYSTEM. V 1.0
// SAME AS SOLARDUINO AMBIENT, BUT WITH ALL 4 SENSORS AND 3 ACTUATORS USED IN THIS CASE, BUT THE SKETCH HAS BEEN KEPT
// THE SAME TO ENSURE IT IS CONSISTENT. THE ONLY CHANGES CONCERN THE "Resolution test", NOT PRSENT HERE.

//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>//NEW MQTT library



// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_CHANNEL1 1// sensor
#define VIRTUAL_CHANNEL2 2// sensor
#define VIRTUAL_CHANNEL3 3// sensor
#define VIRTUAL_CHANNEL4 4// sensor
#define VIRTUAL_CHANNEL5 5// sensor

#define VIRTUAL_CHANNEL7 7// relè
#define VIRTUAL_CHANNEL8 8// relè
#define VIRTUAL_CHANNEL9 9// relè


#define RELAY_DIGITAL_PIN1 7// relè pin
#define RELAY_DIGITAL_PIN2 8// relè pin
#define RELAY_DIGITAL_PIN3 9// relè pin

// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin1 = 2;
const int tmpPin2 = 3;
const int tmpPin3 = 4;
const int tmpPin4 = 5;
const int tmpPin5 = 6;

unsigned long lastMillis = 0;
int x = 0;// set default for actuators; on (=1) or OFF (=0)
unsigned int timecount = 0; // on time counter// use the unsigned version of int to avoid issues when end of range is achieved, unsigned int will roll-over back to 1

OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);
OneWire oneWire4(tmpPin4);
OneWire oneWire5(tmpPin5);

DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
DallasTemperature sensors3(&oneWire3);
DallasTemperature sensors4(&oneWire4);
DallasTemperature sensors5(&oneWire5);


// NEW Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
// Solarduino Main  - campeggio@gmail.com
char username[] = "xxxx";
char password[] = "xxxx";
char clientID[] = "xxxx";


void setup()
{
  // set digital pin to output
  pinMode(RELAY_DIGITAL_PIN1, OUTPUT);// relè pin
  pinMode(RELAY_DIGITAL_PIN2, OUTPUT);// relè pin
  pinMode(RELAY_DIGITAL_PIN3, OUTPUT);// relè pin
  digitalWrite(RELAY_DIGITAL_PIN1, HIGH);// set relay at startup to OFF as default - Anello Bungalow
  digitalWrite(RELAY_DIGITAL_PIN2, LOW);// set relay at startup to ON as default - Caldaia
  digitalWrite(RELAY_DIGITAL_PIN3, LOW);// set relay startup to ON as default - Miscelatori

  //  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);// not used: arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac
  delay (10000);// give time to setup and then set digital actuator to default

  Cayenne.virtualWrite(7, 0);// set dashboard toggle switch to OFF as default - Anello Bungalow
  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(8, 1);// set dashboard toggle switch to ON as default - Caldaia
  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(9, 1);// set dashboard toggle switch to ON as default - Miscelatori
  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(0, timecount);// reset the counter to 0


  sensors1.begin();
  sensors2.begin();
  sensors3.begin();
  sensors4.begin();
  sensors5.begin();
}


void loop()
{
  Cayenne.loop();
  //Publish data every 60 seconds (60000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 60000) {
    lastMillis = millis();
    ++timecount;
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0, timecount);// send a number incremented of one unit at every count of one minute
  }
}

CAYENNE_IN(7)
{
  x = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL7, RELAY_DIGITAL_PIN1, x);
  // Write the value received to the digital pin.
  digitalWrite(RELAY_DIGITAL_PIN1, !x);
}

CAYENNE_IN(8)
{
  x = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL7, RELAY_DIGITAL_PIN1, x);
  // Write the value received to the digital pin.
  digitalWrite(RELAY_DIGITAL_PIN2, !x);
}

CAYENNE_IN(VIRTUAL_CHANNEL9)
{
  x = getValue.asInt();
  CAYENNE_LOG("Channel %d, pin %d, value %d", VIRTUAL_CHANNEL7, RELAY_DIGITAL_PIN1, x);
  // Write the value received to the digital pin.
  digitalWrite(RELAY_DIGITAL_PIN3, !x);
}


// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
  // Send the command to get temperatures.
  sensors1.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL1, sensors1.getTempCByIndex(0));

}
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
  // Send the command to get temperatures.
  sensors2.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL2, sensors2.getTempCByIndex(0));

}
CAYENNE_OUT(VIRTUAL_CHANNEL3)
{
  // Send the command to get temperatures.
  sensors3.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL3, sensors3.getTempCByIndex(0));

}

CAYENNE_OUT(VIRTUAL_CHANNEL4)
{
  // Send the command to get temperatures.
  sensors4.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL4, sensors4.getTempCByIndex(0));

}

CAYENNE_OUT(VIRTUAL_CHANNEL5)
{
  // Send the command to get temperatures.
  sensors5.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL5, sensors5.getTempCByIndex(0));

}

After some searching on the net and the precious help of Shramik, I have made substantial changes to the code to refine it, and I have also removed some extra code that was probably left by mistake, during some copy-and-paste operations.
Here is the new code that also has an “Online” Led showing if the system is online or Offline. The code has also doubled the sensors to be used, to produce graphic charts of the same data of each temperature sensor. In short, every sensor pin gives two set of identical data, one for the temp. reading, and one for the graphics.
The Online status Led I troubled a lot to find some working example online, then Shramik gave me the solution, and it Works !
For some reason there are no working example on the Internet. Or simply I could not find any.

Also, in the code, there are some “remmed” lines that have been used to test sensor data without the actual probes connected. This is achieved by creating random numbers to send to the temperature sensors virtual channels. I have left it in the code, so to help who may want to test the system in a quick way, without having to wire up the probes to the system.

Live testing of this new code has started and so far all seems OK. Please do use the code as you please, hope it will be of help to you. Please do leave a reference to the author in our code.

/*
  Solarduino main
  From "Cayenne DS18B20 Example"and other examples

                                                          "cayenne5MQTT_SolArduino1Main_camping"


  This sketch shows how to send temperature data to a DS18B20 Sensor in the Cayenne Dashboard.

  The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

  Steps:
  1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
  2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
  3. In the Cayenne Dashboard add a new DS18B20 widget.
  4. Set the widget to Value Display.
  5. Select Virtual Pins and a virtual pin number.
  6. Set VIRTUAL_CHANNEL to the pin number you selected.
  7. Attach a DS18B20 to an digital pin on your Arduino.
  Schematic:
  [Ground] -- [DS18B20] -- [4.7k resistor] -- [5V]
                 |______________|
                 |
            Digital Pin
  8. Set the tmpPin variable to match the pin used to connect the DS18B20.
  9. Set the token variable to match the Arduino token from the Dashboard.
  10. Compile and upload this sketch.
  11. Once the Arduino connects to the Dashboard it should automatically update the DS18B20 widget with data.
*/
/*
    wirtten by Giorgio Chiaretta, with a great help from Shramik of mydevices, on May 2019, for Camping Verna - Cumiana (TO) Italy
*/

// SETTING FOT THE SOLARDUINO MAIN FOR CAMPING VERNA SOLAR PANELS SYSTEM. V 1.2
// SAME AS SOLARDUINO AMBIENT, BUT WITH ALL 5 SENSORS AND 3 ACTUATORS USED IN THIS CASE, BUT THE SKETCH HAS BEEN KEPT
// THE SAME TO ENSURE IT IS CONSISTENT. THE ONLY CHANGES CONCERN THE "Resolution test", NOT PRSENT HERE.

//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h>//NEW MQTT library



// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_CHANNEL1 1// "Anello bungalow" sensor
#define VIRTUAL_CHANNEL2 2// "Temepratura Caldaia" sensor
#define VIRTUAL_CHANNEL3 3// "Temperatura accumulo acqua sanitaria" sensor
#define VIRTUAL_CHANNEL4 4// "Temperatura pompa pannelli solari" sensor
#define VIRTUAL_CHANNEL5 5// "Temperatura accumulo acqua tecnica" sensor
// Channel 0 is used only to send time elapsed since Arudino borad is on


#define VIRTUAL_CHANNEL7 7// external hot water ciruit "bungalow" valve relè
#define VIRTUAL_CHANNEL8 8// water heater relè
#define VIRTUAL_CHANNEL9 9// hot water mixer relè

//double signals to produce bargraphs ======================================================
#define VIRTUAL_CHANNEL11 11// "Anello bungalow" sensor - per grafico
#define VIRTUAL_CHANNEL12 12// "Temepratura Caldaia" sensor - per grafico
#define VIRTUAL_CHANNEL13 13// "Temperatura accumulo acqua sanitaria" sensor - per grafico
#define VIRTUAL_CHANNEL14 14// "Temperatura pompa pannelli solari" sensor - per grafico
#define VIRTUAL_CHANNEL15 15// "Temperatura accumulo acqua tecnica" sensor - per grafico
//double signals to produce bargraphs ======================================================


#define RELAY_DIGITAL_PIN1 7// external hot water ciruit valve relè pin
#define RELAY_DIGITAL_PIN2 8// water heater relè pin
#define RELAY_DIGITAL_PIN3 9// hot water mixer relè pin

//addition for online LED ----------------------------------------
//================================================================
#define LED_ANALOG_PIN1 A1// online status  pin, used an analog pin as all digital one have been used
//================================================================
//addition for online LED ----------------------------------------

// Digital pin the DS18B20 is connected to. DO NOT USE digital pins 0 or 1 since those conflict with the use of Serial.
//Also, Arduino uses digital pins 10, 11, 12, and 13 (SPI) to communicate with the W5100 on the ethernet shield, so they too cannot be used
const byte tmpPin1 = 2;// "Anello bungalow" sensor
const byte tmpPin2 = 3;// "Temepratura Caldaia" sensor
const byte tmpPin3 = 4;// "Temperatura accumulo acqua sanitaria" sensor
const byte tmpPin4 = 5;// "Temperatura pompa pannelli solari" sensor
const byte tmpPin5 = 6;// "Temperatura accumulo acqua tecnica" sensor


unsigned long lastMillis = 0;

int timecount = 0; // on time counter// use the unsigned version of int if want to avoid issues when end of range is achieved, unsigned int will roll-over back to 1, nut I use a counter redefine
//int randomNumber;  //random number generator used for testing purposes only


//addition for online LED ----------------------------------------
//================================================================
boolean onlineStatus = false;
//================================================================
//addition for online LED ----------------------------------------
// this function is not working. Cayenne say they will try to find a solution for ONLINE status monitor, but asd of today they have no solution.


OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);
OneWire oneWire4(tmpPin4);
OneWire oneWire5(tmpPin5);

DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
DallasTemperature sensors3(&oneWire3);
DallasTemperature sensors4(&oneWire4);
DallasTemperature sensors5(&oneWire5);


// SolArduino2_Main  - xxx@gmail.com, this is the LIVE environment used by the systems
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxx";
char password[] = "xxx";
char clientID[] = "xxx";


// ---- static IP setting START ----
/*
  //set this in case you require static IP address settings
  boolean onlineStatus = true; // test to verify if it is Online
  byte arduino_mac[] = { 0xFE, 0xAE, 0xA6, 0xE0, 0xE7, 0xA3 };//FE-AE-A6-E0-E7-A3 (SolArduino Ambient 2 is "A4" final) - MAKE SURE IT IS UNIQUE ON THE NETWORK
  IPAddress arduino_ip(192, 168, 1, 176);// MAKE SURE IT IS UNIQUE ON THE NETWORK (SolArduino Ambient 2 is "177" final)
  IPAddress dns_ip(1, 1, 1, 1);
  IPAddress gateway_ip(192, 168, 1, 1);
  IPAddress subnet_mask(255, 255, 255, 0);
*/
// ---- static IP setting END ----



void setup()
{
  // set digital pin to output
  pinMode(RELAY_DIGITAL_PIN1, OUTPUT);// relè pin
  pinMode(RELAY_DIGITAL_PIN2, OUTPUT);// relè pin
  pinMode(RELAY_DIGITAL_PIN3, OUTPUT);// relè pin

   // set digital pin to startup default state
  digitalWrite(RELAY_DIGITAL_PIN1, HIGH);// set relay at startup to OFF as default - Anello Bungalow
  digitalWrite(RELAY_DIGITAL_PIN2, LOW);// set relay at startup to ON as default - Caldaia
  digitalWrite(RELAY_DIGITAL_PIN3, LOW);// set relay at startup to ON as default - Miscelatori


  //addition for online status LED ----------------------------------------
  //================================================================
  pinMode(LED_ANALOG_PIN1, OUTPUT);// this is Pin A1 for LED1
  //================================================================
  //addition for online status LED ----------------------------------------



  //  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);// not used: arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac
  delay (1000);// give time to setup and then set digital actuator to default

  Cayenne.virtualWrite(7, 0);// set dashboard toggle switch to OFF as default - Anello Bungalow
  //  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(8, 1);// set dashboard toggle switch to ON as default - Caldaia
  //  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(9, 1);// set dashboard toggle switch to ON as default - Miscelatori
  //  delay (1000);// give time to acquire data and then set next state
  Cayenne.virtualWrite(0, timecount);// reset the counter to 0


  sensors1.begin();
  sensors2.begin();
  sensors3.begin();
  sensors4.begin();
  sensors5.begin();

  /*
    //random number generator used for testing purposes only
    randomSeed(42);
  */

}//close Setup

  //addition for online status LED ----------------------------------------
//================================================================
CAYENNE_CONNECTED() {
  onlineStatus = true;
  digitalWrite(LED_ANALOG_PIN1, HIGH);

}
CAYENNE_DISCONNECTED() {
  onlineStatus = false;
  digitalWrite(LED_ANALOG_PIN1, LOW);

}
//================================================================
  //addition for online status LED ----------------------------------------


void loop()
{
  Cayenne.loop();
  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 5000) {
    lastMillis = millis();
    ++timecount;
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    if (timecount >= 100000) {//if the timecount number is greater than 100 then reduce it to 1
      timecount = 1;
    }
    Cayenne.virtualWrite(0, timecount);// send a number incremented of one unit at every count of one minute

  }
  //addition for online status LED ----------------------------------------
  //================================================================
  if (onlineStatus == true) {
    digitalWrite(LED_ANALOG_PIN1, HIGH);// this has to be here, because when the internet is disconnected, the main loop is never executed.
  }
  if (onlineStatus == false) {
    digitalWrite(LED_ANALOG_PIN1, LOW);// this has to be here, because when the internet is disconnected, the main loop is never executed.
  }
  //================================================================
  //addition for online status LED ----------------------------------------
  
    delay (1000);// give time to acquire data and then start next loop
}

CAYENNE_IN(7)//read digital command from dashboard for external hot water ciruit valve relè
{
  // Write the value received to the digital pin.
  digitalWrite(RELAY_DIGITAL_PIN1, !getValue.asInt());
}

CAYENNE_IN(8)//read digital command from dashboard for  water heater relè
{
  digitalWrite(RELAY_DIGITAL_PIN2, !getValue.asInt());
}

CAYENNE_IN(VIRTUAL_CHANNEL9)//read digital command from dashboard for hot water mixer relè
{
  digitalWrite(RELAY_DIGITAL_PIN3, !getValue.asInt());
}


// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT_DEFAULT()
{
  //CAYENNE_OUT(VIRTUAL_CHANNEL1)// "Anello bungalow" sensor
  // Send the command to get temperatures.
  sensors1.requestTemperatures();
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL1, sensors1.getTempCByIndex(0));
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL11, sensors1.getTempCByIndex(0));
  
  /*
    //random number generator used for testing purposes only, in absebce of a real sensor probe
    //generate a random number
    randomNumber = random(5,30);
       x=(randomNumber);
    //generate a random number
  */

  //CAYENNE_OUT(VIRTUAL_CHANNEL2)// "Temepratura Caldaia" sensor
  // Send the command to get temperatures.
  sensors2.requestTemperatures();
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL2, sensors2.getTempCByIndex(0));
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL12, sensors2.getTempCByIndex(0));


  /*
    //random number generator used for testing purposes only, in absebce of a real sensor probe
    //generate a random number
    randomNumber = random(5,30);
       x=(randomNumber);
    //generate a random number
  */


  //CAYENNE_OUT(VIRTUAL_CHANNEL3)// "Temperatura accumulo acqua sanitaria" sensor
  // Send the command to get temperatures.
  sensors3.requestTemperatures();//if experiencing strange problems with digital pin 4, then the sensor has to be connected in parallel with pin 5, DS18B20 can work by sharing the same bus 
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL3, sensors3.getTempCByIndex(0));// channel 0 of the ds18B20 sensor bus
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL13, sensors3.getTempCByIndex(0));// channel 0 of the ds18B20 sensor bus

  /*
    //random number generator used for testing purposes only, in absebce of a real sensor probe
    //generate a random number
    randomNumber = random(5,30);
       x=(randomNumber);
    //generate a random number
  */

  //CAYENNE_OUT(VIRTUAL_CHANNEL4)// "Temperatura pompa pannelli solari" sensor
  // Send the command to get temperatures.
  sensors4.requestTemperatures();//if experiencing strange problems with digital pin 4, then the sensor has to be connected in parallel with pin 5, DS18B20 can work by sharing the same bus 
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL4, sensors4.getTempCByIndex(0));// channel 1 of the ds18B20 sensor bus
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL14, sensors4.getTempCByIndex(0));// channel 1 of the ds18B20 sensor bus

  /*
    //random number generator used for testing purposes only, in absebce of a real sensor probe
    //generate a random number
    randomNumber = random(5,30);
       x=(randomNumber);
    //generate a random number
  */

  //CAYENNE_OUT(VIRTUAL_CHANNEL5)// "Temperatura accumulo acqua tecnica" sensor
  // Send the command to get temperatures.
  sensors5.requestTemperatures();
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL5, sensors5.getTempCByIndex(0));
  Cayenne.celsiusWrite(VIRTUAL_CHANNEL15, sensors5.getTempCByIndex(0));


  /*
    //random number generator used for testing purposes only, in absebce of a real sensor probe
    //generate a random number
    randomNumber = random(5,30);
       x=(randomNumber);
    //generate a random number
  */


}
2 Likes

thanks @campeggio for sharing the code, it will help alot for other community users.

1 Like

2 Likes