Grow box problem

Combine them, even easier :wink:

BLYNK_WRITE(V1){
    if (param.asInt()){       
        digitalWrite(ledRelayState, HIGH);
        Blynk.virtualWrite(23, HIGH);
    } else {
        digitalWrite(ledRelayState, LOW);
        Blynk.virtualWrite(23, LOW);
    }
}

V1 would be the input from the rtc widget and v23 would be the output for the led widget, i think that @Lichtsignaal did it! Im going to try it! Thanks guys! Really apreciated your help!

The RTC widget, if you use the Blynk one instead of a hardware one, is a different story, but yes. I prefer to use virtual pins because you are much more flexible in what you do. You can set for example two relays high with one button.

Yeah Vpins rock, im starting to realize the potential in them and im going to make a few changes in the project to simplify things. What do you mean regarding blynks rtc widget? I e as planning to use the input from it and give it to a function to close or open a relay…

Blynk has an RTC widget so you don’t need a hardware part anymore to get the time from the Interwebz. It’s really nice to use and saves a couple bucks on hardware, but I’m not sure if you use a hardware RTC, so I thought I’d mention it :slight_smile:

Yeah blynk’s rtc ftw ahah next its try and figure out how to make a weak and day conter. im taking a few days off for vacations and i’ll be back with the full code and pics (i hope). Thanks guys

Im having problems getting through these errors, i’ve making changes after setting the dashboard on my phone, if i anyone could help me it would be great…

/* MeLion GrowBox 0.1 */
// This #include statement was automatically added by the Particle IDE.
#include "PietteTech_DHT/PietteTech_DHT.h"
#include "blynk/blynk.h"
// system defines
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define DHTTYPE  DHT11              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   0         	    // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   600  // Sample every minute
//declaration
void dht_wrapper(); // must be declared before the lib initialization

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;	    // Next time we want to start sample
bool bDHTstarted;		    // flag to indicate we started acquisition
int n;                              // counter
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ""; //Set token from the Blynk app

char VERSION[64] = "0.04";

#define READ_INTERVAL 60000

// My garden setup
bool shutdownButton = 1;
  // Moisture variables
int humid1;
int moistureBreakpoint = 60;
bool extractionInProgress = false;
int moistureValueVirtual;
bool extractionButton = 0;
  // Temperature variables
int temp1;
int temperatureBreakpointLow  = 20;
int temperatureBreakpointHigh = 23;
bool heatingInProgress = false;
bool heatingButton = 0;
  // Lighting variables
bool lightingButton = 0;
  // Timer variables
unsigned long Timer;
unsigned long milis;

void setup()
{
  
  Serial.begin(9600);
  delay(5000);
  Blynk.begin(auth);

 DHTnextSampleTime = 0;  // Start the first sample immediately

}


// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
    DHT.isrCallback();


// Outputs
  pinMode(D1, OUTPUT); //Output for LED Lighting relay 
  pinMode(D2, OUTPUT); //Output for Extraction fan relay 
  pinMode(D3, OUTPUT); //Output for Heater relay 
  
  
  // Initial timer setup
  Timer = millis();

  Serial.println("done setup");
}

void loop()
{
  Blynk.run();

 // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
      
	if (!bDHTstarted) {		// start the sample
	    DHT.acquire();
	    bDHTstarted = true;
	}

 if (!DHT.acquiring()) {		// has sample completed?

  float temp = (float)DHT.getCelsius();
  int temp1 = (temp - (int)temp) * 100;

  char tempInChar[32];
  sprintf(tempInChar,"%0d.%d", (int)temp, temp1);

  float humid = (float)DHT.getHumidity();
  int humid1 = (humid - (int)humid) * 100;
  
  char humidInChar[32];
  sprintf(humidInChar,"%0d.%d", (int)humid, humid1);
  
  // Converting moisture to virtual and sending to Blynk
  moistureVirtual();
 
  n++;  // increment counter
  bDHTstarted = false;  // reset the sample flag so we can take another
  DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
 }
 
}

 

  // Main function that times and calls all of the other subfunctions
  growBoxMaster();
  
}

