SolArduino - Camping solar heater panels control with Arduino


#21

can you post your entire code.


#22
/*
  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));

}