I don’t know why. Here’s the main code:
#define SW_VERSION " SW Ver. 3.2" // SW version will appears at innitial LCD Display
#include "stationDefines.h" // Project definitions
#include "stationCredentials.h"
/* ESP & Blynk */
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetLED PUMPs(V0); // Echo signal to Sensors Tab at Blynk App
WidgetLED PUMPa(V5); // Echo signal to Actuators Tab at Blynk App
WidgetLED LAMPs(V1); // Echo signal to Sensors Tab at Blynk App
WidgetLED LAMPa(V6); // Echo signal to Actuators Tab at Blynk App
/* TIMER */
#include "SimpleTimer.h"
SimpleTimer timer;
/* OLED */
#include <ACROBOTIC_SSD1306.h> // library for OLED: SCL ==> D1; SDA ==> D2
#include <Wire.h>
/* DHT22*/
#include "DHT.h"
DHT dht(DHTPIN, DHTTYPE);
/* DS18B20 Temperature Sensor */
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("ArduFarmBot 2");
Serial.println(".... Starting Setup");
Serial.println(" ");
pinMode(PUMP_PIN, OUTPUT);
pinMode(LAMP_PIN, OUTPUT);
pinMode(PUMP_ON_BUTTON, INPUT_PULLUP);
pinMode(LAMP_ON_BUTTON, INPUT_PULLUP);
pinMode(SENSORS_READ_BUTTON, INPUT_PULLUP);
pinMode(soilMoisterVcc, OUTPUT);
Blynk.begin(auth, ssid, pass, "myhostname", 8080);
oledStart();
dht.begin();
DS18B20.begin();
PUMPs.off();
LAMPs.off();
PUMPa.off();
LAMPa.off();
digitalWrite(PUMP_PIN, LOW);
digitalWrite(LAMP_PIN, LOW);
digitalWrite (soilMoisterVcc, LOW);
waitButtonPress (SHOW_SET_UP); // Wait for Sensor Button to be pressed
oled.clearDisplay();
startTimers();
}
void loop()
{
timer.run(); // Initiates SimpleTimer
Blynk.run();
}
/****************************************************************
* Read remote commands
****************************************************************/
BLYNK_WRITE(3) // Pump remote control
{
int i=param.asInt();
if (i==1)
{
pumpStatus = !pumpStatus;
aplyCmd();
}
}
BLYNK_WRITE(4) // Lamp remote control
{
int i=param.asInt();
if (i==1)
{
lampStatus = !lampStatus;
aplyCmd();
}
}
/****************************************************************
* Read local commands (Pump and Lamp buttons are normally "HIGH"):
****************************************************************/
void readLocalCmd()
{
boolean digiValue = debounce(PUMP_ON_BUTTON);
if (!digiValue)
{
pumpStatus = !pumpStatus;
aplyCmd();
}
digiValue = debounce(LAMP_ON_BUTTON);
if (!digiValue)
{
lampStatus = !lampStatus;
aplyCmd();
}
digiValue = debounce(SENSORS_READ_BUTTON);
if (!digiValue)
{
turnOffOLED = !turnOffOLED;
if (!turnOffOLED)
{
oled.setTextXY(0,0); oled.putString("UPDATING SENSORS");
getDhtData();
getSoilMoisterData();
getSoilTempData();
oledStart();
displayData();
}else oled.clearDisplay();
}
}
/***************************************************
* Receive Commands and act on actuators
****************************************************/
void aplyCmd()
{
if (pumpStatus == 1)
{
Blynk.notify("ArduFarmBot2: Warning ==>> Pump ON");
digitalWrite(PUMP_PIN, HIGH);
if (!turnOffOLED) displayData();
PUMPs.on();
PUMPa.on();
}
else
{
digitalWrite(PUMP_PIN, LOW);
if (!turnOffOLED) displayData();
PUMPs.off();
PUMPa.off();
}
if (lampStatus == 1)
{
Blynk.notify("ArduFarmBot2: Warning ==>> Lamp ON");
digitalWrite(LAMP_PIN, HIGH);
if (!turnOffOLED) displayData();
LAMPs.on();
LAMPa.on();
}
else
{
digitalWrite(LAMP_PIN, LOW);
if (!turnOffOLED) displayData();
LAMPs.off();
LAMPa.off();
}
}
/***************************************************
* Automatically Control the Plantation based on sensors reading
****************************************************/
void autoControlPlantation(void)
{
if (soilMoister < DRY_SOIL)
{
turnPumpOn();
}
if (airTemp < COLD_TEMP)
{
turnLampOn();
}
}
/***************************************************
* Turn Pump On for a certain amount of time
****************************************************/
void turnPumpOn()
{
pumpStatus = 1;
aplyCmd();
delay (TIME_PUMP_ON*1000);
pumpStatus = 0;
aplyCmd();
}
/***************************************************
* Turn Lamp On for a certain amount of time
****************************************************/
void turnLampOn()
{
lampStatus = 1;
aplyCmd();
delay (TIME_LAMP_ON*1000);
lampStatus = 0;
aplyCmd();
}
/***************************************************
* Send data to Blynk
**************************************************/
void sendUptime()
{
Blynk.virtualWrite(10, airTemp); //virtual pin V10
Blynk.virtualWrite(11, airHum); // virtual pin V11
Blynk.virtualWrite(12, soilMoister); // virtual pin V12
Blynk.virtualWrite(13, soilTemp); //virtual pin V13
}
By the way what type of connection should I chose for this 3G project - WiFi, GSM or ethernet?
Last several times I noticed that 3G modem shows NodeMCU connected but it doesn’t initialize. Usually when the nodeMCU program starts running the OLED display will light up. It works flawlessly with my local WiFi server version though.
This is the last log where Iswitched between the WiFi code version and the 3G one.
> 00:36:00.279 INFO - xxx@gmail.com hardware joined.
> 00:36:38.058 INFO - xxx@gmail.com@gmail.com hardware joined.
> 00:42:31.615 INFO - xxx@gmail.com@gmail.com Blynk-app (android-22720) joined.
> 00:42:33.598 INFO - xxx@gmail.com@gmail.com Blynk-app (android-22720) joined.
> 00:43:02.422 INFO - xxx@gmail.com@gmail.com Blynk-app (android-22720) joined.
> 00:47:42.486 INFO - xxx@gmail.com@gmail.com Blynk-app (android-22720) joined.
> 00:55:19.129 INFO - xxx@gmail.com@gmail.com hardware joined.
> 00:55:58.004 INFO - xxx@gmail.com@gmail.com hardware joined.