void growBoxMaster()
{
  milis = millis();
  if(milis - Timer >= 1000UL)
  {
    Serial.println("********************* Timed pseudoloop execution *********************");
    
    shutdownMaster();
    moistureMaster();
    heatingMaster();
    lightingMaster();
    Timer = millis();
  }
}

void shutdownMaster()
{
  Serial.println("------- shutdownMaster started -------");


  if(!shutdownButton)
  {
      startShutdown();
  }
    // Printing important values
  Serial.print("shutdownButton - ");
  Serial.println(shutdownButton);
}

void startShutdown()
{
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  Blynk.virtualWrite(28, 1023);
  Serial.println("SHUTDOWN");
}



void moistureMaster()
{
  Serial.println("------- moistureMaster started -------");
  
  
  if((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = HIGH))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = LOW))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = HIGH))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = LOW))
  {
    extractionInProgress = false;
    stopExtraction();
  }
  
  Serial.print("humid1 - ");
  Serial.println(humid1);

  Serial.print("extractionInProgress - ");
  Serial.println(extractionInProgress);

  Serial.print("moistureBreakpoint - ");
  Serial.println(moistureBreakpoint);

}

void startExtraction()
{
  digitalWrite(2, HIGH);
  Blynk.virtualWrite(25, 1023);
  Serial.println("Extraction - started");
}

void stopExtraction()
{
  digitalWrite(2, LOW);
  Blynk.virtualWrite(25, 0);
  Serial.println("Extraction - stoped");
}

void heatingMaster()
{
  Serial.println("------- heatingMaster started -------");

  
  getTemperature();

  
  if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (!heatingButton))
  {
    heatingInProgress = true;
    startHeating();
  }
  else if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (heatingButton))
  {
    heatingInProgress = false;
    stopHeating();
  }
  else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (!heatingButton))
  {
    heatingInProgress = false;
    stopHeating();
  }
  else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (heatingButton))
  {
    heatingInProgress = true;
    startHeating();
  }
  
  Serial.print("temp1 - ");
  Serial.println(temp1);

  Serial.print("heatingInProgress - ");
  Serial.println(heatingInProgress);

  Serial.print("temperatureBreakpointLow - ");
  Serial.println(temperatureBreakpointLow);

  Serial.print("temperatureBreakpointHigh - ");
  Serial.println(temperatureBreakpointHigh);
  
  Serial.print("heatingButton - ");
  Serial.println(heatingButton);
}

void startHeating()
{
  digitalWrite(3, HIGH);
  Blynk.virtualWrite(24, 1023);
  Blynk.virtualWrite(21, HIGH);
  Serial.println("Heating - started");
}

void stopHeating()
{
  digitalWrite(3, LOW);
  Blynk.virtualWrite(24, 0);
  Blynk.virtualWrite(21, LOW);
  Serial.println("Heating - stoped");
}

void getTemperature()
{
  
  Blynk.virtualWrite(26, temp1);
}

void LightingMaster()
{
  Serial.println("------- heatingMaster started -------");

  
  if(!lightingButton)
  {
    startLighting();
  }
  else if(lightingButton)
  {
    stopLighting();
  }
  
  Serial.print("lightingButton - ");
  Serial.println(lightingButton);
}

void startLighting()
{
  digitalWrite(1, HIGH);
  Blynk.virtualWrite(22, 1023);
  Serial.println("Lighting - started");
}

void stopLighting();
{
  digitalWrite(1, LOW);
  Blynk.virtualWrite(22, 0);
  Serial.println("Lighting - stopped");
}


// Getting value of moistureBreakpoint
BLYNK_WRITE(V2)
{
  int pinData = param.asInt();
  moistureBreakpoint = pinData;
}


// Getting value of temperatureBreakpointLow
BLYNK_WRITE(V4)
{
  int pinData = param.asInt();
  temperatureBreakpointLow = pinData;
}


// Getting value of temperatureBreakpointHigh
BLYNK_WRITE(V5)
{
  int pinData = param.asInt();
  temperatureBreakpointHigh = pinData;
}


// Getting value of shutdownButton
BLYNK_WRITE(V6)
{
  bool pinData = param.asInt();
  shutdownButton = pinData;
}


// Getting value of extractionButton
BLYNK_WRITE(V6)
{
  int pinData = param.asInt();
  extractionButton = pinData;
}


// Getting value of LightingButton
BLYNK_WRITE(V7)
{
  bool pinData = param.asInt();
  lightingButton = pinData;
}


// Getting value of heatingbutton
BLYNK_WRITE(V8)
{
    int pinData = param.asInt();
  heatingButton = pinData;
}


void moistureVirtual()
{
  Blynk.virtualWrite(20, humid1);

}

errors:

                 from blynk/BlynkSimpleParticle.h:14,
                 from blynk/blynk.h:2,
                 from blynkt.cpp:4:
blynk/BlynkApiParticle.h:90:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
     #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
      ^
blynkt.cpp:16:1: error: expected unqualified-id before 'else'
 else if(lightingButton);
 ^

blynkt.cpp: In function 'void growBoxMaster()':
blynkt.cpp:131:20: error: 'lightingMaster' was not declared in this scope
 }
                    ^

blynkt.cpp: In function 'void LightingMaster()':
blynkt.cpp:290:18: error: 'stopLighting' was not declared in this scope
 }
                  ^

blynkt.cpp: At global scope:
blynkt.cpp:305:1: error: expected unqualified-id before '{' token
     startLighting();
 ^

In file included from blynk/BlynkApi.h:17:0,
                 from blynk/BlynkApiParticle.h:14,
                 from blynk/BlynkParticle.h:14,
                 from blynk/BlynkSimpleParticle.h:14,
                 from blynk/blynk.h:2,
                 from blynkt.cpp:4:
blynkt.cpp: In function 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)':
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: redefinition of 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)'
     void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
          ^

blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
blynkt.cpp:345:1: note: in expansion of macro 'BLYNK_WRITE'
 
 ^
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)' previously defined here
     void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
          ^

blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
blynkt.cpp:337:1: note: in expansion of macro 'BLYNK_WRITE'
 
 ^
make[1]: *** [../build/target/user/platform-6blynkt.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

Wow sorry but your code is messy :sweat:
What board are you using? I will try to compile it here with changes.
A few things I can see though:

  • Put everything in dht_wrapper() (pinMode(), timer and serial output) in setup() and ditch the function all together.
  • Put vars with values in setup(), not just with the #defines.
  • In loop() put if(Blynk.connected()){blynk.run(); );
  • Take all the DHT stuff out of loop and put it in a function with a 2sec timer so you’re not calling it thousands of times a sec when the DHT only transmits every 2 seconds anyway.
  • Define your pins above setup(). I see that in your startShutdown() function you have digitalWrite’s with direct pin numbers. Replace these with definitions.This is more in line of best practice for coding. Also helps if you need to change the pins for whatever reason later. Change it in one place.
  • Many of your declaring errors will go away if you put the loop() as the very last thing in the sketch.
    I find that the best order of a sketch is:

defines
global vars declarations
setup()
blynk_writes()
void functions for your project
loop()

So try reorganizing the layout of your sketch to be more in line with this concept.

Hope this helps!

1 Like

The LightingMaster is easy, you spelled it with a capital L naming the function, but you are calling it with a lowercase L. :slight_smile:

But I do agree with @Jamin. If you clean it up a bit and adhere to what is become to known as the golden Blynk standard it’ll look much nice and will be easier to maintain and more fun to deal with! :smile:

1 Like

Great help and tips! Yeah im a messy noob ahah going to clean up a bit using what you said to make it more clear to spot errors.

Cheers guys!

Edit: im using a particle photon @Jamin

1 Like

i tried to organize things and to structure the code according to the order advised but i still have lots of errors and now my head hurts from trying to understand this new way ahah so far i have this…


// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

/* MeLion GrowBox 0.1 */

#include "blynk/blynk.h"
// system defines
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
// Sensor Declaration
#define DHTPIN 4     
#define DHTTYPE DHT11 
#define ledRelay  1    // D1 pin output to Lighting LED's relay
#define fanRelay  2    // D2 pin output to Extraction Fan relay
#define heatRelay  3   // D3 pin output to Heating relay
#define dhtIn 4        // D4 pin input from DHT11

DHT dht(DHTPIN, DHTTYPE);

char auth[] = "";

// Garden setup
bool shutdownButton = 1;
  // Moisture variables
int humid1;
int moistureBreakpoint = 60;
bool extractionInProgress = false;
int moistureValueVirtual;
bool extractionButton = 0;
  // Temperature variables
int temp1;
int temperatureBreakpointLow  = 20;
int temperatureBreakpointHigh = 23;
bool heatingInProgress = false;
bool heatingButton = 0;
  // Lighting variables
bool lightingButton = 0;
  // Timer variables
unsigned long Timer;
unsigned long milis;

// Outputs
  pinMode(ledRelay, OUTPUT); //Output for LED Lighting relay 
  pinMode(fanRelay, OUTPUT); //Output for Extraction fan relay 
  pinMode(heatRelay, OUTPUT); //Output for Heater relay 
  pinMode(dhtIn, INPUT); //Input for the DHT pin
  

void setup()
{
  
  Serial.begin(9600);
  delay(1000);
  Blynk.begin(auth);
  
  dht.begin();
  
}

// Getting value of moistureBreakpoint
BLYNK_WRITE(V2)
{
  int pinData = param.asInt();
  moistureBreakpoint = pinData;
}


// Getting value of temperatureBreakpointLow
BLYNK_WRITE(V4)
{
  int pinData = param.asInt();
  temperatureBreakpointLow = pinData;
}


// Getting value of temperatureBreakpointHigh
BLYNK_WRITE(V5)
{
  int pinData = param.asInt();
  temperatureBreakpointHigh = pinData;
}


// Getting value of shutdownButton
BLYNK_WRITE(V6)
{
  bool pinData = param.asInt();
  shutdownButton = pinData;
}


// Getting value of extractionButton
BLYNK_WRITE(V6)
{
  int pinData = param.asInt();
  extractionButton = pinData;
}


// Getting value of LightingButton
BLYNK_WRITE(V7)
{
  bool pinData = param.asInt();
  lightingButton = pinData;
}


// Getting value of heatingbutton
BLYNK_WRITE(V8)
{
    int pinData = param.asInt();
  heatingButton = pinData;
}

void growBoxMaster()
{
  milis = millis();
  if(milis - Timer >= 1000UL)
  {
    Serial.println("********************* Timed pseudoloop execution *********************");
    
    dhtReadings();
    shutdownMaster();
    moistureMaster();
    heatingMaster();
    lightingMaster();
    Timer = millis();
  }
}

// Get Readings
  // Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a 
// very slow sensor)
void dhtReadings();
{	
	float humid1 = dht.getHumidity();
// Read temperature as Celsius
	float temp1 = dht.getTempCelcius();
// Read temperature as Farenheit
	float f = dht.getTempFarenheit();
  
// Check if any reads failed and exit early (to try again).
	if (isnan(humid1) || isnan(temp1) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}

// Compute heat index
// Must send in temp in Fahrenheit!
	float hi = dht.getHeatIndex();
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();

	Serial.print("Humid: "); 
	Serial.print(humid1);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(temp1);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr());


  Serial.println("done setup");
}


void shutdownMaster()
{
  Serial.println("------- shutdownMaster started -------");


  if(!shutdownButton)
  {
      startShutdown();
  }
    // Printing important values
  Serial.print("shutdownButton - ");
  Serial.println(shutdownButton);
}

void startShutdown()
{
  digitalWrite(ledRelay, LOW);
  digitalWrite(fanRelay, LOW);
  digitalWrite(heatRelay, LOW);
  Blynk.virtualWrite(28, 1023);
  Serial.println("SHUTDOWN");
}



void moistureMaster()
{
  Serial.println("------- moistureMaster started -------");
  
  moistureVirtual()
  
  if((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = HIGH))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid1 > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = LOW))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = HIGH))
  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid1 < moistureBreakpoint) && (extractionInProgress) && (extractionButton = LOW))
  {
    extractionInProgress = false;
    stopExtraction();
  }
  
  Serial.print("humid1 - ");
  Serial.println(humid1);

  Serial.print("extractionInProgress - ");
  Serial.println(extractionInProgress);

  Serial.print("moistureBreakpoint - ");
  Serial.println(moistureBreakpoint);

}

void startExtraction()
{
  digitalWrite(2, HIGH);
  Blynk.virtualWrite(25, 1023);
  Serial.println("Extraction - started");
}

void stopExtraction()
{
  digitalWrite(2, LOW);
  Blynk.virtualWrite(25, 0);
  Serial.println("Extraction - stoped");
}


void moistureVirtual()
{
  Blynk.virtualWrite(20, humid1);

}


void heatingMaster()
{
  Serial.println("------- heatingMaster started -------");

  
  temperatureVirtual();

  
  if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (!heatingButton))
  {
    heatingInProgress = true;
    startHeating();
  }
  else if((temp1 < temperatureBreakpointLow) && (!heatingInProgress) && (heatingButton))
  {
    heatingInProgress = false;
    stopHeating();
  }
  else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (!heatingButton))
  {
    heatingInProgress = false;
    stopHeating();
  }
  else if((temp1 >= temperatureBreakpointHigh) && (heatingInProgress) && (heatingButton))
  {
    heatingInProgress = true;
    startHeating();
  }
  
  Serial.print("temp1 - ");
  Serial.println(temp1);

  Serial.print("heatingInProgress - ");
  Serial.println(heatingInProgress);

  Serial.print("temperatureBreakpointLow - ");
  Serial.println(temperatureBreakpointLow);

  Serial.print("temperatureBreakpointHigh - ");
  Serial.println(temperatureBreakpointHigh);
  
  Serial.print("heatingButton - ");
  Serial.println(heatingButton);
}

void temperatureVirtual()
{
  
  Blynk.virtualWrite(26, temp1);
}

void startHeating()
{
  digitalWrite(3, HIGH);
  Blynk.virtualWrite(24, 1023);
  Blynk.virtualWrite(21, HIGH);
  Serial.println("Heating - started");
}

void stopHeating()
{
  digitalWrite(3, LOW);
  Blynk.virtualWrite(24, 0);
  Blynk.virtualWrite(21, LOW);
  Serial.println("Heating - stoped");
}



void lightingMaster()
{
  Serial.println("------- heatingMaster started -------");

  
  if(!lightingButton)
  {
    startLighting();
  }
  else if (lightingButton)
  {
    stopLighting();
  }
  
  Serial.print("lightingButton - ");
  Serial.println(lightingButton);
}

void startLighting()
{
  digitalWrite(1, HIGH);
  Blynk.virtualWrite(22, 1023);
  Serial.println("Lighting - started");
}

void stopLighting();
{
  digitalWrite(1, LOW);
  Blynk.virtualWrite(22, 0);
  Serial.println("Lighting - stopped");
}



void loop()
{
  if (Blynk.connected()) Blynk.run();

  // Initial timer setup
  Timer = millis();
  // Main function that times and calls all of the other subfunctions
  growBoxMaster();
  
}


erros:

In file included from blynk/BlynkParticle.h:14:0,
                 from blynk/BlynkSimpleParticle.h:14,
                 from blynk/blynk.h:2,
                 from blynkt.cpp:6:
blynk/BlynkApiParticle.h:90:6: warning: #warning "analogInputToDigitalPin not defined => Named analog pins will not work" [-Wcpp]
     #warning "analogInputToDigitalPin not defined => Named analog pins will not work"
      ^
blynkt.cpp:16:1: error: expected unqualified-id before 'else'
 else if (lightingButton);
 ^

blynkt.cpp:42:10: error: expected constructor, destructor, or type conversion before '(' token
   // Moisture variables
          ^

blynkt.cpp:43:10: error: expected constructor, destructor, or type conversion before '(' token
 int humid1;
          ^

blynkt.cpp:44:10: error: expected constructor, destructor, or type conversion before '(' token
 int moistureBreakpoint = 60;
          ^

blynkt.cpp:45:10: error: expected constructor, destructor, or type conversion before '(' token
 bool extractionInProgress = false;
          ^

In file included from blynk/BlynkApi.h:17:0,
                 from blynk/BlynkApiParticle.h:14,
                 from blynk/BlynkParticle.h:14,
                 from blynk/BlynkSimpleParticle.h:14,
                 from blynk/blynk.h:2,
                 from blynkt.cpp:6:
blynkt.cpp: In function 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)':
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: redefinition of 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)'
     void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
          ^

blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
blynkt.cpp:92:1: note: in expansion of macro 'BLYNK_WRITE'
 
 ^
This looks like an error in blynk library. Would you like to create an issue on GitHub to let the author know?
CREATE ISSUE
blynk/BlynkHandlers.h:155:10: error: 'void BlynkWidgetWrite6(BlynkReq&, const BlynkParam&)' previously defined here
     void BlynkWidgetWrite ## pin (BlynkReq& request, const BlynkParam& param)
          ^

blynk/BlynkHandlers.h:163:31: note: in expansion of macro 'BLYNK_WRITE_2'
 #define BLYNK_WRITE(pin)      BLYNK_WRITE_2(pin)
                               ^
blynkt.cpp:84:1: note: in expansion of macro 'BLYNK_WRITE'
 
 ^
blynkt.cpp: In function 'void growBoxMaster()':
blynkt.cpp:121:17: error: 'dhtReadings' was not declared in this scope
   bool pinData = param.asInt();
                 ^

blynkt.cpp: At global scope:
blynkt.cpp:135:1: error: expected unqualified-id before '{' token
   milis = millis();
 ^

make[1]: *** [../build/target/user/platform-6blynkt.o] Error 1
make: *** [user] Error 2

i always put setup exactly before loop

this is an easy error for you to find and fix

what is milis?

like: defines
global vars declarations
blynk_writes()
void functions for your project
setup()
loop()
?
does this solve anything?

sure! at least that is what works for me…

i don’t think it helped… i think its the same errors…

edit: ill try to solve this tomorrow, I’m a zombie from sleeping too little thinking about this ahah

I cant seem to compile it because I dont have the Photon boards library installed in IDE.
I recommend you ditch the Photon device and go for a NodeMCU ESP8266-12F/E clone for like $3… get the 4Mbyte version…

Im just re-writing your code so it compiles on the ESP now… might save you loads of head scratching :slight_smile: hah

EDIT: Here you go… this compiles fine on my end on an ESP8266 NodeMCU clone. I’ve chopped out at least 80 lines of repeated code. I also recommend ditching all the Serial prints UNLESS you need them for debugging… I installed SimpleTimer lib so its in line with Blynk standards to control the growboxmaster()…you can see it fires every 2 seconds… you can change that in setup.

/* MeLion GrowBox 0.1 */
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
/* DEFINITIONS */
#define ledRelay   1    // D1 pin output to Lighting LED's relay
#define fanRelay   2    // D2 pin output to Extraction Fan relay
#define heatRelay  3    // D3 pin output to Heating relay
#define DHTPIN     4    // D4 pin input from DHT11
#define DHTTYPE DHT11
/* VIRTUAL PORTS */
#define UPTIME_vPIN           0
#define MOIST_BRK_PNT_vPIN    2
#define TEMP_BRK_PNT_LO_vPIN  3
#define TEMP_BRK_PNT_HI_vPIN  4
#define SHUTDOWN_BTN_vPIN     5
#define EXTRACT_BTN_vPIN      6
#define LIGHTING_BTN_vPIN     7
#define HEAT_BTN_vPIN         8
#define HUMID_vPIN           20
#define HEATING_LED_vPIN     21
#define LIGHTING_vPIN        22
#define HEATING_vPIN         24
#define EXTRACT_vPIN         25
#define TEMP_vPIN            26
#define SHUTDOWN_vPIN        28
/* LIBRARY CMDS */
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer0;
SimpleTimer timer1;
/* AUTH CODE BLYNK */
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
/*******************************************************************************************************/
/* GLOBAL VAR DEFINE - Enter default values in setup */
bool shutdownButton;
float humid;
float temp;
int moistureBreakpoint;
bool extractionInProgress;
int moistureValueVirtual;
bool extractionButton;
int temperatureBreakpointLow;
int temperatureBreakpointHigh;
bool heatingInProgress;
bool heatingButton;
bool lightingButton;
/*******************************************************************************************************/
void setup() {
  /* SET PINMODE */
  pinMode(ledRelay, OUTPUT); //Output for LED Lighting relay
  pinMode(fanRelay, OUTPUT); //Output for Extraction fan relay
  pinMode(heatRelay, OUTPUT); //Output for Heater relay
  pinMode(DHTPIN, INPUT); //Input for the DHT pin
  /* SET DEFAULT VAR VALUES */
  shutdownButton = 1;
  moistureBreakpoint = 60;
  extractionInProgress = false;
  extractionButton = 0;
  temperatureBreakpointLow = 20;
  temperatureBreakpointHigh = 23;
  heatingInProgress = false;
  heatingButton = 0;
  lightingButton = 0;
  /* START COMMUNICATION */
  Serial.begin(115200);
  while (!Serial) {
    ;
  }
  Blynk.begin(auth, "SSID", "PASS");
  while (Blynk.connect() == false) {
    ;
  }
  /* START LIBRARIES */
  dht.begin();
  timer0.setInterval(2000L, growBoxMaster);
  timer1.setInterval(1000L, sendUptime);
  /* DONE SETTING UP */

}
/*******************************************************************************************************/
BLYNK_WRITE(MOIST_BRK_PNT_vPIN) {
  moistureBreakpoint = param.asInt();
}
BLYNK_WRITE(TEMP_BRK_PNT_LO_vPIN) {
  temperatureBreakpointLow = param.asInt();
}
BLYNK_WRITE(TEMP_BRK_PNT_HI_vPIN) {
  temperatureBreakpointHigh = param.asInt();
}
BLYNK_WRITE(SHUTDOWN_BTN_vPIN) {
  shutdownButton = param.asInt();
}
BLYNK_WRITE(EXTRACT_BTN_vPIN) {
  extractionButton = param.asInt();
}
BLYNK_WRITE(LIGHTING_BTN_vPIN) {
  lightingButton = param.asInt();
}
BLYNK_WRITE(HEAT_BTN_vPIN) {
  heatingButton = param.asInt();
}
/*******************************************************************************************************/
void sendUptime() {
  Blynk.virtualWrite(UPTIME_vPIN, millis() / 1000);
}

void growBoxMaster() {
  dhtReadings();
  shutdownMaster();
  moistureMaster();
  heatingMaster();
  lightingMaster();
}

// Get Readings
void dhtReadings() {
  humid = dht.readHumidity();
  temp  = dht.readTemperature();
  if (isnan(humid) || isnan(temp) ) {
    return;
  }
  Blynk.virtualWrite(HUMID_vPIN, humid);
  Blynk.virtualWrite(TEMP_vPIN, temp);
}


void shutdownMaster()
{
  Serial.println("------- ShutdownMaster started -------");
  if (!shutdownButton)  {
    digitalWrite(ledRelay, LOW);
    digitalWrite(fanRelay, LOW);
    digitalWrite(heatRelay, LOW);
    Blynk.virtualWrite(SHUTDOWN_vPIN, 1023);
    Serial.println("SHUTDOWN");
  }
  Serial.print("shutdownButton - ");
  Serial.println(shutdownButton);
}

void moistureMaster() {
  Serial.println("------- moistureMaster started -------");

  if ((humid > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = HIGH))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid > moistureBreakpoint) && (!extractionInProgress) && (extractionButton = LOW))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid < moistureBreakpoint) && (extractionInProgress) && (extractionButton = HIGH))  {
    extractionInProgress = true;
    startExtraction();
  }
  if ((humid < moistureBreakpoint) && (extractionInProgress) && (extractionButton = LOW))  {
    extractionInProgress = false;
    stopExtraction();
  }

  Serial.print("humid - ");
  Serial.println(humid);

  Serial.print("extractionInProgress - ");
  Serial.println(extractionInProgress);

  Serial.print("moistureBreakpoint - ");
  Serial.println(moistureBreakpoint);

}

void startExtraction()
{
  digitalWrite(fanRelay, HIGH);
  Blynk.virtualWrite(EXTRACT_vPIN, 1023);
  Serial.println("Extraction - started");
}

void stopExtraction()
{
  digitalWrite(fanRelay, LOW);
  Blynk.virtualWrite(EXTRACT_vPIN, 0);
  Serial.println("Extraction - stoped");
}




void heatingMaster()
{
  Serial.println("------- heatingMaster started -------");

  if ((temp < temperatureBreakpointLow) && (!heatingInProgress) && (!heatingButton))  {
    heatingInProgress = true;
    startHeating();
  }
  else if ((temp < temperatureBreakpointLow) && (!heatingInProgress) && (heatingButton))  {
    heatingInProgress = false;
    stopHeating();
  }
  else if ((temp >= temperatureBreakpointHigh) && (heatingInProgress) && (!heatingButton))  {
    heatingInProgress = false;
    stopHeating();
  }
  else if ((temp >= temperatureBreakpointHigh) && (heatingInProgress) && (heatingButton))  {
    heatingInProgress = true;
    startHeating();
  }

  Serial.print("temp - ");
  Serial.println(temp);

  Serial.print("heatingInProgress - ");
  Serial.println(heatingInProgress);

  Serial.print("temperatureBreakpointLow - ");
  Serial.println(temperatureBreakpointLow);

  Serial.print("temperatureBreakpointHigh - ");
  Serial.println(temperatureBreakpointHigh);

  Serial.print("heatingButton - ");
  Serial.println(heatingButton);
}


void startHeating(){
  digitalWrite(heatRelay, HIGH);
  Blynk.virtualWrite(HEATING_vPIN, 1023);
  Blynk.virtualWrite(HEATING_LED_vPIN, HIGH);
  Serial.println("Heating - started");
}

void stopHeating(){
  digitalWrite(heatRelay, LOW);
  Blynk.virtualWrite(HEATING_vPIN, 0);
  Blynk.virtualWrite(HEATING_LED_vPIN, LOW);
  Serial.println("Heating - stoped");
}

void lightingMaster()
{
  Serial.println("------- lightingMaster started -------");
  if (!lightingButton)  {
    digitalWrite(ledRelay, HIGH); 
    Blynk.virtualWrite(LIGHTING_vPIN, 1023);
    Serial.println("Lighting - started");
  }
  else if (lightingButton)  {
    digitalWrite(ledRelay, LOW); 
    Blynk.virtualWrite(LIGHTING_vPIN, 0);
    Serial.println("Lighting - stopped");
  }
  Serial.print("lightingButton - ");
  Serial.println(lightingButton);
}

/*******************************************************************************************************/
void loop()
{
  Blynk.run();
  timer0.run();
  timer1.run();
}

The pinmode declaration is not in the setup(). That is at least something I saw. Also, I don’t think it’s needed to declare the output pin for DHT, but I’m not sure, I don’t think I do that.

You have Two BLYNK_WRITE(V6). I think you need to find another free pin :wink: I assume it can be V5.

void dhtReadings(); <-- remove the “;”, it’s not supposed to be there
{

Furthermore I see you have a different kind of library to read out the DHT, but this is what I noticed when compiling.

If your head hurts too much, set aside the project for a day or so and continue later. If you try to hard it will come back and bite you in the ass, baby steps :wink:

@Jamin :open_mouth: the code you posted compiles and is fully functioning with a node mcu ? If so i think ill order one, many thanks man!

@Lichtsignaal i quickly changed the dht library because i wasnt getting steady readings and started doing the structural changes and things got messed up aha when i get home ill look closely on those points you mentioned if i cant get it to compile i think ill order the.nodemcu that @Jamin was talking about since the code is good. its a chance to really study and learn the proper ways to write and how blynk should work

Thanks for the effort and time spent guys, looking forward to share the knowledge when i get to your level ahah cheers

EDIT: @Jamin i dont think its hard to adapt to use a particle photon, i dont know, i havent had a chance to have a proper look to your code but it looks really great. ill try it :wink:

@bernas_123, Totally go for it dude! If you can adapt it then go hard… it should be pretty simple too :slight_smile:
Just a note, grab the proper DHT library… dont use the adafruit version. :slight_smile:

If you do grab a NodeMCU… I have both of these and they’re great… larger one and smaller one